Hi, i'm trying to use the attribute shortcode (wpv-woo-list_attributes) to create a conditional output. I want to say:
If the attribute 'colour' = 'grey' then show option A
If the attribute 'colour' = 'blue' then show option B
And so on, how do I build the shortcode, there is only (wpv-woo-list_attributes) listen on the shortcodes page and no example.
Thanks
James
Hi James,
Thank you for contacting us and I'll be happy to assist.
The "wpv-woo-list_attributes" shortcode generates a table of available attributes, so it can't be used for a such a conditional check.
If you'd like to build a conditional check to see if a specific attribute term is attached to a product, you can use "has_term" function ( https://codex.wordpress.org/Function_Reference/has_term ), as shown in this example:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/#specific
After you've added the "has_term" at "WP Admin -> Toolset -> Settings -> Front-end Content -> Functions inside conditional evaluations", you can use the conditional shortcode like this:
[wpv-conditional if="( has_term('Red', 'pa_color', null) eq '1' )" ]
<p>This one is available in red!</p>
[/wpv-conditional]
Note: You'll replace "color" with actual attribute slug used on your website and keeping the "pa_" at the start.
I hope this helps and let me know how it goes.
regards,
Waqar
My issue is resolved now. Thank you!
Hi Waqar,
This is also something I wanted to reproduce on my website. But instead of a specific color condition, I would like to have a condition that do "If any color is selected, show this section" - "If there's no color selected, don't show this section". Because for now, if there's no specific color selected in the attributes, I have a blank spot on my product page where we can see "Color : ". I would like the full colour section to not show if there's no color selected in the attributes. What should I modify in your actual code to make this work like this?
Thank you!
J-F