12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Jun 18, 2021

How to Check If There Is At Least One Product on Sale in Oxygen

Sridhar Katakam

If you are using Oxygen‘s Repeater to show WooCommerce products that are on sale (members-only tutorial here), you may want to set a condition on it so it gets output only when there is at least 1 product on sale.

This is quite simple to do, thanks to the most powerful condition in Oxygen – Dynamic Data.

Here’s how you can use the built-in Dynamic Data condition for this.

Dynamic Data > PHP Function Return value (under Advanced).

Function Name: wc_get_product_ids_on_sale

Operator: is_not_blank

That’s it.

If you want to output a text message for when there are no products on sale, set a condition similar to the above but choose is_blank as the operator.

wc_get_product_ids_on_sale returns an array of IDs of WooCommerce products that are on sale.

Here’s a code snippet I used while I was testing the above:

	$array = wc_get_product_ids_on_sale();
	print( '<pre>' . print_r( $array, true ) . '</pre>' );

	$product_ids = wc_get_product_ids_on_sale();

	foreach ( $product_ids as $product_id ) {
		echo '<h4>' . $product_id . ' - ' . get_the_title( $product_id ) . '</h4>';