Skip Navigation

[Resolved] Can I use View's conditional output to check Woocommerce product type

This support ticket is created 2 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by Altti Papinsaari 2 years, 7 months ago.

Assisted by: Jamal.

Author
Posts
#2171865

Hello,

is it possible to use View's conditional output to display different content for Simple and Variable products?

#2171999

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting Toolset support.

WooCommerce Product types are handled by a hidden custom taxonomy (slug: product_type) with the following default terms:
- simple
- grouped
- variable
- external

Other plugins, such as WooCommerce Bookings or WooCommerce Subscriptions add other terms to this taxonomy('bookable', 'subscription').

This being said, you can use the Views conditional to conditionally display content per type. For example, to display different content templates, you can use:

[wpv-if evaluate="has_term('simple', 'product_type', null) = '1'"]
[wpv-post-body view_template="simple-product-template"]
[/wpv-if]
[wpv-if evaluate="has_term('variable', 'product_type', null) = '1'"]
[wpv-post-body view_template="variable-product-template"]
[/wpv-if]

If you are using the blocks editor, you can use the "has_term" function in the conditions.

I hope this helps. Let me know if you have any questions.

#2173671

Hello,

thank you for reply! I was trying to use the code in my product listing view but for some reason it doesn't seem work as the content between tags is not displayed. Any idea what might cause this?

 
[wpv-if evaluate="has_term('simple', 'product_type', null) = '1'"]
MY CONTENT HERE
[/wpv-if]
#2173835

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Maybe the "has_term" function needs to be registered in Toolset->Settings->Front-end Content->Functions inside conditional evaluations. Please register it, check again, and let me know what you will get.

If that does not help, I might need a copy of your website to debug it locally. Would that be fine with you? If yes, allow me temporary access and I'll install Duplicator or All In One Migration plugins to take a copy. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#2174751

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.