Skip to content

WooCommerce "Sorry, your session has expired" at checkout

Fix the WooCommerce checkout error "Sorry, your session has expired. Return to shop" so shoppers can place orders again. You will find where the shopper's cart session gets lost, in a cache, a cookie or the sessions table, and prove the fix with a test that creates no order.

A shopper fills in your WooCommerce checkout, clicks Place order, and gets “Sorry, your session has expired. Return to shop” instead of an order confirmation. WooCommerce shows this message when the cart is empty at the moment the order is posted, which means the server could no longer find that shopper’s session. The session usually goes missing in one of three places. It can be a page cache or a CDN (content delivery network, the servers that hold copies of your pages) in front of the store. It can also be the session cookie itself, or the database table that holds the cart. Run the safe curl test in step 2 first, because it tells you within a minute whether the session reaches PHP at all.

What you’ll accomplish

  • Know which check in WooCommerce produces the message, and what the related “We were unable to process your order” message means.
  • Find out whether a page cache, a CDN or a cookie problem stops the session from reaching PHP.
  • Read the shopper’s session row in the database and check how long sessions really last on your store.
  • Confirm the fix with a checkout request that cannot create an order.

Prerequisites

You need SSH or cPanel Terminal access as the site’s user, and WP-CLI (the wp command, which runs WordPress tasks from the shell). The examples use https://www.example.com and the default table prefix wp_. Replace both with your own values. The facts below match current WooCommerce source (version 11.x) and the classic checkout, the one built with the [woocommerce_checkout] shortcode.

The newer Checkout block uses the Store API (WooCommerce’s REST interface for carts and checkout) and reports the same problem with different words. The Troubleshooting section covers it.

How it works

WooCommerce keeps each guest’s cart in a session. Two pieces have to meet on every request:

  • The cookie. Its name is wp_woocommerce_session_ followed by a hash of your site address. Its value holds a customer ID (for guests, t_ plus 30 random characters), an expiry time, a renewal time and a signature, separated by | characters (%7C once encoded; older versions used ||). WooCommerce builds that signature from the secret keys in wp-config.php, so a changed key makes every existing cookie invalid.
  • The row. WooCommerce stores the cart contents in wp_woocommerce_sessions, one row per customer ID, and a session_expiry column holds a Unix timestamp. With a persistent object cache (a memory store such as Redis that keeps database results between requests), WooCommerce checks that cache before the table.

A guest session lasts 48 hours, and a logged-in customer’s lasts 7 days. Once a guest session is more than 24 hours old, the next visit extends it. Two filters can change those numbers, wc_session_expiration and wc_session_expiring. Every 12 hours a background task named woocommerce_cleanup_sessions deletes expired rows. Current versions schedule it in Action Scheduler, the job queue that ships with WooCommerce, instead of as a plain WP-Cron event.

When the shopper clicks Place order, the browser posts the form to /?wc-ajax=checkout. WooCommerce then checks two things, in this order:

  1. The nonce, a short-lived token printed in the form that proves the form was built for this visitor. For guests it is tied to the session’s customer ID. If it fails and the cart is empty, you get “Sorry, your session has expired”. If it fails while the cart still has items, the message is “We were unable to process your order, please try again.”
  2. The cart. If the nonce passes but the cart is empty, WooCommerce stops with the same expiry message.

One more detail explains why the message feels sudden. When WordPress builds the checkout page for a visitor whose cart is empty, it sends them to the cart page instead. That page then says “Your cart is currently empty”. So a shopper who saw a full checkout form lost the cart after the page loaded. The other possibility is that WordPress never built that page, because a cache served it.

Request path of a checkout in four steps. Step 1, the browser sends the wp_woocommerce_session cookie; a warning beside it says the cookie can be missing because it expired, was blocked, or was set on another host. Step 2, the cache or CDN; the warning says it can strip the cookie or serve a cached checkout page. Step 3, PHP looks up the session row in woocommerce_sessions; the warning says the signature can fail or the row can be gone. Step 4, highlighted, is the cart check in process_checkout. An empty cart leads to the red error Sorry, your session has expired. A cart with items lets the checkout continue.

Step-by-step

1. Reproduce it and read the failing request. Open a private browser window, add one product to the cart and go to checkout. Open the developer tools (F12) on the Network tab. Then click Place order with a payment method that needs no real card, such as Cash on delivery turned on for a few minutes. When the error appears, no order was created. Find the request whose address ends in ?wc-ajax=checkout and look at its Cookies panel. If you have no safe way to submit the form on the live store, skip to step 2, which gives the same answer without a browser.

  • If no wp_woocommerce_session_ cookie was sent, the browser or something in front of the server lost it. Continue with steps 2 to 4.
  • If the cookie was sent and you still get the message, PHP cannot use it. Go to steps 5 and 6.

