Shopify Discounts Disappearing After Login? Here's the Community-Backed 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, I've been diving deep into the Shopify community forums, and this exact scenario popped up in a 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.
The Annoying Discount Disappearing Act
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. 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.
Mick_Smith's investigation pointed to the core issue: "the cart.cart_level_discount_applications Liquid object is not (re)populated after a customer logs in." This is crucial.
Why Shopify Does This (And How to Work Around It)
This is where our sharp community members like SectionKit jumped in with some invaluable insight. SectionKit explained: "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. A dummy cart update after login fixes it."
Aha! The login process itself doesn't tell Shopify, "Hey, this customer just logged in, go re-check all discounts based on their new status!" It waits for a cart change. So, the solution is to force a cart update right after login, without actually changing the cart's contents in a meaningful way for the customer.
SectionKit even provided a hint for how to do this: a "dummy cart update" using the Cart API reference. But how exactly do you implement that?
The Community-Backed Solution: A Smart Code Snippet
This is where oscprofessional came to the rescue with a brilliant and elegant code snippet. They explained: "An attribute update via the AJAX Cart API counts as a cart change and triggers discount re-evaluation."
The solution involves adding a small piece of JavaScript that checks if a customer is logged in and has items in their cart. If so, it performs a subtle AJAX update to the cart by adding a hidden attribute. This "dummy" update triggers Shopify's discount re-evaluation, and then a quick page reload ensures everything displays correctly.
Step-by-Step: Implementing the Dummy Cart Update
Here’s how you can implement this fix in your Shopify store. This code should ideally go into your theme.liquid file, or your main cart template file, to ensure it runs whenever a customer might encounter this issue.
- Access Your Theme Code: From your Shopify admin, go to Online Store > Themes. Find your current theme, click Actions > Edit code.
- Locate the Right File: Open
theme.liquid. You'll want to place this script ideally before the closing