Hello,
is it possible to use View's conditional output to display different content for Simple and Variable products?
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.
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]
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. **
My issue is resolved now. Thank you!