Conditional check for the linked products available or not

Hello,

We are currently building a WooCommerce Single Product Template and are looking for a way to display Linked Products (Upsells and Cross-sells) only when they are (assigned or) not empty.

Could you please guide us on how to implement this dynamically? Any examples or best practices would be greatly appreciated.

Thank you for your support.

Hello @bibhashkarn,

Thanks for writing to us.

In order to display the cross-sell product on the WooCommerce Single Product layout, I would suggest you please use the Cross Sell product element.

Hope it helps
Thanks

Hi,

Thank you for your response and for sharing the screenshot.

We are currently displaying upsell products on the single product page, and this is working as expected. Please refer to the attached screenshot for reference. However, we are facing an issue where the upsell section still appears even when no upsell products are assigned to the current product.

Our requirement is to display the Upsell Products section only when upsell products are assigned. At the moment, while the upsell products themselves are not shown, the parent/upper container (div) remains visible. We would like to hide the entire section, including its parent div, when no upsell products are assigned, as shown in the screenshot.

We would appreciate your guidance on how to achieve this.

Thank you and best regards.

Hello Bibhash,

You can use String dynamic content {{dc:post:meta key="_upsell_ids"}} Is Not {empty space} as your condition.

image

image

Kindly let us know how it goes as I have tested this on my end.

Hi,

Thank you for your response and kind support.
It worked perfectly and as expected.

Thank you, and best regards.

You’re welcome, Bibhash

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.