Cart Array Issue

Solved
sethreese
Tourist
6 2 4

I am trying to get a button to show up only if a card isn't in the cart. Cards are all tagged "Card."

I'm trying to use this to get the tags of all the cart items then, if one is tagged Card, the button won't show up. It works if only a card is in the cart, but if more items are there the button remains. Any ideas? I've tried using unless as well. Same result. 

 {% assign cardtag = item.product.tags | join: "," %}
          
   {% if cardtag contains "Card" %}
        
        
          {% else %}
          
      <div class="cart-card-wrapper">
            <a href="/collections/cards"><div class="cart-add-card-link-text">Did you forget a card?</div></a>
            
        </div> 
   {% endif %}

 

 

0 Likes
sethreese
Tourist
6 2 4

This is an accepted solution.

For anyone who would like to know, I ended up with this. It worked for me.

{% assign all_tags = '' | split: '' %}
        {% for item in cartItems %}
          {% assign all_tags = all_tags | concat: item.product.tags %}
          {% endfor %}
         {% unless all_tags contains 'Card' %}
   
          
      <div class="cartdrawer-card-wrapper">
            <a href="/collections/cards"><div class="cart-add-card-link-text">Did you forget a card?</div></a>
            
        </div> 
   {% endunless %}
0 Likes