Sale products

For displaying on sale products with WooCommere the [products on_sale="true"] or [sale_products] shortcodes can be used. If your WooCommerce version is lower than 3.2 then you can only use the latter since the [products] shortcode did not support the on_sale attribute in the earlier versions.

The appearance of the displayed products depends on your active theme, the following examples are using Chap theme, but the shortcodes work with any theme as long as you’re using WooCommerce.

Displaying WooCommerce on sale products using the products shortcode
Sale!
$99.00 $82.00
Add to cart
Sale!
$15.00 $12.00
Add to cart
Sale!
$15.00 $12.00
Read more
Sale!
$30.00$35.00
Select options
Sale!
$20.00$50.00
View products
Sale!
$20.00 $18.00
Add to cart
Sale!
$3.00 $2.00
Add to cart
<products limit="8" columns="4" on_sale="true" />
WooCommerce sale products shortcode
Sale!
$99.00 $82.00
Add to cart
Sale!
$15.00 $12.00
Add to cart
Sale!
$15.00 $12.00
Read more
<sale_products columns="3" per_page="3">
Notes
The old sale_products shortcode should be used for WooCommerce version 3.1 or lower.

On sale shortcode displaying products that are not on sale

In some circumstances the shortcode is known to not work properly and display products that are not currently on sale.

When this happens you can try the following:

Go to WooCommerce -> Status -> Tools in your WordPress administration dashboard
Clear WooCommerce transients cache
Clear expired transients
Regenerate product lookup tables
Recount terms
Run database update (it takes time for this action to complete)
Clear any of your website caches
Give it time

If all else fails and it’s critical to not display non-sale products you could use JavaScript as a temporary fix:

JavaScript
Code may vary depending on theme
jQuery(function($){
  $('.woocommerce[class*="columns-"] .product:not(.sale)').hide();
});

Leave a comment

Your email address will not be published. Required fields are marked *