Code for Security Deposit

New Member
1 0 0

Hello Shopify Community,


I am trying to launch my site next week but i have a particular issue within some custom code that i just can't figure out. Any assistance would be truly appreciated.


I have amended some 'Gift Wrap' code initially written by a Shopify Expert to allow the customer to choose to add a gift wrap service to items in the cart. The code counts the quantity of items in the cart and adds a corresponding quantity of gift wrap products.


This has now become a security deposit for my Teepee Hire. The ISSUE is that my 'individual' products contain 'multiples' eg. 2 Teepees or 3 Teepees.


I have gone down the route of using the 'variant option 1' value as the identifier eg. 2 Teepees and but the site keeps freaking out and the cart keeps growing automatically.


I am obviously out of my depth here but hoping this is rudimentary to some folk. I have included below what i think is the key part of the code but please let me know if any other excerpts would be useful in problem solving.


{% assign id = %}

{% assign gift_wraps_in_cart = 0 %}
{% for item in cart.items %}
{% if product.variant.option1 == '2 Teepeez' %}
{% assign gift_wraps_in_cart = 2 %}
{% endif %}
{% endfor %}
{% assign items_in_cart = cart.item_count | minus: gift_wraps_in_cart %}


Thanks in advance