Shopify Discounts Not Applying After Customer Login? Here's the Fix!
Hey there, fellow store owners!
Ever noticed a strange hiccup on your Shopify store where a customer logs in, and suddenly, those special discounts you set up just... disappear from their cart? Or rather, they don't appear when they should? It's a frustrating little quirk, and it's one that recently sparked a really helpful discussion in the Shopify community forums. I wanted to dive into it because it’s a common scenario, especially for those of us using customer tags for targeted promotions.
The Mystery of the Missing Discount
The issue, as brilliantly outlined by Mick_Smith in a recent thread titled "Discounts don't apply after customer login," goes something like this: You've got a fantastic discount set up for customers with a particular tag. A customer visits your store, adds items to their cart, and then decides to log into their account. Boom. The discount, which should now apply because they're a tagged customer, is nowhere to be seen on the cart page. Even hitting refresh doesn't fix it!
Mick_Smith pointed out a few key observations that really helped nail down the problem:
- If the customer logs in first, then adds items, the discount applies perfectly.
- The discount does eventually show up at the checkout stage, which is a relief, but not ideal for customer confidence on the cart page.
- The real kicker: if the customer simply alters their cart contents – adds another item, removes one, changes a quantity – the discount magically appears.
This last point was the big clue. It suggested that something about a cart change was triggering the discount evaluation, but a simple login wasn't. Mick_Smith's investigation further revealed that the cart.cart_level_discount_applications Liquid object wasn't being repopulated after a customer logs in. This is crucial because it's what determines which discounts are displayed on the cart page.
Why Does This Happen? The Shopify Cart Update Logic
This is where the community really stepped in. SectionKit, another helpful voice in the thread, explained the underlying mechanism perfectly. Shopify, by design, evaluates customer tag discounts only when the cart is updated. A customer logging into their account, while a significant event for their session, doesn't actually count as a cart update in Shopify's eyes.
So, when a customer logs in, their new customer.id and associated tags become active, but the cart's discount eligibility isn't re-evaluated until an actual change to the cart's contents occurs. That's why adding or removing an item fixes it – it forces Shopify to take another look.
The Elegant Solution: A "Dummy" Cart Update
Knowing the "why" immediately points us to the "how." If logging in doesn't trigger a cart update, we need to manually trigger one. SectionKit suggested a "dummy cart update" after login. Mick_Smith then asked for documentation on how to perform this, and SectionKit pointed to the Shopify Cart API reference, which is always a good place to start for programmatic cart interactions.
But the real hero of the day was oscprofessional, who provided a concise and effective code snippet that does exactly this! This solution leverages the AJAX Cart API to make a minor, imperceptible change to the cart, specifically by updating a cart attribute. This small change is enough to tell Shopify, "Hey, something happened here, re-evaluate those discounts!"
Implementing the Fix: Step-by-Step
Here’s how you can implement this fix on your Shopify store. It involves adding a small piece of JavaScript code to your theme.
Step 1: Access Your Theme Code
- From your Shopify admin, go to Online Store > Themes.
- Find the theme you want to edit (it's always a good idea to duplicate your theme first for a backup!).
- Click Actions > Edit code.
Step 2: Add the Code Snippet
You'll want to add this code to your theme.liquid file, or specifically to your cart template if you prefer. Placing it in theme.liquid ensures it runs globally after login.
- In the left sidebar, under Layout, click on
theme.liquid. - Scroll down and paste the following code snippet just before the closing