Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Cart merges wrongly on login: how to find and fix it

CNV-163Low impactOther toolBy FunnelGuardPublished Updated
On this page

What this issue is

A shopper adds products as a guest, then logs in. Their account may already hold a saved cart from an earlier visit. The store has to decide what the cart looks like next. A wrong merge is any result the shopper did not expect: the guest items are wiped, the saved items are wiped, quantities double, or the same product appears twice as separate lines.

Why it costs you leads or sales

Where a wrong merge breaks the path
  1. Guest adds itemsCart holds 2 products
  2. Logs inSaved cart collides with guest cart
  3. Cart pageItems missing or doubled
  4. CheckoutShopper abandons or pays wrong amount

The break sits at the login step, so everything after it loses the shopper's intended cart.

How to check if your site has it

Test the three merge cases
  1. Prepare a test account

    Log in, add Product A (quantity 1) and Product B, then log out. This is the saved cart.

  2. Case 1: empty guest cart

    In a new private window, log in without adding anything. The saved cart should appear intact.

  3. Case 2: different products

    Log out, add Product C as a guest, then log in. Expect A, B and C.

  4. Case 3: same product

    Log out, add Product A as a guest, then log in. Decide what is right (quantity 2 or stay at 1) and check the result is one line, not two.

  5. Check variants and stock

    Repeat with a different size or colour of the same product, and with an item near its stock limit.

How to fix it

Fix by platform
  1. Rule out plugins

    On a staging copy, deactivate cart-related plugins (persistent cart, abandoned cart, caching) one at a time and rerun the three test cases.

  2. Check persistent cart

    WooCommerce stores the saved cart in user meta. If a plugin or custom code clears or overwrites it at the wp_login hook, remove or adjust that code.

  3. Exclude cart from caching

    Make sure the cart, checkout and account pages are excluded from page and object caching so a stale cart is not served after login.

Example merge logic (adapt to your own cart data)javascript
function mergeCarts(guestItems, savedItems, stockById) {
  const merged = new Map();
  for (const item of [...savedItems, ...guestItems]) {
    const key = item.productId + ':' + (item.variantId || '');
    const qty = (merged.get(key)?.qty || 0) + item.qty;
    const max = stockById[key] ?? qty;
    merged.set(key, { ...item, qty: Math.min(qty, max) });
  }
  return [...merged.values()];
}
Login with items in both carts

Before

  • Saved cart replaces the guest cart
  • Or the same product shows as two lines
  • Header count differs from the cart page

After

  • Both carts combine into one
  • Same product and variant is one line
  • Quantities capped at stock
  • Header count matches the cart page

How to confirm it's fixed

Confirmation checks
  • Empty guest cart plus saved cart shows the saved items
  • Guest cart plus empty saved cart keeps the guest items
  • Different products from both carts all appear
  • Same product and variant becomes one line with the right quantity
  • Quantity never exceeds stock
  • Header count and mini-cart match the cart page without a reload
  • Cart total matches the line items at checkout

How to prevent it happening again

How FunnelGuard handles this

Questions people ask

Why do items disappear from my cart when I log in?

Usually the store loads the saved account cart and replaces the guest cart instead of combining them. A plugin, theme script or cache can also clear the cart at login. Test with a guest cart and a saved cart to see which rule your site follows.

Why does my cart quantity double after logging in?

The merge adds the guest quantity to the saved quantity, and in some setups it runs twice, for example once on login and again on page reload. Merge identical product and variant lines and make sure the merge only runs once per login.

Should a guest cart replace or merge with the saved cart?

Merging is the safer choice. Combine both carts, treat the same product and variant as one line, and cap quantity at available stock. Replacing either cart means the shopper loses items they chose.

Does Shopify keep the cart when a customer logs in?

Shopify normally keeps the cart through login because it is tied to a cart cookie. If items vanish, the cause is usually theme code or an app that clears or rewrites the cart. Test with apps disabled on a duplicate theme.

Why does WooCommerce lose the cart after login?

Common causes are caching of the cart or account pages, plugins that clear the persistent cart, or custom code on the login hook. Test on staging by deactivating cart plugins one by one and excluding cart pages from caching.

How do I test the cart merge after login?

Use a test account with a saved cart and a private browser window. Check three cases: an empty guest cart, a guest cart with different products, and a guest cart with the same product. Also test a variant and an item near its stock limit.

Can FunnelGuard detect a wrong cart merge on login?

No. This depends on a logged-in account with saved cart history, which is outside what FunnelGuard checks. Use an end-to-end test tool with a test account or a manual QA checklist.

Does FunnelGuard catch this?

Other tool

Needs a different kind of tool.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.