Liquid code for customer accounts with no tags

Solved

Liquid code for customer accounts with no tags

KlaudiaZapiet
Shopify Partner
68 4 10

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?

Klaudia from Zapiet
Learn more about our apps at Zapiet
Accepted Solution (1)

Kani
Shopify Partner
468 125 232

This is an accepted solution.

Hi @KlaudiaZapiet 

 

The first one is close

{% unless customer.tags == blank %}
    {% for tag in customer.tags %}
        {% if tag == 'test' %}
            do something
            {% break %}
        {% endif %}
    {% endfor %}
{% endunless %}

 

Hey!! ʕ ᵔᴥᵔ ʔ
Please click 'Like' and ' Accept as Solution' to encourage me to continue sharing my expertise. ♡
If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response. 🙂

View solution in original post

Replies 5 (5)

jordanholmes
Shopify Partner
152 28 34

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 %}

 

Jordan Holmes
Shopify Expert and Ruby on Rails Developer
Shopify Partner Directory
KlaudiaZapiet
Shopify Partner
68 4 10

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"

Klaudia from Zapiet
Learn more about our apps at Zapiet
jordanholmes
Shopify Partner
152 28 34

Hey,

 

{% if customer.tags contains 'tag' %}

 

This should just return false if the customer has no tags - what error are you getting?

Jordan Holmes
Shopify Expert and Ruby on Rails Developer
Shopify Partner Directory

Kani
Shopify Partner
468 125 232

This is an accepted solution.

Hi @KlaudiaZapiet 

 

The first one is close

{% unless customer.tags == blank %}
    {% for tag in customer.tags %}
        {% if tag == 'test' %}
            do something
            {% break %}
        {% endif %}
    {% endfor %}
{% endunless %}

 

Hey!! ʕ ᵔᴥᵔ ʔ
Please click 'Like' and ' Accept as Solution' to encourage me to continue sharing my expertise. ♡
If you need any technical assistance, feel free to send me a DM. You no longer have to search for answers without getting a response. 🙂
KlaudiaZapiet
Shopify Partner
68 4 10

Amazing, this worked!

Klaudia from Zapiet
Learn more about our apps at Zapiet