Shopify Discounts Not Applying After Login? The Essential Cart Page Fix
Hey fellow store owners and Shopify enthusiasts!
You know that feeling when you've meticulously set up a fantastic discount, perhaps one tied to customer tags, only to hear from a customer (or experience yourself) that it's just... not showing up? Specifically, it's those moments when a customer has items in their cart, then logs into their account, and BAM – the discount vanishes from the cart page. It's frustrating, right? You're thinking, "Did I set it up wrong?" "Is my theme broken?"
Well, as experts in Shopify migrations and development at Shopping Cart Mover, we often encounter these nuanced challenges. This exact scenario popped up in a Shopify Community forum discussion started by Mick_Smith titled "Discounts don't apply after customer login." And let me tell you, it's a classic example of how the community comes together to solve those tricky, head-scratching issues that impact customer experience and conversion.
The Annoying Discount Disappearing Act: When Login Breaks the Cart
Mick_Smith laid out the problem perfectly: "When you set up a discount for customers tagged with a specific tag and they then visit the website and add items to their cart, if then they proceed to log in, the discount does not show on the cart page. Even a page refresh does not solve the issue."
Sound familiar? The key here is the sequence of events: add items to cart FIRST, then log in. If a customer logs in before adding items, everything works as expected. This distinction is crucial for understanding the root cause. And here's the kicker: if the customer then performs any action that alters the cart (like changing a quantity, adding another item, or removing something), the discount suddenly reappears. Even more puzzling, Mick_Smith noted that if the customer just hits the checkout button, the discount does show up at the checkout stage. So, the discount isn't completely gone, it's just playing hide-and-seek on the cart page, particularly with the cart.cart_level_discount_applications Liquid object.
Why Does This Happen? Shopify's Cart Re-evaluation Logic
The core of this issue lies in how Shopify evaluates and applies discounts, especially those tied to customer tags. As SectionKit succinctly explained in the forum, "Shopify evaluates the customer’s tag discount only when the cart is updated. Since the login does not trigger the cart update, a discount is missed."
When a customer logs in, their session changes, and their associated tags become available. However, this login event itself doesn't automatically trigger a re-evaluation of the cart's contents against potential discounts. Shopify's system is designed to re-check discounts primarily when there's an explicit change to the cart's items or attributes. Without such a trigger, the cart page continues to display the cart state *before* the customer's login, thus missing any tag-based discounts.
The Elegant Solution: A "Dummy" Cart Update via AJAX
The good news is that the Shopify community, specifically oscprofessional, provided an elegant and effective solution: perform a "dummy" cart update using the Shopify AJAX Cart API immediately after a customer logs in. This subtle update acts as the necessary trigger for Shopify to re-evaluate the cart and apply any eligible discounts.
Implementing the Fix: Step-by-Step Guide
This solution involves adding a small JavaScript snippet to your Shopify theme. We recommend placing this code in your theme.liquid file, just before the closing