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

How to use Liquid If statements in cart loops correctly?

How to use Liquid If statements in cart loops correctly?

ConnorHEMK
Tourist
7 0 1

Hello,

I am trying to us the following code on the cart page to check if a product has a tag, if it does display text, however when I do this and there is more than 1 product in the cart (with different tags) it displays the text for each product.

This is a example of my code:

{% for item in cart.items %}
    {% if item.product.tags contains 'shiptoday' %}
         <h1>Ships Today</h1>
    {% endif %}
{% endfor %}

 
This would be underneath the product title, as a test I have noticed if there is multiple products but none of them contain the product tag then the <h1> tag doesn't show, however if one of the products has the tag, all the products show the <h1> tag.

Am I doing something wrong or misunderstanding how liquid/tags work on the cart page?

Replies 0 (0)