Shopify themes, liquid, logos, and UX
I'm currently developing a web store on Shopify with some specific needs that has led to some code in order to facilitate these needs. Some background;
I have been able to fulfil all the needs here in pretty basic ways, I've been able to sort preorder and premade items into separate collections, which means the 50% deposit is applied as a discount to items in the preorder collection. The only issue I have run into is the pretty rudimentary (and hardly watertight) solution for stopping preorder and premade items occupying a cart. I've used some basic liquid to check if items in the customer's cart conflict with the current item they are viewing, if they can't share a cart, the button is not created on the page, rather just some text saying they can't add the item. The solution works fine for the store, due to the nature of what it's selling it's very unlikely customers will go out of their way to check out with an invalid cart. For its intended function the code works perfectly and doesn't act up.
The only issue is that somehow, despite all the code for hiding the button being contained within the product-template.liquid, the cart page encounters a really weird bug where a customer adds a pre-order item (in a valid manner). The item will show in the cart with the deposit discount applied, and the subtotal will be correct, however, the item will show as $0. This bug only applies for pre-order items with the automatic discount.
This bug only persists for a bit, after two or so refreshes it tends to correct itself.
Visual of the cart acting normally after the bug is gone
I don't understand how this code is interfacing with the cart in an odd manner despite being separate from the product page code and only ever getting the state of the cart, never setting. I've tried isolating the code that hides the add to cart button, and the bug is not present. I'm pretty new to Shopify so I'm wondering if I've made an odd oversight or am missing something obvious.
The block of code in 'product-template.liquid' that includes the logic and introduces the bug:
{% assign in_preorder_collection = false %} {% for collection in product.collections %} {% if in_preorder_collection == false and collection.title == 'Pre-Order' %} <div> <p style="color:green;font-size:0.75em">  Pay a 50% deposit per item </p> </div> {% assign in_preorder_collection = true %} {% endif %} {% endfor %} <div class="product-form__controls-group product-form__controls-group--submit"> <div class="product-form__item product-form__item--submit {%- if section.settings.enable_payment_button %} product-form__item--payment-button {%- endif -%} {%- if product.has_only_default_variant %} product-form__item--no-variants {%- endif -%}" > {% assign allow_flag = true %} {% if in_preorder_collection %} {% for item in cart.items %} {% for collection in item.product.collections %} {% if collection.title == 'Pre-Built' %} {% for collection in product.collections %} {% if collection.title == 'Pre-Order' %} <h2>Pre-Built and Pre-Order Items cannot be in the same Cart</h2> {% assign allow_flag = false %} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endfor %} {% else %} {% for item in cart.items %} {% for collection in item.product.collections %} {% if collection.title == 'Pre-Order' %} {% for collection in product.collections %} {% if collection.title == 'Pre-Built' %} <h2>Pre-Built and Pre-Order Items cannot be in the same Cart</h2> {% assign allow_flag = false %} {% endif %} {% endfor %} {% endif %} {% endfor %} {% endfor %} {% endif %} {% if allow_flag %} <button type="submit" name="add" {% unless current_variant.available %} aria-disabled="true"{% endunless %} aria-label="{% unless current_variant.available %}{{ 'products.product.sold_out' | t }}{% else %}{{ 'products.product.add_to_cart' | t }}{% endunless %}" class="btn product-form__cart-submit{% if section.settings.enable_payment_button and product.selling_plan_groups == empty %} btn--secondary-accent{% endif %}" {% if settings.enable_ajax %}aria-haspopup="dialog"{% endif %} data-add-to-cart> <span data-add-to-cart-text> {% unless current_variant.available %} {{ 'products.product.sold_out' | t }} {% else %} {{ 'products.product.add_to_cart' | t }} {% endunless %} </span> <span class="hide" data-loader> {% include 'icon-spinner' %} </span> </button> {% if section.settings.enable_payment_button %} {{ form | payment_button }} {% endif %} </div> </div> {% endif %} {% endform %} </div>
And here is the same code without the logic, removing the bug;
<div> <p style="color:green;font-size:0.75em">  Pay a 50% deposit per item </p> </div> <div class="product-form__controls-group product-form__controls-group--submit"> <div class="product-form__item product-form__item--submit {%- if section.settings.enable_payment_button %} product-form__item--payment-button {%- endif -%} {%- if product.has_only_default_variant %} product-form__item--no-variants {%- endif -%}"> <button type="submit" name="add" {% unless current_variant.available %} aria-disabled="true"{% endunless %} aria-label="{% unless current_variant.available %}{{ 'products.product.sold_out' | t }}{% else %}{{ 'products.product.add_to_cart' | t }}{% endunless %}" class="btn product-form__cart-submit{% if section.settings.enable_payment_button and product.selling_plan_groups == empty %} btn--secondary-accent{% endif %}" {% if settings.enable_ajax %}aria-haspopup="dialog"{% endif %} data-add-to-cart> <span data-add-to-cart-text> {% unless current_variant.available %} {{ 'products.product.sold_out' | t }} {% else %} {{ 'products.product.add_to_cart' | t }} {% endunless %} </span> <span class="hide" data-loader> {% include 'icon-spinner' %} </span> </button> {% if section.settings.enable_payment_button %} {{ form | payment_button }} {% endif %} </div> </div> {% endform %} </div>
Any help is extremely appreciated! Thanks for your time 🙂
Sorry you are facing this issue, it would be my pleasure to help you.
Welcome to the Shopify community!😊
Thanks for your good question.
Please share your site URL,
I will check out the issue and provide you a solution here.
When custom code on a Shopify product page causes certain products to show as $0 in the cart, it can be a challenging issue to debug. Here are steps to identify and resolve the problem:
Check the Custom Code for Errors:
Review Product Template Code:
Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025