You can use a shortcode or block in order to display the WooCommerce products on sale. However, what if you wanted a proper “product category” called “Sale” – and where you didn’t need to manually assign this category to each product?
Basically, how do we display all the discounted products in a custom category called “Sale”, without doing any manual work?
Here’s a super quick tutorial. Enjoy!

Step 1: Add New Product Category
A one-off manual step is required, actually.
Simply go to WP Dashboard > Products > Categories > Add new category and enter the category name e.g. “Sale” and its slug e.g. “sale”.
The slug is very important as it’s used in the snippet below, so if you decide to rename it, you must change the PHP accordingly.
Step 2: PHP Snippet To Programmatically Populate the “Sale” Product Category With Products On Sale
/**
* @snippet Automatically Populate Sale Product Cat
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 6
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
add_action( 'woocommerce_product_query', 'bbloomer_sale_category' );
function bbloomer_sale_category( $q ) {
if ( "sale" !== $q->get( 'product_cat' ) ) return; // "sale" = slug
$q->set( 'post_type', 'product' );
$q->set( 'product_cat', null );
$product_ids_on_sale = wc_get_product_ids_on_sale() ? wc_get_product_ids_on_sale() : array();
$q->set( 'post__in', $product_ids_on_sale );
}
Hi, how can I show only 1 category on the product archive?
When I put everyone in “sale”, for example it appears like “women, sale”
I want to hide Sale or only show the first category,
Thankss!!!!
Screenshot please?
Hi Rodolfo,
Thanks for the snippet. This works nice!
Just for your info: It is not compatible with Permalink Manager Pro unfortunately. When Permalink Manager Pro is active, the Sale category page shows nothing.
Thank you!
I would love this functionality! However, I can’t get the snippet to work in Kadence Theme and WordPress 6.0.2.
Well, apparently it does populate the Sale Category. I did not see it working immediately because the sale category itself did not appear on Shop Page together with all the available categories. Is there a way for the Sale Category to appear with the rest of the Categories at the shop page?
Great! The Sale Category is a standard WooCommerce product category, so it should show
Thanks for all your hard work, your site has helped me plenty with a starting point. But for this I seen that it works only on the frontend and I needed it to also show up on the backend too. After more research and testing I did finally got a code that works for adding it to the backend and frontend. Hopes this helps someone else.
Thank you Chanel!
syntax error, unexpected ‘&’
here: if ( $product->is_on_sale() ) {
how can i fix that?
Try now
Dont work for variable products 🙁
Hello Ivo, please expand on that? The wc_get_product_ids_on_sale function should indeed return variable products IDs as well. Is your DB table “wc_product_meta_lookup” up to date?
And will it work with variable products too?
And will it remove the products automatically when they are not on sale anymore?
And I do not want products from a category to be included, how do I implement this in your code?
Thanks for your feedback!
1) it should
2) it will
3) I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Thanks for your reply.
Your code works but the products do not appear in the category SALE. When I go to Woocommerce -> products -> filter on category: Sale… that product is not there…
Backend or frontend? Because in the backend it won’t show any products, this simply populates the frontend category “Sale”