Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hey, need some help with coding a condition!
I'm trying to set a condition only for loyal customers with a specific tag. This works, however, if the customer doesn't have any tags, it doesn't seem to work.
I've tried the following:
{% for customer in customer.tags %}
{% if customer == 'test' %}
do something
{% endif %}
{% endfor %}
{% for customer in customer.tags %}
{% if customer.tags ==null %}
do something
{% endif %}
{% endfor %}
{% if customer.id == null %}
do something
{% endif %}
The first and third block works. However, the second one doesn't. If I'm logged in as a customer and my customer account has no tags, the action doesn't work. Am I doing something wrong?
Solved! Go to the solution
This is an accepted solution.
The first one is close
{% unless customer.tags == blank %}
{% for tag in customer.tags %}
{% if tag == 'test' %}
do something
{% break %}
{% endif %}
{% endfor %}
{% endunless %}
Hello,
I'm surprised any of the above work. If you are just wanting to test if a customer has a tag then something like
{% if customer.tags contains 'yourtaghere' %}
{% endif %}
Thanks Jordan, this works if the customer has a tag. However, I was trying to set up conditions for customers that have accounts, but don't have any tags. It worked with "customer.tags == blank"
Hey,
{% if customer.tags contains 'tag' %}
This should just return false if the customer has no tags - what error are you getting?
This is an accepted solution.
The first one is close
{% unless customer.tags == blank %}
{% for tag in customer.tags %}
{% if tag == 'test' %}
do something
{% break %}
{% endif %}
{% endfor %}
{% endunless %}
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025