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
- Guest adds itemsCart holds 2 products
- Logs inSaved cart collides with guest cart
- Cart pageItems missing or doubled
- 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
Prepare a test account
Log in, add Product A (quantity 1) and Product B, then log out. This is the saved cart.
Case 1: empty guest cart
In a new private window, log in without adding anything. The saved cart should appear intact.
Case 2: different products
Log out, add Product C as a guest, then log in. Expect A, B and C.
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.
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
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.
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.
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.
Check how the theme handles login
Shopify keeps the cart in a cart cookie and normally carries it through login. If items vanish, look for theme or app code that calls /cart/clear.js or rewrites the cart on login.
Review cart apps
Disable saved-cart, wishlist or upsell apps one at a time on a duplicate theme to find which one changes the cart.
Use the checkout login flow
If you use customer accounts, test logging in from the cart and from the checkout separately, as the two can behave differently.
Write an explicit merge function
Run it once on login. Key lines by product and variant ID, add quantities, cap at stock, then save the result to the account and clear the guest cart.
Make it safe to repeat
Guard against running twice (for example on a page refresh after login) so quantities do not double.
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()];
}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
- 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.
Related issues
- CNV-153Cart empties itself between pagesFix guide
- CNV-152Cart count doesn't update after addFix guide
- CNV-158Cart total doesn't match line itemsFix guide
- CNV-156Quantity update doesn't recalc totalFix guide
- CNV-164Cart limits by region block valid customersFix guide
- CNV-162Checkout button in cart brokenFix guide