2. Test the session path from the shell. This test follows the browser’s path through your CDN, and it cannot create an order. Replace 123 with the ID of a simple, in-stock product.

curl -s -c /tmp/wcjar -o /dev/null -D - "https://www.example.com/shop/?add-to-cart=123" | grep -i "set-cookie: wp_woocommerce"

Example output:

set-cookie: wp_woocommerce_session_8c2d41f07e9a3b5c6d1e0f2a4b7c9d3e=t_4be19a07c3d85f2e6a1b9c04d7e3f8%7C1791041872%7C1790955472%7C9f3c27a1b8e64d05c2f7a9e13b6d4c80; expires=Sat, 03 Oct 2026 15:37:52 GMT; Max-Age=172800; path=/; secure; HttpOnly

No line at all means the add-to-cart response came from a cache, or something stripped the cookie. Now post a checkout with a deliberately wrong nonce, once with the cookie and once without:

curl -s -b /tmp/wcjar -d "woocommerce-process-checkout-nonce=test" "https://www.example.com/?wc-ajax=checkout" | grep -o "We were unable to process your order\|Sorry, your session has expired"
curl -s -d "woocommerce-process-checkout-nonce=test" "https://www.example.com/?wc-ajax=checkout" | grep -o "We were unable to process your order\|Sorry, your session has expired"

Expected output on a healthy store:

We were unable to process your order
Sorry, your session has expired

The first line proves the cookie reached PHP and the cart was found. The wrong nonce then stopped the order safely. If the first command also prints “Sorry, your session has expired”, the session is lost on the way in, and steps 3 to 6 find where. On a store in another language, search for a short part of each translated message that has no accented letters. The response is JSON, so accented letters arrive escaped (é becomes \u00e9) and will not match.

3. Check whether the checkout page is cached. Request it without any cookie:

curl -s -o /dev/null -D - https://www.example.com/checkout/ | grep -iE "^HTTP|^location|cache-control|cf-cache-status|x-cache|^age"

Expected output, a redirect to the cart because this request has no cart:

HTTP/2 302
cache-control: no-cache, must-revalidate, max-age=0, private
location: https://www.example.com/cart/

A 200 with cf-cache-status: HIT, x-cache: HIT or an age above 0 means a cache answered for WordPress. Shoppers then see a checkout form that WordPress never built for them, with someone else’s nonce in it. Exclude /cart/, /checkout/, /my-account/ and any URL containing wc-ajax from every cache layer. Also make sure requests carrying a wp_woocommerce_session_ cookie skip the cache and keep their Cookie header. Our article on WooCommerce cache bypass cookies gives the rules for Cloudflare. WooCommerce lists the paths to exclude in its caching plugin documentation. Purge the cache after changing the rules.

4. Check the host and the scheme. Unless COOKIE_DOMAIN is set in wp-config.php, the cookie belongs to the exact host that set it. A secure cookie is also never sent over http. Ask WordPress which addresses it builds for the store and for checkout:

wp eval 'echo home_url(), PHP_EOL, wc_get_checkout_url(), PHP_EOL;'

Example output:

https://www.example.com
https://www.example.com/checkout/

Both lines must use the same scheme and host, and that host must be the one shoppers type. Then confirm the other variants redirect:

curl -s -o /dev/null -w "%{http_code} %{redirect_url}\n" http://example.com/checkout/

Expected output:

301 https://www.example.com/checkout/

A 200 here means the store answers on a second address. A shopper who adds to cart on one address and checks out on the other arrives with no session. Add a permanent redirect to the canonical address at the server or CDN.

5. Check how long sessions really last. Look at guest sessions in the table:

wp db query "SELECT COUNT(*) AS guest_sessions, ROUND((MAX(session_expiry) - UNIX_TIMESTAMP()) / 3600, 1) AS newest_hours_left, SUM(session_expiry < UNIX_TIMESTAMP()) AS expired_not_deleted FROM wp_woocommerce_sessions WHERE LEFT(session_key, 2) = 't_'"

Example output:

guest_sessions	newest_hours_left	expired_not_deleted
2716	47.9	38

newest_hours_left should sit slightly under 48. A value near 0.5 means code shortened the lifetime to about 30 minutes, so find it:

grep -rn "wc_session_expiration\|wc_session_expiring" wp-content/plugins wp-content/themes wp-content/mu-plugins --exclude-dir=woocommerce

