Set sale prices trough code
-
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?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Set sale prices trough code’ is closed to new replies.