• 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/

Viewing 1 replies (of 1 total)
  • I’m having the same problem as Niels. This problem does not only occur when inserting _sale_price values, but also when inserting _regular_price values. The prices don’t show up until you update the product.

    I’ve tried to trigger some update_post logic, but to be honest, I don’t know exactly how to do that. All over the web you can find examples of how to update the meta data using the update_post_meta function, but no one speaks of the problems that Niels and I are experiencing.

    Perhaps someone (or you Niels) have found a solution to this?

Viewing 1 replies (of 1 total)
  • The topic ‘Set sale prices trough code’ is closed to new replies.