As part of the WooCommerce site, I want to have a sale page that lists the elements of the sale (pagination and filtering). I think the best way to do this is to have a "Sales" category, which is automatically added to any messages that are part of the sale (since category pages allow you to automatically filter and paginate).
I have this code so far to programmatically add a sale category to products while saving them:
function update_test( $product) { wp_set_object_terms($product, 'sale', 'product_cat', true ); } add_action( 'save_post', 'update_test', 1, 2);`
However, I want this to happen only if the product is sold (it has a sale price), so saving messages that are not for sale does not add a sale category. I tried a few different things, but no luck. I tried this, but it did not work:
function update_test( $product ) { if($product->is_on_sale()){ wp_set_object_terms($product, 'sale', 'product_cat', true ); } } add_action( 'save_post', 'update_test', 1, 2);`
but it just made my site freeze when saved.
Any ideas?
Andy
source share