Liquid attributes for In-Cart item not working

Solved
Tourist
13 0 0

So I'm trying to change the text and functionality of a button in the cart if a certain product is in the customers cart. I'm having trouble finding the right Liquid attribute to identify that product if its in the cart, what would be the problem?

 

% if product.title contains 'Glowband' %}
<form method="post" action="/cart/add" class="LaunchTipAddToCartForm LaunchTipAddToCartForm" enctype="multipart/form-data">
<input type="hidden" name="id" value="30334320541744">
<input type="hidden" name="quantity" value="1">
<button type="submit" name="add" title="Default Title" class="btn add-to-cart launchtip_add_to_cart" style="font-size:nullpx;background-color:null;color:null;">
<span class="add-to-cart__text">Added To Cart</span>
</button>
</form>
{% endif %}

I tried multiple tags like: cart.items.product.title, items,product.title, cart.items.title, and many more but cant seem to get it.

0 Likes

Success.

Shopify Partner
1153 133 200

You'll have to iterate over all line items and check for a product match. Assuming you have a for tag around? Something like:

{% for item in cart.items % }
......
{% if item.product.title contains 'Glowband' %}
<form method="post" action="/cart/add" class="LaunchTipAddToCartForm LaunchTipAddToCartForm" enctype="multipart/form-data">
<input type="hidden" name="id" value="30334320541744">
<input type="hidden" name="quantity" value="1">
<button type="submit" name="add" title="Default Title" class="btn add-to-cart launchtip_add_to_cart" style="font-size:nullpx;background-color:null;color:null;">
<span class="add-to-cart__text">Added To Cart</span>
</button>
</form>
{% endif %}
......
{% endfor %}

 

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Tourist
13 0 0

Thank you! This made it worked.

 

Although, now I didn't get the result I expected, I have an Upsell Add-On button in my cart and I'm trying to disable the buttons function when that certain Add-On is added to the cart and also add a success message. Thought I could with an "If" tag that would add a new (non functional) button but hide the original.

0 Likes