if statement on product tags

Highlighted
Shopify Partner
7 0 0

Hi

I am not much of a coder, but am in need of a very time critical change

I have had to change the architecture of my site last minute, and now my front page collection (only has 3 products) needs to link to a unique collection of products  rather than a product

 

I thought the easiest way to do this (as its very static) would be to create an if statement and use product tags

 

see below

 


      {% if item.product.tag == littlehands %}
      <a class="grid-view-item__link" href="https://inspirebookbox.com.au/collections/our-little-hands-0-2-inspire-book-box">
      <img src="https://cdn.shopify.com/s/files/1/1996/3231/files/Select.jpg?14969197971242235864"/>  </a> 
      {% endif %} 
      
      {% if item.product.tag == bighands %}
      <a class="grid-view-item__link" href="https://inspirebookbox.com.au/collections/our-big-hands-3-6-inspire-book-box">
      <img src="https://cdn.shopify.com/s/files/1/1996/3231/files/Select.jpg?14969197971242235864"/>  </a> 
      {% endif %}
      
      {% if item.product.tag == family %}
      <a class="grid-view-item__link" href="https://inspirebookbox.com.au/collections/our-big-hands-3-6-inspire-book-box">
      <img src="https://cdn.shopify.com/s/files/1/1996/3231/files/Select.jpg?14969197971242235864"/>  </a> 
      {% endif %}
      
  </div>    

However the outcome is 3 buttons linking to 3 different areas instead of 1. 

0 Likes
Highlighted
Shopify Expert
9925 103 1763

Try something more like:

{% if item.product.tags contains "littlehands" %}
...

 

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
2 Likes
Highlighted
Shopify Partner
7 0 0

Thanks Jason

 

I sorted it out, needed a for loop first, and then the if's off the results of the for.

 

0 Likes
Highlighted
New Member
5 0 0

Hi Roxanne,

I think I am attempting to do a simliar thing, but can't figure it out. Can you share the code you wrote with the loop to do this, thank you!

0 Likes
Highlighted
New Member
4 0 0

This works

I put this in the product-template.liquid code and am using App metafield guru to set the message I want in the product.metafields.Info.Shipping field of the product metafield

{% assign has_delivery_tag = false %}
{% for tag in item.product.tags %}
{{tag}}

{% if tag == 'Delivery' %}
{% assign has_delivery_tag = true %}
{% break %}
{% endif %}
{% endfor %}
{% if has_delivery_tag == false %}
<h6><p style="color:purple;font-size: 22px">Delivery Information:-<BR>
{{ product.metafields.Info.Shipping }} </p></h6></style>
{% endif %}

0 Likes