Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Cart empties between pages: how to find and fix broken sessions

OPS-088High impactDetectedBy FunnelGuardPublished Updated
On this page

What this issue is

A session is the server's short-term memory of one visitor. The browser holds a small ID in a cookie, and the server uses that ID to look up the cart, login and other details. If the ID is not sent back, or the server cannot find or write the stored data, each page looks like a brand-new visit and the cart is empty.

Why it costs you leads or sales

Visitors who have chosen a product and lost it rarely start again. Ad clicks you paid for end at an empty cart. Because the site still loads and nothing shows an error, you may only notice when orders drop.

Where the journey breaks
  1. Product pageVisitor clicks Add to cart
  2. Session savedCookie or session file fails
  3. Cart pageShows empty cart
  4. CheckoutNever reached
  5. PurchaseNo order, no purchase tag

The visitor adds a product, but the session is lost on the next page, so everything after it is lost.

Visitors who reach checkout after adding to cartExample numbers
Visitors who reach checkout after adding to cart (example)Sessions working: 60 %; Sessions broken: 5 %02346605Sessions workingSessions broken%

Example: illustrative numbers only. A broken session can cut the share who keep their cart sharply.

How to check if your site has it

Test the cart by hand
  1. Use a clean browser window

    Open a private window so no old cookies interfere. Add a product, then go to the cart.

  2. Watch the cookies

    Open DevTools, then Application (Chrome) or Storage (Firefox), then Cookies. Look for a session cookie such as PHPSESSID, woocommerce_cart_hash, wp_woocommerce_session_*, or cart (Shopify). Check it exists and stays the same between pages.

  3. Check the response headers

    In the Network tab, click the add-to-cart request and look for Set-Cookie. If it is missing, or the response is served from a cache, the session is not being created.

  4. Compare browsers and domains

    Try another browser, and try both www and non-www. If the cart works on one host name but not the other, the cookie domain is the cause.

  5. Check server logs

    Look in the PHP error log for 'session_start(): Failed to write session data' or 'open_basedir' or 'No space left on device'.

Common causes and what you will see
CauseTypical sign
Page cache serves cart pagesCart empty for everyone; no Set-Cookie on cart or checkout
Session save path not writable or disk fullErrors in PHP log; cart empties at random
Cookie domain or path mismatchWorks on www only, or only after a redirect fix
SameSite or Secure flag wrongFails after redirect from a payment or another domain, or on http
Redirects between http/https or www/non-wwwCookie set on one host, cart read on another
Multiple servers with local sessionsCart empties intermittently

How to fix it

Fix the cause you found. Start with caching, because it is the most common one, then cookies, then server storage.

Fix by platform
  1. Exclude cart pages from caching

    In your cache plugin or host cache, never cache the Cart, Checkout and My Account pages, or requests with the woocommerce_items_in_cart cookie. Most WooCommerce-aware cache plugins have this setting; check yours.

  2. Match the site address

    In Settings, General, make WordPress Address and Site Address use the same host (www or not) and https.

  3. Clear caches and test

    Purge page, object and CDN caches, then repeat the add-to-cart test in a private window.

Set the session cookie safely before session_start()php
<?php
session_set_cookie_params([
  'lifetime' => 0,
  'path'     => '/',
  'domain'   => '.example.com', // your domain, covers www and non-www
  'secure'   => true,           // https only
  'httponly' => true,
  'samesite' => 'Lax',
]);
session_start();
Cart behaviour

Broken

  • Cart page is served from cache
  • No session cookie is set or it changes each page
  • Cart is empty after Add to cart

Fixed

  • Cart and checkout bypass the cache
  • One session cookie persists across pages
  • Items stay in the cart through checkout
What a lost session does to the cartInteractive
Session cookie is lost between pages

Session lost

Leads or data lost

The cart page loads empty. The visitor leaves and no purchase is recorded.

Toggle the cause to see the effect on the cart.

How to confirm it's fixed

Confirmation checks
  • In a private window, add a product and open the cart: the item is still there
  • The session cookie is present and unchanged across at least three page loads
  • The cart survives moving between www and non-www, and http to https redirects
  • Checkout shows the same items and totals as the cart
  • Test in at least two browsers, including a mobile one
  • PHP error log shows no session write errors

How to prevent it happening again

Prevention
  • Keep cart, checkout and account paths on the cache exclusion list after every cache, CDN or host change
  • Watch disk space and the session folder size
  • Test the add-to-cart journey after theme, plugin, PHP and hosting changes
  • Keep one canonical domain with redirects
  • Use shared session storage if you add servers
  • Run an automated cart check on a schedule

How FunnelGuard handles this

FunnelGuard detects this today. Its cart assert check has a robot visitor add a product and then checks that the item is still in the cart on the next step. If the cart is empty, the check fails, FunnelGuard re-checks from a second region, and then sends one alert (email, Slack, Teams, WhatsApp, webhook or PagerDuty) with a screenshot and a likely cause.

Questions people ask

Why does my cart empty when I go to another page?

The server is not recognising you between pages. Usual causes are a cached cart page, a missing or blocked session cookie, a cookie set for a different domain, or session data that cannot be saved because of a full disk or unwritable folder.

Why is my WooCommerce cart empty after adding a product?

Most often the cart or checkout page is being cached by a plugin, host or CDN. Exclude the Cart, Checkout and My Account pages from caching, purge all caches and test again in a private window.

How do I check if the session cookie is being set?

Open DevTools, go to the Application or Storage tab and look at Cookies after clicking Add to cart. You should see a session cookie, and the add-to-cart response should include a Set-Cookie header. If neither appears, the session is not being created.

Can a www and non-www mismatch empty the cart?

Yes. A cookie set for one host name is not sent to the other, so the cart is lost when a redirect or link switches between them. Pick one canonical domain and redirect the others to it.

Can a full disk cause the cart to empty?

Yes. PHP file sessions are written to disk, and when there is no space the data fails to save. The PHP error log will usually show a session write failure or 'No space left on device'.

Why does the cart only empty for some visitors?

Browser cookie settings, SameSite rules after a redirect, several servers with separate session storage, or a cache that only serves some requests can all affect only part of your traffic. Test in several browsers and check whether you run more than one server.

How can I be alerted when the cart stops working?

Run an automated add-to-cart test on a schedule. FunnelGuard does this with a cart assert check, re-tests from a second region on failure and sends one alert with a screenshot and likely cause.

Does FunnelGuard catch this?

Detected

FunnelGuard checks for this today.

How: Cart assert.

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.