WordPress.org

Forums

WooCommerce - excelling eCommerce
Set sale prices trough code (2 posts)

  1. Niels van Renselaar
    Member
    Posted 1 year 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/

  2. Studio dub
    Member
    Posted 4 months ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic