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.

  1. Access Your Theme Code: From your Shopify admin, go to Online Store > Themes. Find your current theme, click Actions > Edit code.
  2. Locate the Right File: Open theme.liquid. You'll want to place this script ideally before the closing tag, or within the section, ensuring it executes after the necessary Liquid objects are available. If you prefer, you can also place it directly in your cart.liquid or a relevant section file if your theme uses sections for the cart.
  3. Insert the Code: Copy and paste the following code snippet:
{% if customer and cart.item_count > 0 %}

{% endif %}
  1. Understand What It Does:
    • {% if customer and cart.item_count > 0 %}: This Liquid conditional ensures the script only runs if a customer is logged in AND they actually have items in their cart (no need to refresh an empty cart!).
    • const customerId = "{{ customer.id }}";: It grabs the logged-in customer's ID.
    • const alreadyRefreshed = {{ cart.attributes.discounts_refreshed_for | json }} === customerId;: This is the clever part! It uses a temporary cart attribute, discounts_refreshed_for, as a flag. If this attribute already matches the current customer's ID, it means we've already done the refresh for this customer during this session, preventing unnecessary reloads.
    • await fetch('/cart/update.js', ...): This performs an asynchronous POST request to Shopify's AJAX Cart API. It updates the cart by simply setting the discounts_refreshed_for attribute to the current customerId. This minimal change is enough to trigger Shopify's discount re-evaluation logic.
    • window.location.reload();: After the cart is updated and discounts are re-evaluated on the backend, this line simply reloads the page to display the correct, updated cart with the discount applied.
  2. Save and Test: Save your changes and thoroughly test the scenario: add items to cart, log in, and check the cart page. The discount should now appear!

This solution is a fantastic example of leveraging Shopify's own APIs to work around a specific platform behavior. It's clean, efficient, and doesn't rely on any external apps, which is always a plus for performance and control.

Huge thanks to Mick_Smith for bringing this issue to light and to SectionKit and oscprofessional for providing such clear explanations and a robust solution. It really shows the power of the Shopify community when we all share our knowledge to make our stores run smoother. Happy selling!

Share:

Use cases

Explore use cases

Agencies, store owners, enterprise — find the migration path that fits.

Explore use cases