What's your biggest current challenge? Have your say in Community Polls along the right column.

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

Solved

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

fede26
Visitor
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

Accepted Solution (1)

PaulNewton
Shopify Partner
7450 657 1565

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

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


View solution in original post

Replies 5 (5)

PaulNewton
Shopify Partner
7450 657 1565

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

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


fede26
Visitor
3 0 0

Fantastic now it works correctly, thank you so much!

DFenn
Visitor
1 0 0

Hey Paul,

 

Im having the issue of the collection not showing the products.

 

Is this correct?

 

 

{% if customer.tags contains "VIP" %}

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

{{ pages.no-access.content }}
{% endif %}

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

{% endif %}

 

Adibaby
Visitor
1 0 0

Hi Paul - I wonder if you can help me. I have done the same as above to "protect" veterinary subscription food products in a collection. If I go to the collection via the website it works but if anyone googles the vet product and clicks on the direct link to that products they can see it and buy it without having to have the tag.

 

So the collection code I use is:

{% if customer.tags contains 'vet_buyer' %}
{% section 'collection-template' %}
{% else %}
{{ pages.no-access.content }}
{% endif %}

 

This works if the user navigates to the collection via the menu or home page:

https://www.justforpets.co.za/collections/royal-canin-veterinary-health-nutrition

 

but if they google a product in that collection and go straight to the link they can still see it and buy it without having the tag 'vet_buyer'

eg: https://www.justforpets.co.za/products/royal-canin-gastrointestinal-high-fibre

 

I have been searching but I cannot find a way to hide all those products that are in that collection from un-tagged buyers so that they see the same "Apologies" page.

The page template does not appear in the product template dropdown and I am not sure how to go about it.

Help would be appreciated. 🙂

Many thanks,

Adi

Ashton
Visitor
3 0 0

Hi Paul,