Search code examples
shopifyliquidshopify-template

Display HTML if any item of cart got specific tag


I want to implement two selectboxes in my shopify cart page if the cart contains an item with tag "test1"

my current code

{% for item in cart.items %}
  {% for products in item.products %}
      {% for tag in product.tags %}
          {% if tag contains 'test1' %}
            <select>....</select>
          {% endif %}
      {% endfor %}
  {% endfor %}
{% endfor %}

anyone can tell me what I'm doing wrong?


Solution

  • Please refer below code. you are rendering unnecessary loops. item access product object directly and product can tags.

    {% for item in cart.items %}
        {% if item.product.tags contains 'custom-tag' %}
             <h1> Yahoo </h1>
        {% endif %}
    {% endfor %}
    

    O/P will like below Image

    enter image description here