Shopify Cart Not Cleared After Logout: Why and How to Fix

Blog Author Image
December 1, 2026
Blog Thimble Image

A customer logs out of your store on the family computer. An hour later, someone else logs in and finds a cart full of products they never picked. On a B2B store it can be worse: the next person sees another account's order, quantities and trade prices.

This isn't a bug in your theme. It's how Shopify carts work, and it happens on every store.

Why the Shopify cart is not cleared after logout

Shopify keeps the cart in a cookie called cart, stored in the browser. That cookie holds a cart token, not a customer ID. The cart belongs to the browser, not to the customer account.

Logging out ends the customer's session. It doesn't touch the cart cookie. So the cart stays where it was, ready for whoever uses that browser next.

It's also why carts disappear across devices: the cart never travels with the account.

When it becomes a problem

Most shoppers use their own phone, so they never notice. It matters when several people share one browser:

  • A family computer at home
  • A shared PC in an office or a workshop
  • A tablet at a store counter or a trade desk
  • Sales reps who log into their clients' accounts to build orders

In each case, the next customer sees products that aren't theirs. On a wholesale store that hides prices from the public, that's a privacy issue, not just a confusing cart.

The usual fix: clear the cart on logout with a script

The common answer on the Shopify forums is a few lines of JavaScript that call /cart/clear.js when the customer logs out. Shopify's Ajax Cart API documents this endpoint: it sets the quantity of every line item to zero.

It solves the privacy problem, but it creates another one: the cart is gone for good. When the customer logs back in, on this computer or another one, the cart is empty. A buyer who spent an hour building a 40-line order has to start over.

Two more things to know:

  • /cart/clear.js doesn't remove the cart note or cart attributes. They stay for the next person.
  • The script lives in your theme code, so you have to keep it working through theme updates.

If what you need is a button that lets customers empty their own cart, see our guide to adding a clear cart button.

How to clear the cart on logout without losing it

What you want is two things at once: an empty cart on the shared computer, and the customer's cart waiting for them when they come back.

Ecto auto-clear carts on logout: A signs out and the cart is emptied, B signs in and gets their own cart, A signs in again and the cart is back

That's what Ecto does with its Auto-clear carts on logout option:

  1. While a customer is logged in, Ecto saves their cart to their account.
  2. When they log out, the cart is emptied in that browser.
  3. When the next customer logs in on the same computer, their own saved cart loads, not the previous one.
  4. When the first customer logs back in, on this computer or any other device, their cart is restored.

If your customers share devices, turn the option on. Without it, the cart left in the browser becomes the cart of the next customer who logs in. Ecto then saves it to their account, because the most recent cart always wins.

We saw this with one of our B2B merchants. Their sales reps log into several client accounts on the same laptop, and the first client's cart kept following them into the next account. Turning on auto-clear on logout fixed it.

Ecto works with any Online Store theme and with the new customer accounts (login with an email code). 3‑click setup, no code, no theme edits. Carts are saved for logged-in customers only, and kept for 90 days after their last change.

Try it on the demo store

Log in on the Ecto demo store, add a product, log out, then log back in on your phone. Your cart is there. When you're ready, start a free trial from the Shopify App Store.

FAQ

How do I clear the cart on logout in Shopify?

Out of the box, logging out doesn't clear the cart. You can call /cart/clear.js when the customer logs out, but then the cart is lost for good. With Ecto's Auto-clear carts on logout option, the cart is emptied in that browser and restored when the customer logs back in.

Why does my Shopify cart stay after logout?

Shopify stores the cart in a browser cookie, not in the customer account. Logging out ends the session but leaves the cart cookie in place.

Can customers on a shared computer see each other's cart?

Yes, if one logs out and the next one uses the same browser. Clearing the cart on logout prevents it.

Does Shopify save the cart to the customer account?

Not for every customer. Shopify syncs carts through Shop for customers who have a Shop account. For everyone else, the cart stays in the browser.

Does /cart/clear.js remove the cart note?

No. It only sets quantities to zero. The cart note and cart attributes stay.

Stop losing carts
Ecto syncs every logged-in customer's cart across devices, so they find it wherever they come back.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Start Free trial
Start Free trial