Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Re: Exclude if product vendor is __ and product tags contain__

Exclude if product vendor is __ and product tags contain__

Emma1903
Excursionist
21 0 5

I'm trying to add 2 conditions on an %if tag on product-template.liquid code. Screenshot attached of what the code currently looks like. 

 

It's working for the first condition (vendor) but it's not filtering out the second condition (product tags). Please let me know what I'm doing wrong!

 

code.JPG

 

Replies 3 (3)

StoreWatchers
Trailblazer
205 30 37

Hello @Emma1903,

 

Greetings from the Store Watchers Support Team! Happy to help you today.

 

Product.tags value type is array not string that's why it is not working. You have to use code like :

 

{% if product.vendor == 'Jamie Joseph' %}
{% unless product.tags contains 'RINGS' %}
<p>ADD PARAGRAPH YOU WANT TO ADD HERE</p>
{% endunless %}
{% endif %}

 

Note :

  • An array is a collection of a strings and A string is a simple text. Product.tags have multiple strings in it that is why the condition does not match. 
  • Contains checks the case of string(case-sensitive)

Let me know if require further assistance! 

 

Regards,

Store Watchers Support Team

StoreWatchers - Automate testing for your Shopify store in seconds


If you find my reply helpful, please hit Like and Mark as Solution
Visit us: App Store | Website | FAQs
Emma1903
Excursionist
21 0 5

Thank you so much! This is very helpful and makes sense. Where I'm stuck, is that I don't want to exclude RINGS. I want to exclude all other product types (example: PENDANTS, NECKLACES, EARRINGS). How would I use this code in order to target product vendor JAMIE JOSEPH and RINGS?

StoreWatchers
Trailblazer
205 30 37

Hello @Emma1903,

 

Please use below updated code to do it :

 

{% if product.vendor == 'JAMIE JOSEPH' and  product.tags contains 'RINGS' %}
<p>ADD PARAGRAPH YOU WANT TO ADD HERE</p>
{% endif %}

 

StoreWatchers - Automate testing for your Shopify store in seconds


If you find my reply helpful, please hit Like and Mark as Solution
Visit us: App Store | Website | FAQs