# The WooCommerce cart empties itself

> A customer adds a product, moves to another page, and the cart is empty: this is almost always a session persistence problem, not a bug in the WooCommerce cart itself. WooCommerce tracks cart contents through cookies and a PHP session; as soon as either isn’t carried reliably from one page to the next, the cart looks like it’s emptying itself.

- Source canonique : [https://allaux.fr/en/wordpress-woocommerce/problemes/panier-qui-se-vide](https://allaux.fr/en/wordpress-woocommerce/problemes/panier-qui-se-vide)
- Langue : EN
- Dernière mise à jour : 2026-09-30

## Direct answer

> Exclude the Cart, Checkout and My Account pages from page caching: a cached copy served to every visitor shows an empty cart even though the session exists. Then check that the wp_woocommerce_sessions table actually fills up when a product is added, and that the whole journey stays on one domain, www or not, never dropping back to http.

## How I go about it

1. **Checking the cart cookies** — I check in the browser that woocommerce_cart_hash and wp_woocommerce_session_… are actually set after adding to cart, and that they persist from page to page without being wiped.
2. **Testing with caching disabled** — I reproduce the journey with all page caching turned off. If the cart behaves normally in that case, the most common cause is confirmed: a cached page being served as a logged-out version to a visitor who actually has an active cart.
3. **Checking the effective domain** — I check that no page in the buying journey loads on www when the rest of the site is non-www, or on http instead of https: this kind of mismatch changes the cookie’s effective domain and silently breaks the session.
4. **Checking PHP session storage** — On a badly configured host, particularly one load-balancing across several servers, PHP session storage may not be shared properly between requests, emptying the cart with no apparent WooCommerce-side cause.
5. **Looking for a plugin that empties the cart** — I check whether a cross-sell, abandoned-cart or promotion plugin calls WC()->cart->empty_cart() at an unexpected moment: rarer, but a real case I’ve run into before.

## What I handle regularly

- The customer adds a product, comes back to the site later, and the cart is empty again
- The cart empties when moving between pages, but not every time
- It only happens with www in the address, or only without www
- The cart stopped working right after enabling a caching plugin or switching hosts
- Impossible to reproduce in private browsing, only in normal browsing

## What breaks a cart session

WooCommerce tracks a cart with two cookies: woocommerce_cart_hash, which detects whether the cart contents changed, and wp_woocommerce_session_…, which links the browser to a server-side PHP session holding the actual contents. If either isn’t carried correctly on every page, WooCommerce can’t find the cart tied to that visitor anymore.

By far the most common cause is a page caching plugin (or a host-level cache) serving a static, logged-out version of a page to a visitor who actually has an active session cookie. The cart, the account pages and the checkout must stay dynamic, never cached like a storefront page.

A domain mismatch, www versus non-www, or http versus https, also changes the effective domain the cookie is attached to: the cart appears to empty when moving between address variants, when in reality it’s two separate sessions.

## What’s a setting, what needs development

> Excluding the cart, account pages and checkout from caching, or fixing a www/non-www mismatch, is hosting configuration. Diagnosing a third-party plugin calling empty_cart() at the wrong moment means reading its code, which is development work.

## Worth reading too

- **Slow WordPress or WooCommerce site** — A misconfigured cache is often the same root cause as an emptying cart. ([/wordpress-woocommerce/site-lent](/wordpress-woocommerce/site-lent))
- **WooCommerce payment problem** — A cart emptying right before payment sometimes gets confused with a blocked checkout. ([/wordpress-woocommerce/probleme-paiement](/wordpress-woocommerce/probleme-paiement))

## FAQ

### Can this actually lose me sales?

Yes, directly: a customer who sees an empty cart often abandons the purchase rather than re-selecting everything. It’s worth treating as a priority, not a minor annoyance.

### Is my caching plugin necessarily to blame?

Not necessarily, but it’s the first thing I check, since it’s the most common cause. Most caching plugins can exclude the cart, it just needs to be configured correctly.

### Why does it work in private browsing but not normal browsing?

Often because an old cookie or a cached session, set before a fix or configuration change, is still active in the normal browser and interferes with the new session.

### Do I need to switch hosts if session storage is the issue?

Not necessarily switch hosts, but sometimes the PHP session storage configuration needs adjusting with them, particularly on hosting spread across several load-balanced servers.
