woocommerce update sale price

I currently have a form where the admin can bulk update sale prices of products within one screen.

When the form is submitted i simply use update_post_meta like this:

Read More
update_post_meta($id,'_sale_price', 'new sale price here');

This updates the _sale_price meta key. When i go into the admin to check this, the new sale price has been inserted. When i view the product on the front end, the item is not marked as on sale. I have to go back in and re-save the product.

My question is, does woocommerce add some other meta_key to mark the product as on sale? I have had a dig round in the database for all the custom fields inserted, but can only see _sale_price.

Any help would be greatly appreciated

Related posts

Leave a Reply

1 comment

  1. Having a look at the Product abstract class in WooCommerce the following php code gets whether or not the product is on sale:

    return ( $this->sale_price != $this->regular_price && $this->sale_price == $this->price );
    

    Which seems to indicate that the _price has to be the same as the sale_price in order for it to be classed as on sale. So just

    update_post_meta($id, '_price', 'new sale price here too');
    

    as well as the code in your question and it should work.