Example output:

wp-content/mu-plugins/store-tweaks.php:14:add_filter( 'wc_session_expiration', fn() => 1800 );

Run that search from the WordPress root folder. Remove the filter or raise it to at least 172800 seconds (48 hours). A large expired_not_deleted count, in the thousands, means the cleanup task is stuck. Check it:

wp action-scheduler action list --hook=woocommerce_cleanup_sessions --status=pending --fields=hook,status,scheduled_date

Example output:

+------------------------------+---------+---------------------------+
| hook                         | status  | scheduled_date            |
+------------------------------+---------+---------------------------+
| woocommerce_cleanup_sessions | pending | 2026-10-01 18:00:00 +0000 |
+------------------------------+---------+---------------------------+

A date in the past means the queue is not being processed. Action Scheduler is itself started by WP-Cron, so look for DISABLE_WP_CRON in wp-config.php without a real cron job to replace it. A stuck cleanup does not cause the error on its own, but a huge table slows every cart write.

6. Check the table and the shopper’s row. Confirm the table exists and is healthy:

wp db query "CHECK TABLE wp_woocommerce_sessions"

Example output:

Table	Op	Msg_type	Msg_text
shopdb.wp_woocommerce_sessions	check	status	OK

“doesn’t exist” means a migration skipped the table. Recreate it under WooCommerce > Status > Tools > Verify base database tables. A success shows “Database verified successfully.” A crash or “Table is full” message points to the database server, so check free disk space with df -h. Next, take the customer ID from the cookie in step 2 (the part before the first %7C) and look up its row:

wp db query "SELECT session_key, FROM_UNIXTIME(session_expiry) AS expires_at, LENGTH(session_value) AS bytes FROM wp_woocommerce_sessions WHERE session_key = 't_4be19a07c3d85f2e6a1b9c04d7e3f8'"

Example output:

session_key	expires_at	bytes
t_4be19a07c3d85f2e6a1b9c04d7e3f8	2026-10-03 15:37:52	1843

No row while the cookie exists means the write failed or something deleted it. If many shoppers lost their carts at the same moment, check whether the secret keys in wp-config.php changed. A security plugin’s “regenerate salts” feature or a restore from another copy does this. The tell is that every wp-admin user was logged out at the same time. Carts started after the change work normally.

Validate it works

Rerun the two checkout commands from step 2. The request with the cookie must print “We were unable to process your order”, and the one without must print “Sorry, your session has expired”. Then rerun step 3 and confirm the 302 to /cart/ with no cache HIT.

Finally, place one real test order in a private window, with the same no-card payment method as step 1. Add a product, go to checkout, change the postcode once so the order summary refreshes, then click Place order. You should land on the Order received page. Delete the test order and turn off the test payment method afterwards. Remove the cookie file with rm /tmp/wcjar.

Troubleshooting

Shoppers see “We were unable to process your order, please try again.” instead. Their cart is fine but the nonce is stale. This is the classic sign of a cached checkout page served to someone who has items in the cart. Fix the cache rules from step 3. A browser that restores the page from its back-forward cache can cause it too, and a reload clears it.

Only some shoppers are affected, at random times. Look for a WAF (web application firewall, a filter in front of the site) or bot rule that removes cookies from wc-ajax requests. Also check for a cookie-consent tool that blocks or deletes the wp_woocommerce_session_ cookie until consent is given. That cookie is needed for the cart to work at all, so classify it as strictly necessary. If the step 2 test passes from the shell but fails in a browser, the cause is on the browser side.

It started on a load-balanced store. Each web server must read the same database and the same object cache. If every server keeps its own local cache, one server can hand back an older, empty copy of the session. Point all servers at one shared Redis instance, with a key prefix unique to this site.

The Checkout block shows a different message. The block posts to /wp-json/wc/store/v1/checkout. It reports “Cannot place an order, your cart is empty.” or “Nonce is invalid.” instead. It reads the same session cookie and the same table, so steps 3 to 6 apply unchanged.

The cart is already empty when the checkout page loads. That is an earlier failure, before checkout. Our guide to add to cart not working follows the session from the add-to-cart click.

When this is the wrong approach

If a single shopper left the checkout tab open for more than two days, the message is WooCommerce working as designed. Avoid stretching guest sessions much past a few days, because the table grows with every visitor. A custom headless storefront is a separate front end that talks to WooCommerce only through its API. There, the session travels in a Cart-Token header instead of a cookie, so check your front end first. For hook-level details, the WooCommerce developer documentation is the reference.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.