Displaying sale products on WooCommerce is a nice feature to have. It helps to attract more customers and increase revenue. In this article, we will get all the products that are on sale using WP_QUERY
class.
Check if product is on sale
We can simply check if a product is on sale on by using is_on_sale()
function.
Get Products on Sale from All Categories
On contrary, getting a list of products that are on sale is a bit complex than check for a single product. We will use WP_QUERY
class. In addition, we will use wc_get_product_ids_on_sale()
function to get all the ids.
The above query will retrieve all the products that are on sale from all category.
Get Products on Sale from Specific Categories
We can also retrieve list of products from specific categories. For this we should pass ids of categories as an array.
Read More Articles