Tell us what you are trying to do?
I am using Divi Builder where I have created a template for a single product. I have inserted a conditional to display a custom taxonomy in relation to a category as shown below.
{!{wpv-conditional if="( $(product_categories) eq 'Sake' )"}!} {!{wpv-post-taxonomy type="sake-type"}!}
My question is how do I also conditionally display text which is the label for the taxonomy that I am displaying. Note that I have gotten the conditional to work and display the taxonomy but I can't do the same for the text (label). See picture attached.
Sakey Type: {!{wpv-post-taxonomy type="sake-type"}!}
Is there any documentation that you are following?
I have read the forums but I can't find a solution.
Is there a similar example that we can see?
What is the link to your site?
hidden link
Hi, there's no shortcode to display a Taxonomy label, so you should do something like this:
{!{wpv-conditional if="( $(product_categories) eq 'Sake' )"}!}
Sake type: {!{wpv-post-taxonomy type="sake-type"}!}
{!{/wpv-conditional}!}
{!{wpv-conditional if="( $(product_categories) eq 'Whisky' )"}!}
Whisky type: {!{wpv-post-taxonomy type="whisky-type"}!}
{!{/wpv-conditional}!}
{!{wpv-conditional if="( $(product_categories) eq 'Vodka' )"}!}
Vodka type: {!{wpv-post-taxonomy type="vodka-type"}!}
{!{/wpv-conditional}!}
Hi, Thanks. But when I add the ending code {!{/wpv-conditional}!} to the end, the category does not appear. But when I remove it, the remaining works and displays with the label.
Okay I see now, the $(product_categories) syntax is not correct. The $(slug) syntax should only be used for testing custom field values, but you're trying to use it with a taxonomy term. This won't work. Instead, you should use "has_term" as described here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/#specific
If you are using WooCommerce, the WC Product Categories taxonomy slug is "product_cat", so your code would look like this:
{!{wpv-conditional if="( has_term('Sake', 'product_cat', null) eq '1' )"}!}
Sake type: {!{wpv-post-taxonomy type="sake-type"}!}
{!{/wpv-conditional}!}
Be sure to register has_term in Toolset Settings, as described in that document.
Hi, I registered the has_term in the settings and used the recommended code but it didn't work. I played adjusted it a bit as follows:
{!{wpv-conditional if="( has_term('Sake', 'product_cat') eq 'Sake' )"}!}Sake Types: {!{/wpv-conditional}!}{!{wpv-post-taxonomy type="sake-type"}!}
This produced the text for the Sake Type, however, the Label Sake Types did not appear. I then shifted the {!{/wpv-conditional}!} to the end as follows:
{!{wpv-conditional if="( has_term('Sake', 'product_cat') eq 'Sake' )"}!}Sake Types: {!{wpv-post-taxonomy type="sake-type"}!}{!{/wpv-conditional}!}
This did not work as well and produced neither the label or the Sake Type.
Got it to work with this.
{!{wpv-conditional if="( has_term('Sake', 'product_cat', null) eq '1' )"}!} Sake type: {!{/wpv-conditional}!} {!{wpv-post-taxonomy type="sake-type"}!}
Thanks for the help!
My issue is resolved now. Thank you!