Add Sale Status Filter Attribute
Here's how you can add a "Sale Status" or "On Sale" or "Promotion" filter to your products making it possible for your website visitors to filter products by their sale status.
In this example let's go with "Promotion". The filter (using the WooCommerce Attribute Filter widget) will look something like this.
Here's how to set this up:
1. Add a new WooCommerce Product Attribute named "Promotion" here WordPress Admin Area > Products > Attributes > Add New
2. Add the following code to your Custom Plugin (create a custom plugin).
add_filter( 'dfrpswc_filter_attribute_value', function ( $value, $attribute, $post, $product, $set, $action ) { if ( $attribute !== 'pa_promotion' ) { return $value; } return absint( $product['onsale'] ?? 0 ) ? 'Yes' : 'No'; }, 20, 6 );
3. Save your custom plugin file.
Now after your Product Sets update again, each product will have a "Promotion" status of either "Yes" if the product is on sale and "No" if the product is not on sale.