Woocommerce update sale price

Currently, I have a form in which the administrator can massively update product prices on one screen.

When the form is submitted, I simply use update_post_meta as follows:

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

This updates the meta key _sale_price. When I enter the admin to check this out, a new selling price has been inserted. When I look at the product on the front side, this product is not marked as sold. I have to go back and save the product again.

My question is, does woocommerce add another meta key for product labeling, like on sale? I have a dig in the database for all inserted user fields, but only _sale_price can be seen.

Any help would be greatly appreciated.

+3
source share
1 answer

Looking at the abstract product class in WooCommerce, the following php code gets whether the product is for sale:

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

Which, apparently, indicates that the price should be the same as sale_price to be classified as sold. So just

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

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

+9
source

All Articles