Showing Message if Variant SKU Contains "x"

Highlighted
Shopify Partner
4 0 0

Hello,

I was hoping someone could help me with some Shopify liquid. 

I'm trying to display a message whenever a current variant SKU is selected. I'm able to populate the message if I refresh the page with the option selected, but it doesn't change dynamically if I select the option that should hide/show it.

Screenshot.png

Example:

Customer selects variant with sku that contains "TUSA" show message 

Customer selects variant with sku that does not contain "TUSA" hide message 

 

Here is the code I'm trying to use:

{% assign messagetest = true %}                  
{% for variant in product.variants %}
{% unless current_variant.sku contains 'TUSA' %}
{% assign messagetest = false %}
{% endunless %}
{% endfor %}

{% if messagetest %}
test
{% else %}
{% endif %}

 

Cheers!

0 Likes
Highlighted
Shopify Partner
563 67 91

To dynamically change the text you will need to use Ajax call or javascript. Liquid will be rendered on load or refresh

- Was my reply helpful? Click Like to let me know!
- Was your question answered? Click Accept as Solution

Skype : lokendra.panwar1
0 Likes