Skip to content

Cloudflare APO breaking the WooCommerce cart: stale mini-carts and empty checkouts

APO caches full HTML at the edge, and WooCommerce carts are the first thing to go strange — wrong item counts, carts that empty themselves. What APO bypasses by default and where stores still get burned.

A WooCommerce store turns on Cloudflare APO and within days the reports arrive: the header cart shows 0 items after adding a product, the mini-cart displays someone’s stale count, or the cart page flashes items that then vanish. APO is not blindly caching your checkout — it ships with WordPress- and WooCommerce-aware bypasses — but those bypasses assume a stock setup. The breakage almost always comes from a theme that prints cart state directly into cacheable HTML, a performance plugin that disabled cart fragments, or an extra “cache everything” rule stacked on top of APO.

What’s happening

APO stores rendered WordPress HTML at the Cloudflare edge and serves it without touching the origin. To coexist with commerce it bypasses the edge cache when the request carries state cookies — the wordpress_logged_in_ family, woocommerce_items_in_cart, woocommerce_cart_hash, and wp_woocommerce_session_ — and it respects the Cache-Control: no-cache headers WooCommerce sends on the cart, checkout, and account pages. A visitor with something in their cart therefore gets origin-rendered pages, and an anonymous browser gets cached ones.

The dynamic part of every other page — the header cart count and mini-cart — is WooCommerce’s job, done client-side via cart fragments: a wc-ajax=get_refreshed_fragments POST that fetches current cart HTML and swaps it into the cached page. That division of labour is where stores break it:

  • The theme prints the cart count server-side without registering it as a fragment. The count gets baked into the cached HTML, so every anonymous visitor sees whatever the cache captured — usually 0, sometimes another shopper’s pre-cookie state.
  • Cart fragments were disabled by a performance plugin or snippet (“cart fragments slow down your site” is common advice). Without fragments, nothing corrects the cached HTML after an AJAX add-to-cart.
  • A custom Cache Everything rule sits on top of APO and, unlike APO, knows nothing about WooCommerce cookies — it happily caches HTML for shoppers mid-session, or caches a wc-ajax GET some plugin performs.

What to check first

  • Does the problem affect only anonymous shoppers before login? (Points at cached HTML plus a fragments gap.)
  • Was a “disable cart fragments” optimization applied — in the theme, a snippet plugin, or a performance plugin’s WooCommerce tab?
  • Do you have Cache Rules or legacy Page Rules with Cache Everything alongside APO? List them before touching anything.
  • Plan note: APO is a paid add-on (US$5/month) on the Free plan and included on Pro and above — if the store pays for it, it deserves ten minutes of configuration review.

How to verify

Confirm what the edge is doing for a cookie-less visitor versus a shopper with a cart:

# Anonymous request: expect an APO edge hit on a product page
curl -sI https://www.example.com/product/sample/ \
  | grep -iE 'cf-cache-status|cf-apo-via|cf-edge-cache|age'

# Simulated shopper with items in cart: expect BYPASS/DYNAMIC, not HIT
curl -sI -H 'Cookie: woocommerce_items_in_cart=1' \
  https://www.example.com/product/sample/ \
  | grep -iE 'cf-cache-status|cf-apo-via'

# Cart and checkout must never be edge cache hits
curl -sI https://www.example.com/cart/ | grep -iE 'cf-cache-status|cache-control'
curl -sI https://www.example.com/checkout/ | grep -iE 'cf-cache-status|cache-control'

A cf-cache-status: HIT on the cookie-bearing request or on /cart/ means a rule other than APO is caching past the bypasses. Then check the front end: in browser devtools, add a product to the cart and watch the Network tab for the wc-ajax=get_refreshed_fragments POST. If it never fires, fragments are disabled and the cached header count will never update.

The fix

  1. Re-enable cart fragments if anything disabled them. On an APO store, fragments are not optional decoration — they are the only mechanism that reconciles cached HTML with real cart state. Remove the dequeue wc-cart-fragments snippet or the plugin toggle.
  2. Make the theme fragment-aware. Any element showing cart count or totals must be registered through the woocommerce_add_to_cart_fragments filter so the AJAX response replaces it, instead of being rendered once into cacheable HTML.
  3. Remove or scope Cache Everything rules that overlap APO. APO already handles HTML caching with WooCommerce awareness; a blanket rule on /* is redundant and dangerous. If you keep any cache rule, add explicit bypass conditions for the WooCommerce cookies and for URLs containing wc-ajax.
  4. Keep the official Cloudflare plugin active so purges fire on product and content updates — APO without its purge integration serves stale catalogue pages until TTL expiry.
  5. Re-test the full shopper journey: anonymous browse, add to cart, cart page, checkout, then a second browser to confirm no leaked state. The curl checks above should show HIT only on the anonymous, cookie-less requests.

When this fix is wrong

  • Carts emptying for logged-in users too, with APO bypassing correctly, points at PHP session or object-cache trouble at the origin (Redis evictions, load-balanced servers without shared sessions) — not the edge.
  • Random cart contents swapping between users with cf-cache-status: HIT on cookie-bearing requests is a server-side page cache (LiteSpeed, nginx FastCGI cache, a host cache) caching per-shopper HTML. Fix that layer; APO is the innocent bystander.
  • Checkout errors about expired nonces after long idle times are WordPress nonce lifetime versus cache TTL — a purge schedule question, not a fragments question.

Common mistakes

  • Disabling cart fragments for PageSpeed points on a store that relies on them under APO.
  • Stacking Cache Everything on top of APO “for extra speed” — it mostly adds extra incidents.
  • Testing only as an admin, whose logged-in cookie bypasses everything, then declaring the store healthy.
  • Purging the edge cache manually after every complaint instead of fixing the cache key and fragment logic.
  • Forgetting that APO caches per-device-type and per-cookie rules, so “works on my laptop” proves nothing about the mobile cache entry.

Prevention

  • Add the three curl checks above to a synthetic monitor that runs hourly against a product page, the cart, and the checkout.
  • Treat every new performance plugin or theme update as a cart-regression risk: re-run the shopper journey after each one.
  • Keep APO’s configuration deliberate — cache key, purge hooks, and real-IP restoration are covered in Cloudflare APO deep configuration, and the official behaviour reference is the APO documentation.
  • If you decide APO is more machinery than the store needs, the cookie-bypass recipe without APO is documented in WooCommerce cache exclusions on Cloudflare without APO.

A cart that lies to shoppers costs more than slow TTFB ever did. Need Cloudflare stabilized in front of a WordPress or WooCommerce site that earns money? Stack Harbor runs that exact stack under managed enterprise WordPress hosting — book an infrastructure consult.