All posts

WooCommerce invalid nonce at checkout: why caching breaks Place order

A nonce is a short-lived token WordPress puts in a form so the server can tell the request came from a page it served recently. WooCommerce uses one on the checkout form and another on every Store API call from the block checkout. When the token is older than WordPress accepts, or was made for someone else’s session, the order is refused before payment is even tried. In most stores the cause is the same: a checkout page served from a cache.

Free checkout scan

Enter your store address. A real browser adds a product to the cart and walks the checkout up to the payment step, like a customer, and shows you every step with a screenshot.

  • Free, no account
  • Stops before payment, no order
  • Nothing to install
· 4 min read
A laptop showing the WordPress logo

What the error looks like

On the classic checkout the order fails after Place order with a notice such as "We were unable to process your order, please try again" or "Sorry, your session has expired". The form carries the token in a hidden field named woocommerce-process-checkout-nonce.

On the block checkout the browser talks to the Store API (/wp-json/wc/store/v1/…) and sends the token in a Nonce header. A bad one comes back as woocommerce_rest_invalid_nonce, a missing one as woocommerce_rest_missing_nonce, and the checkout shows a generic error.

"Payment nonce is missing" is a different message with the same word. It comes from card gateways such as Braintree or PayPal, whose script did not return a payment token to the form. That one is a payment-script problem, covered in PayPal Payments problems on WooCommerce.

Why a cache causes it

WordPress nonces are valid for 12 to 24 hours, and for a guest WooCommerce ties them to the shopper’s session cookie. A cached checkout page hands every visitor the token that was generated for whoever loaded the page first. It fails when it gets too old, and it can fail sooner because it belongs to another session.

Cache plugins such as WP Rocket and LiteSpeed Cache leave cart, checkout and my-account out of the cache by default. The usual culprit is a layer above WordPress that does not know about WooCommerce: a hosting page cache (Varnish, nginx FastCGI cache), a Cloudflare "Cache Everything" rule, or a CDN set to cache HTML.

A cache rule written for speed

A rule like "cache every HTML page for 4 hours" breaks checkout only for some buyers, at some times. That is why it so often survives testing by the store owner, who is logged in and bypasses the cache.

Visitor Aloads /checkout/ firstCache stores the pagenonce = AVisitor Bgets the cached pagePlace ordernonce A + session Binvalid nonceorder refused, no payment triedFix: never cache /checkout/,wc-ajax or the Store API
A cached checkout serves the token made for the first visitor. The next buyer submits it with a different session, and the order is refused.

How to confirm it

bash
curl -sI https://example.com/checkout/ \
  | grep -iE "cf-cache-status|x-cache|x-litespeed-cache|^age|cache-control"
A HIT or an age above zero on /checkout/ means the page is cached
  1. Open the checkout in a private window. Logged out, with an item in the cart, the way a buyer sees it.
  2. Check the response headers. In DevTools → Network, select the /checkout/ document. cf-cache-status: HIT, x-cache: HIT, x-litespeed-cache: hit or a large age value mean the page came from a cache.
  3. Compare tokens. View the page source in two different private windows and search for woocommerce-process-checkout-nonce. The same value in both means both visitors got one cached page.
  4. Watch the order request. Place the order and look at the ?wc-ajax=checkout or Store API response. A nonce error there confirms it.

The fix: what to keep out of the cache

Keep out of the cacheWhy
/cart/, /checkout/, /my-account/The pages carry per-session tokens and cart contents
?wc-ajax=*Classic checkout, coupons, shipping recalculation
/wp-json/wc/store/*Block cart and checkout (Store API)
Requests with woocommerce_items_in_cart or wp_woocommerce_session_* cookiesA shopper with a cart must never get a shared page
nginx
# nginx FastCGI cache: never cache checkout or a shopper with a cart
set $skip_cache 0;
if ($request_uri ~* "/(cart|checkout|my-account)/|wc-ajax=|/wp-json/wc/store/") {
  set $skip_cache 1;
}
if ($http_cookie ~* "woocommerce_items_in_cart|wp_woocommerce_session_") {
  set $skip_cache 1;
}
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
code
(http.request.uri.path contains "/checkout" or http.request.uri.path contains "/cart" or http.request.uri.path contains "/my-account" or http.request.uri.path contains "/wp-json/wc/store" or http.request.uri.query contains "wc-ajax" or http.cookie contains "woocommerce_items_in_cart" or http.cookie contains "wp_woocommerce_session_")
Cloudflare → Caching → Cache Rules, action Bypass cache

Set those exclusions in every layer that caches HTML: the plugin, the host’s cache and the CDN. For Cloudflare that means a Cache Rule that bypasses the cache for those paths and cookies; the details are in Cloudflare and the WooCommerce checkout. Then purge everything, because pages already cached keep their old tokens until they expire.

For speed, cache the product and category pages. They get most of the traffic and carry no checkout token.

Catching it before buyers do

A nonce problem is easy to miss because the page looks fine: the form renders and totals update, and only the final submit fails. A test that stops before Place order will not see it. A test that submits an order as a guest, from outside, will.

MageSentinel walks the WooCommerce checkout as a guest in a real browser on a schedule. With the MageSentinel plugin connected and real test orders turned on, it places the order, reports the step that failed with a screenshot, and the plugin cancels the order afterwards. You can also run the free WooCommerce checkout checker once without signing up. For other reasons Place order fails, see WooCommerce checkout stuck on processing.

Find out your checkout broke before your customers do.

Real checkout checks for Magento and WooCommerce · free plan · no card requiredWooCommerce checkout monitoring →
FAQ

Common questions

Still have a question?More answers, and a way to reach us.Support →
01What does invalid nonce mean in WooCommerce?

The security token sent with the checkout or Store API request is too old or belongs to another session, so WooCommerce refuses the request. A cached checkout page is the most common cause.

02How long is a WordPress nonce valid?

Between 12 and 24 hours by default. A page cached for longer than that serves an expired token.

03Is "payment nonce is missing" the same error?

No. That message comes from a card or PayPal gateway whose script did not return a payment token. Look at JavaScript errors and the gateway script, not the page cache.