Shopify Add to Cart Broken? The Hidden Code Fix & Conversion Killers Revealed
Hey everyone! As a Shopify migration expert and someone who spends a lot of time in the community forums, I often see store owners wrestling with issues that feel like a black box. Recently, a thread titled "Code Check" caught my eye, started by a store owner named Monique1. It's a fantastic example of how a small code issue can have a huge impact on sales, and how the community can come together to solve it. Let's dive into what happened and what we learned!
The Mystery of the Missing Cart Items
Monique's story is one many of you might relate to. She noticed a sudden drop in sales and, more alarmingly, customers couldn't add products to their cart. Initially, she observed it was redirecting to the homepage, then later clarified that the cart simply remained empty after clicking "Add to cart." This was happening after she had switched themes, both created by the same freelancer. While she'd also decreased her Google Ads spend (which definitely impacts traffic!), she suspected a deeper technical glitch.
This is where the community really shines. Fellow store owners and experts jumped in to help diagnose the problem, starting with some excellent initial troubleshooting advice.
Initial Diagnoses: Redirects, Traffic, and Basic Form Checks
Ploqo and LucasMao were among the first to offer insights. Ploqo suggested checking for a hidden return_to field in the product form, which, if set to /, would indeed send customers back to the homepage after adding an item to the cart (making them think it failed). He also advised separating the sales drop into two potential issues: decreased traffic (due to ads) vs. broken conversion flow (site issue). To do this, he recommended comparing analytics: if sessions are down but conversion rate is similar, it's likely traffic. If sessions are stable but conversion rate plummeted, it's a site problem.
Here's Ploqo's advice on how to look for that tricky return_to field, and other common culprits:
- Duplicate Your Theme First: Always, always make a copy before editing code!
- Search for
return_to: In your theme editor (Online Store > Themes > ... button > Edit code), use Ctrl+Shift+F (or Cmd+Shift+F on Mac) to search all files forreturn_to. A clean theme shouldn't have this. - Check
/cart/add: Ensure your theme uses{{ routes.cart_add_url }}instead of hardcoding/cart/add, which can break for different languages/markets. - Verify
form_type: Confirm your product form is wrapped in a proper product form tag.
LucasMao also confirmed the symptom: clicking "Add to cart" left the page in place, but the cart was empty. He pinpointed that the form was submitting without a variant ID, even for available products. This meant the hidden input[name="id"] field wasn't being populated correctly.
Here are the visual aids Ploqo provided for navigating the theme editor and searching:
The "Aha!" Moment: The Hidden disabled="disabled" Attribute
The real breakthrough came from Deniz_StorefrontQA and vestfoldhall. They both independently identified the core problem: the hidden variant field, , was incorrectly marked with disabled="disabled". This is a critical detail!
Why is it a problem? Browsers simply don't submit disabled fields with a form. So, even though the variant ID was technically present in the code, the browser ignored it, sending an empty ID to Shopify. The result? An empty cart.
Vestfoldhall brilliantly explained the root cause: Monique's theme (Be Yours 4.0.1) had a script designed to *remove* the disabled attribute after the page loaded. However, if anything delayed that script – a slow internet connection, a conflicting app, a mobile device – the button would appear to work but fail silently. This explains why the problem might have been intermittent or hard to reproduce consistently.
The Fix: Making Your Add to Cart Button Bulletproof
The solution is elegant: ensure the disabled attribute is only present in the Liquid code if the product variant is genuinely unavailable. This way, the field is correct *before* any JavaScript even runs, eliminating the "race condition."
Step-by-Step Instructions to Fix Your Product Form:
IMPORTANT: Always duplicate your theme before making any code changes!
-
Duplicate Your Theme: In your Shopify admin, go to Online Store > Themes. Find your current theme, click the ... (three dots) button, and select Duplicate. You'll make changes in this duplicate.
-
Edit Code: In the duplicate theme, click the ... button again and select Edit code.
-
Locate the Problematic Line: You'll need to find this line in two places in your theme files. Search for
name="id". It's typically found within:- The main product section (e.g.,
Sections > main-product.liquid) or a snippet it calls (likebuy-buttonsorproduct-form). - The sticky cart snippet (often identifiable by its ID ending in
--alt).
The line will look something like this:
- The main product section (e.g.,
-
Replace the Code: You need to replace the
disabled="disabled"part with a Liquid condition. Change the line to:Monique shared her code snippet, which shows this exact change in the sticky cart form:
{%- endif -%}

