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:
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
Having a look at the Product abstract class in WooCommerce the following php code gets whether or not the product is on sale:
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
as well as the code in your question and it should work.