If anyone else is interested – the solution:
Since the plugin v1.6.0, we have a new function that you can use to get all discounted product ids:
alg_wc_gsd_get_product_ids( $product_query_args = array( 'limit' => -1 ), $incl_on_sale = true, $use_transient = false )
I.e., in your snippet, replace this:
$product_ids_on_sale = wc_get_product_ids_on_sale() ? wc_get_product_ids_on_sale() : array();
with this:
$product_ids_on_sale = alg_wc_gsd_get_product_ids() ? alg_wc_gsd_get_product_ids() : array();
The alg_wc_gsd_get_product_ids()
function has three optional parameters:
$product_query_args
– sets which products to check. By default, it’s set to all products, i.e., array( 'limit' => -1 )
. This parameter is passed directly to the WooCommerce wc_get_products()
function, so you can use all the same parameters as listed in the documentation.
$incl_on_sale
– if set to true
, will return all on-sale products in your shop, including products that you have set on-sale manually, without using our plugin.
$use_transient
– the function goes through all products in your shop, so it can be rather slow, especially if you have a lot of products. To speed things up, you can store results in a transient by setting the parameter to true
. The transient expires after 24 hours.
P.S. Just in case, we also have a shortcode to display all discounted products, e.g.:
[alg_wc_gsd_products columns="4" use_transient="no"]