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.
How I go about it
-
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.
-
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.
-
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.
-
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.
-
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.
Worth reading too
Describe your need in one minute
A few targeted questions so I can reply with an estimate rather than another questionnaire.