WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Set sale prices trough code (1 post)

  1. Niels van Renselaar
    Member
    Posted 6 months ago #

    Hi,

    I have a small script that updates products from a offline systeem, to keep thing synchronized. My client can set a "sale" price at that system too, and we want to push that to a WooCommerce webshop. So, we build a little snippet that set the appropiate post meta (this are variable products):

    $product_meta['_price'] = $saleprice;
    $product_meta['_sale_price'] = $saleprice;
    $product_meta['_regular_price'] = $regularpprice;
    
    // get current variables from the parent product
    $parent_price = get_post_meta( $product_id, "_price", true );
    $parent_min_variation_price = get_post_meta( $product_id, "_min_variation_price", true );
    $parent_max_variation_price = get_post_meta( $product_id, "_max_variation_price", true );
    $parent_min_variation_regular_price = get_post_meta( $product_id, "_min_variation_regular_price", true );
    $parent_max_variation_regular_price = get_post_meta( $product_id, "_max_variation_regular_price", true );
    $parent_min_variation_price = get_post_meta( $product_id, "_min_variation_price", true );
    $parent_min_variation_price = get_post_meta( $product_id, "_min_variation_price", true );
    
    if( $regularprice < $parent_price ) {
    update_post_meta( $post_parent, '_price', $regularprijs );
    }
    
    if( $regularprice < $parent_min_variation_price ) {
    update_post_meta( $post_parent, '_min_variation_price', $regularprice );
    update_post_meta( $post_parent, '_min_variation_regular_price', $regularprice );
    }
    
    if( $regularprice > $parent_max_variation_price ) {
    update_post_meta( $post_parent, '_max_variation_price', $regularprice );
    update_post_meta( $post_parent, '_max_variation_regular_price', $regularprice );
    }
    
    if( $saleprice > $parent_max_variation_price ) {
    update_post_meta( $post_parent, '_max_variation_sale_price', $saleprice );
    }
    
    if( $saleprice < $parent_max_variation_price ) {
    update_post_meta( $post_parent, '_min_variation_sale_price', $saleprice );
    }

    But, this only gets applied of the client "updates" the product in WordPress to. So I think we are missing a meta value we need to set... but which one?

    http://wordpress.org/plugins/woocommerce/

Reply

You must log in to post.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 6 months ago by Niels van Renselaar
  • This topic is not resolved
  • WordPress version: 3.8