"if customer.tags contains" does not search for a tag

Solved
fede26
New Member
3 0 0

Hi,

I am trying to set up a "private collection" page that only customers with the 'vip' tag can view.

I created a new collection with the theme 'private-collection', then I added the code below on a new section called 'collection.private-collection.liquid':

 

{% if customer.tags contains ‘vip’ %}

{% section 'collection' %}
{% else %}

{{ pages.no-access.content }}

{% endif %}

 

I then tagged some customers as 'vip' but it does not seem to recognise the vip customers - no one is able to open the page.

I believe that "contains" in the first row does not work correctly, as all customers see the "else" option.

I am using the Debut theme.

Would you be able to help fixing this?

If helpful, this is the store url: https://hasbanigioielli.myshopify.com/

This is the "private collection": https://hasbanigioielli.myshopify.com/collections/private-collection 

 

Thanks a lot,
Federico

0 Likes
PaulNewton
Shopify Partner
2601 136 475

This is an accepted solution.

Some additional steps to try

First replace backquotes ‘ with simple quotes "

{% if customer.tags contains ‘vip’ %}
{% if customer.tags contains "vip" %}

then try downcasing all the tags so matching is more consistent

{% assign customersTagsDowncased = customer.tags | downcase %}
{% if customersTagsDowncased contains "vip" %}
 
{% endif %}

 

If that does not work, loop over all tags for the check, wrap the following around thelogic

{% for tag in customer.tags %}
 {% if tag == "tagname" %}

 {% endif %}
{% endfor %}
Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
fede26
New Member
3 0 0

Fantastic now it works correctly, thank you so much!

0 Likes