Skip to content

WordPress WooCommerce caching rules — what to cache, what never to

WordPress WooCommerce caching done wrong creates wrong-cart bugs, leaked sessions, and customer-data exposure. The cacheable / never-cacheable list and the cookie rules.

A WordPress WooCommerce store with an aggressive page cache is fast. A WordPress WooCommerce store with an incorrectly configured page cache leaks one customer’s cart contents to another, serves stale prices, or — in the worst case we have seen on takeover — caches the order-received page and shows one customer’s order to the next visitor. The line between “fast” and “broken” is the cookie rule. Get the cookie rule right and WooCommerce caches well. Get it wrong and the store ships customer data to strangers.

What’s happening

WooCommerce relies on cookies to know whether a visitor is in cart, in checkout, logged in, or browsing anonymously:

  • woocommerce_cart_hash — set when the cart is non-empty
  • woocommerce_items_in_cart — count of items
  • wp_woocommerce_session_<hash> — the actual session token
  • wordpress_logged_in_* — set when logged in (WordPress cookie)

Page-cache layers (LiteSpeed Cache, WP Rocket, W3 Total Cache, FastCGI cache, Cloudflare APO, Bunny CDN) must bypass cache when any of these cookies are present. Otherwise the cache treats a logged-in user the same as anonymous, serves them an anonymous page, and the user sees themselves “logged out.”

The bigger risk is the reverse: caching a logged-in page and serving it to anonymous users. If a WooCommerce site caches the checkout page (which should never happen) and serves a logged-in customer’s page to the next visitor, you have a data leak.

The cacheable / never-cacheable list for WooCommerce:

Cache freely:

  • Homepage (for anonymous users; bypass when cart cookie present)
  • Product category pages (for anonymous users)
  • Single product pages (for anonymous users)
  • Blog posts and content pages
  • Static assets (CSS, JS, images) — long TTL with versioning

Bypass cache always:

  • Cart page (/cart/)
  • Checkout page (/checkout/)
  • My Account pages (/my-account/*)
  • Order received page (/checkout/order-received/)
  • ?wc-ajax= query parameter (cart fragments, checkout AJAX)
  • ?wc-api= query parameter (payment-gateway callbacks, webhooks)
  • ?add-to-cart= query parameter
  • Anything when WooCommerce session cookie is present

Special handling:

  • REST API (/wp-json/) — never cache for write methods, cache reads carefully
  • Admin (/wp-admin/*, wp-login.php) — never cache

How to verify

# Which page-cache plugin is active?
wp plugin list --status=active --format=csv | grep -iE "cache|rocket|litespeed|w3-total"

# Test cache behavior on different pages
# Anonymous request to homepage (should hit cache)
curl -s -I 'https://example.com/' -H 'Cookie: ' | grep -iE "x-cache|cf-cache-status|x-litespeed-cache"

# Request to checkout (should NEVER show "HIT")
curl -s -I 'https://example.com/checkout/' -H 'Cookie: ' | grep -iE "x-cache|cf-cache-status|x-litespeed-cache"

# Request as if cart is non-empty (should bypass)
curl -s -I 'https://example.com/' -H 'Cookie: woocommerce_cart_hash=xyz123' | grep -iE "x-cache|cf-cache-status"

# Check what cookies the page cache bypasses on
# LiteSpeed Cache:
cat .htaccess | grep -A 5 "CacheLookup"
# WP Rocket:
wp config get WP_ROCKET_REJECTED_URI 2>/dev/null

# Cloudflare APO config (check zone settings via API)
curl -s 'https://api.cloudflare.com/client/v4/zones/<zone_id>/settings/automatic_platform_optimization' \
  -H "Authorization: Bearer <token>"

# Test order-received page caching (the data-leak case)
# Place a test order, capture the order-received URL, fetch it from a different session
curl -s -I 'https://example.com/checkout/order-received/12345/?key=wc_order_xxx' | grep -iE "x-cache"

# Object cache health (Redis backed)
wp redis status 2>/dev/null

# Cart fragments — should be cacheable separately
curl -s 'https://example.com/?wc-ajax=get_refreshed_fragments' -H 'Cookie: woocommerce_cart_hash=xyz' | head -5

The single highest-signal test is the checkout-page cache check. If x-cache ever shows HIT on /checkout/, your cache is broken in a dangerous way. Stop everything and fix the bypass rule.

The fix

  1. Bypass cache on the WooCommerce cookies. Every page-cache plugin has this setting; verify it is configured.
    • LiteSpeed Cache: Cache → Cache → Do Not Cache Cookies, add wp_woocommerce_session_, woocommerce_cart_hash, woocommerce_items_in_cart.
    • WP Rocket: Cache → Never Cache (cookies tab).
    • Cloudflare: Cache Rules → Bypass when cookie matches wp_woocommerce_session_|woocommerce_cart_hash|woocommerce_items_in_cart.
    • FastCGI cache (nginx): in the cache key, include $cookie_woocommerce_cart_hash as a fastcgi_cache_bypass condition.
  2. Bypass cache on the WooCommerce URLs.
    • URL patterns: /cart/*, /checkout/*, /my-account/*
    • Query strings: ?wc-ajax=*, ?wc-api=*, ?add-to-cart=* Most cache plugins ship this list as defaults; verify it has not been edited.
  3. Cache only for anonymous users. A “vary by cookie” rule that treats logged-in users as a separate cache key keeps the page fast for both anonymous and signed-in users without leaking data. Cloudflare cannot do this on the standard plan; LiteSpeed and WP Rocket can.
  4. Object-cache the long tail in Redis. Page cache handles pages; object cache handles intra-request lookups. With Redis (Object Cache Pro or the free Redis Object Cache plugin), get_option, wp_cache_get, and WooCommerce’s internal caches all drop to memory. This complements page cache without conflicting.
  5. Test before launch. A small script that fetches the checkout page anonymously, then as a logged-in user, and verifies different responses. Run this in CI.
  6. Audit after any cache-plugin update. Cache plugins ship configuration changes in updates. After WP Rocket / LiteSpeed Cache / W3TC updates, re-run the cache-behavior check from “How to verify.”

For the page-cache foundation, the existing cpwp-litespeed-cache-woocommerce and wp-cache-redis-object-pro-deploy articles are the prerequisites. Pair with Enterprise WordPress operations for the cache-monitoring posture.


Stack Harbor configures WordPress WooCommerce caching layers end-to-end under Enterprise WordPress — the cookie bypass, the URL exclusions, and the data-leak detection. If your store is fast but you are not sure whether one customer can see another’s cart, we can audit and certify the cache layer.