If product tag contains "" Display ""

Tourist
25 0 1

Afternoon all,

product-grid-item.liquid:

{% if product.tags contains 'bulk-buy-discounts%}

       <div class="product__label--bulk-buy"><span>Bulk Buy</span></div> 

{% endif %}

 

I'm using this bit of code in the product-grid-item.liquid but for some reason it's not working, i've tried searching all over but i cant find a method that will display a div if a certain tag is in a product. If i just use the div part of the code it seems to display fine on the collections page but i really need it to display if a certain tag is used ?

 

Cheers.

0 Likes
Shopify Expert
9765 86 1513

Are you sure that product is the right object you need to be referencing? Take a look at other parts of the code in that file. What object does that file use to pull in things like images? 

Links to live page, theme in use, extra code for context, etc is always helpful.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Tourist
14 0 1

Try this:

 {% for t in product.tags %}
     {% if t contains 'bulk-buy-discounts' %}     
            <div class="product__label--bulk-buy"><span>Bulk Buy</span></div>      
     {% endif %}
  {% endfor %}

0 Likes
Shopify Expert
9765 86 1513

You would only need to do the above if "bulk-buy-discounts" is part of the tag. If it's the complete tag the loop over each isn't required as it will match based on the array.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Tourist
14 0 1

Each product array is available on the collection pages?

0 Likes
Shopify Expert
9765 86 1513

You're showing a product on a collection page, so those objects are available - including the tags array within.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Tourist
14 0 1

Nice, thanks for the info.  Looks like the problem could be that 2U Direct just left off the closing quotation mark after bulk-buy-discounts.

0 Likes
Shopify Expert
9765 86 1513

Good eyes. Very possible.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Tourist
25 0 1

fixed!

0 Likes
Highlighted
Shopify Partner
12 1 4

 

Here is what you need!

<!--Convert the tags into a string by joining them with COMMA-->
{% assign productTags = product.tags | join: ', ' %}
<!--Now Check for the desired tag name-->
{% if productTags contains 'Show_Size_Chart' %}

Okay.. I found the tag

{% else %}

<!--Tag not found :( -->
{% endif %}

 

0 Likes