A shopper drops a $120 item in their cart, hits checkout, and gets greeted by an empty basket—or worse, someone else’s pre-filled shipping address. That nightmare happens the second your edge CDN serves cached dynamic WooCommerce pages to anonymous visitors.
I ran into this exact disaster on a WooCommerce store running on WordPress 6.4 behind StackPath. We dropped global page load times down to 240ms, celebrated for about two hours, and then watched conversions crater because the edge was blindly returning HIT responses on /checkout/. Here’s how to lock this down using StackPath EdgeRules, cookie sniffing, and strict origin headers.

The Cached Cart Disaster: What Actually Breaks
Standard WordPress posts are simple to cache. A visitor requests an article, the edge serves pre-rendered HTML from memory, and your origin server barely breaks a sweat. WooCommerce completely breaks this model.
WooCommerce relies on PHP sessions, nonces, and cookies to track cart state between page transitions. If StackPath caches /cart/ or /checkout/, things go downhill fast:
- The Ghost Cart: A buyer adds items, lands on the cart page, and sees nothing. The edge just handed them a cached snapshot built for an unauthenticated user with zero cookies.
- Session Leaking: If the CDN caches a response right after someone calculates shipping, the next buyer sees that person’s postal code, shipping rate, or even pre-filled form values.
- Dead Payment Nonces: Gateways like Stripe and PayPal generate one-time security nonces. If twenty buyers get the same cached checkout HTML, nineteen of them will trigger payment gateway errors during authorization.
The goal is simple: let the edge cache your catalog, category archives, and static assets aggressively, but force it to step out of the way the instant a shopper touches a cart.
Understanding WooCommerce Session Cookies and Headers
WooCommerce is actually smart about cookies out of the box. It doesn’t send dynamic session cookies to fresh visitors who are just browsing your catalog, which keeps your product pages cache-friendly.
The second someone clicks “Add to Cart”, WooCommerce sets three distinct cookies:
woocommerce_items_in_cart: Set to1when there are items in the basket. Client-side scripts use this to toggle cart counts.woocommerce_cart_hash: An MD5 hash of the cart contents, used to track changes.wp_woocommerce_session_*: A unique hash that ties the visitor back to their row in thewp_woocommerce_sessionsdatabase table (holding cart items, coupons, and tax calculations).
If any of these cookies show up in an incoming request, StackPath must never serve cached HTML. We also need this same safeguard for logged-in accounts, which I covered in detail when setting up how to bypass CDN cache for logged-in WordPress users in StackPath.
Rule 1: Bypass Cache for WooCommerce Core URL Paths
The easiest safety net is matching hard URL patterns in the StackPath portal. Even if someone somehow hits checkout without an active session cookie, that page must never get written to edge storage.
In your StackPath dashboard, pick your CDN site and head to the EdgeRules tab. Click Add EdgeRule to create your base path exclusion:
- Name:
Bypass WooCommerce Dynamic URIs. - Under If (Conditions), select Request URL.
- Set the operator to matches regular expression or matches wildcard.
- Input the dynamic URI path string:
*/(cart|checkout|my-account|wc-api|addons)/* - Under Then (Action), select Cache Expiration and choose Bypass Cache.
- Add another Action: Set Response Header with Header Name
X-Edge-Cache-Policyand ValueWooCommerce-Path-Bypass.
That custom response header is a lifesaver when debugging with curl later. If you see it in your terminal, you know the rule matched and did its job.
Rule 2: Bypass Cache on Active WooCommerce Cookies
URL matching covers /cart/ and /checkout/, but what about your header cart? Most modern stores have a mini-cart counter or dropdown in the global navigation bar across every single post and product page.
If a customer adds a product to their cart and clicks back to the homepage, a naive edge rule will serve them a cached homepage with an empty cart icon. To fix this without killing page caching for everyone, add a rule that watches for cart cookies:
- Click Add EdgeRule and name it:
Bypass on WooCommerce Cart Cookies. - Set the condition to Request Cookie.
- Set the operator to matches regular expression.
- Insert the regex pattern matching WooCommerce state cookies:
(woocommerce_items_in_cart|woocommerce_cart_hash|wp_woocommerce_session_) - Under Action, choose Cache Expiration -> Bypass Cache.
- Leave edge compression stripping off if your origin depends on specific response headers.
This keeps anonymous traffic blazing fast on cached pages, but the millisecond a buyer adds a product, their entire session bypasses the edge cache so dynamic cart fragments stay in sync.
Rule 3: Handling Cart Fragments and WooCommerce AJAX Endpoints
WooCommerce uses cart fragments (via /?wc-ajax=get_refreshed_fragments) to update cart counts across cached pages asynchronously. If your CDN intercepts or caches these AJAX queries, your cart counter will freeze or display old totals.
Cart fragments trigger via query parameters or through admin-ajax.php. If you followed our earlier guide on how to ignore query strings on static assets in StackPath CDN, double-check that your static rules aren’t accidentally scooping up these dynamic PHP endpoints.
Create a dedicated rule to force dynamic bypass on all WooCommerce AJAX calls:
- Rule name:
Bypass WooCommerce AJAX Endpoints. - Condition: Request URL matches wildcard:
*?wc-ajax=* - Add an OR condition: Request URL matches wildcard:
*admin-ajax.php* - Action: Cache Expiration -> Bypass Cache.
This lets your origin PHP workers handle cart updates in real time without the edge getting in the way.
Origin Web Server Headers: Hardening Nginx and Apache
StackPath respects upstream Cache-Control headers when configured to honor origin instructions. Relying strictly on CDN dashboard settings is risky—if an edge rule gets accidentally deleted or you migrate DNS, you don’t want your store suddenly caching checkouts. The cleanest architecture is having your origin web server explicitly broadcast no-store headers on cart pages.
For Nginx, drop this inside your primary server block right before your standard WordPress rewrite rules:
Add this Nginx configuration to disable cache headers on cart and account paths:
# Match dynamic WooCommerce routes and force zero-cache headers
location ~* ^/(cart|checkout|my-account|wc-api)/ { try_files $uri $uri/ /index.php?$args; add_header Cache-Control "no-store, no-cache, must-revalidate, max-age=0" always; add_header Pragma "no-cache" always; add_header X-Origin-Cache-Control "Bypass-WooCommerce" always;
}Reload Nginx to activate the new routing rules:
sudo nginx -t && sudo systemctl reload nginxIf you’re on Apache or LiteSpeed, add these directives to your root .htaccess file directly above the standard # BEGIN WordPress marker:
Add the following directives to your .htaccess configuration:
# Force no-cache on dynamic WooCommerce paths SetEnvIf Request_URI "^/(cart|checkout|my-account|addons)" WOO_NOCACHE=1 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" env=WOO_NOCACHE Header set Pragma "no-cache" env=WOO_NOCACHE Header set Expires "0" env=WOO_NOCACHE
As the MDN Cache-Control documentation notes, setting no-store tells every intermediate proxy, CDN, and browser not to stash a single byte of that response.
Origin Shield Considerations
If you have StackPath Origin Shield enabled, requests pass through an intermediate regional POP before reaching your real server. This prevents massive traffic spikes from crushing WordPress, as detailed in our guide on how to configure StackPath Origin Shield to protect origins from spikes.
Origin Shield can buffer responses if your EdgeRules do not specify an immediate origin pass-through. Inside your EdgeRules, check the ordering. StackPath evaluates rules strictly from top to bottom:
- Rule 1: Bypass WooCommerce Dynamic URIs (Priority: 1)
- Rule 2: Bypass on WooCommerce Cart Cookies (Priority: 2)
- Rule 3: Bypass WooCommerce AJAX Endpoints (Priority: 3)
- Rule 4: Edge cache catalog items (Priority: 10)
Keep your bypass rules at the very top of the list. If a broad caching rule executes first, StackPath will store the response before it ever evaluates the cookie condition.
Testing Edge Rules with cURL: Verification Commands
Don’t use a regular browser to test this. Browser caches and extensions will lie to you. Use curl to see exactly what the CDN edge POP returns.
First, test that the /checkout/ path returns an explicit bypass status without any cookies attached:
Run this command in your terminal to inspect headers:
curl -I -X GET https://example.com/checkout/ -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)"Inspect the output headers. You should see:
Expected header response block:
HTTP/2 200
server: StackPath
cache-control: no-store, no-cache, must-revalidate, max-age=0
x-cache: BYPASS
x-edge-cache-policy: WooCommerce-Path-BypassNow test an arbitrary static post while sending a mock WooCommerce session cookie. This proves whether Rule 2 catches active shoppers on catalog pages:
Send a request with an active cart cookie:
curl -I -X GET https://example.com/sample-product/ -H "Cookie: woocommerce_items_in_cart=1; wp_woocommerce_session_abc123=xyz789" -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)"If your cookie EdgeRule is configured properly, x-cache must return BYPASS or MISS, never HIT. If it returns HIT, your regular expression does not match the cookie string or your rule ordering is inverted.
A Real Gotcha: The Set-Cookie Header Strip
Here is an edge case that burned half a day of debugging on a client launch. New visitors clicked “Add to Cart” from a product archive, the AJAX call succeeded, but as soon as they clicked any link, their cart emptied out.
The culprit was a poorly constructed StackPath optimization rule that stripped the Set-Cookie header on responses to boost cache hit ratios. Because the edge stripped Set-Cookie, the customer’s browser never stored wp_woocommerce_session_*, so every single request looked like a first-time guest.
You can trace this in WordPress using standard tools from the WordPress Developer Resources. If you need to verify whether session cookies are actually being dispatched by PHP, drop this small snippet into your child theme’s functions.php temporarily:
Add this debug code to monitor session cookie issuance:
session) { header('X-Debug-WC-Session-ID: ' . sanitize_text_field(WC()->session->get_customer_id())); } }
});Make sure your CDN EdgeRules never include the action Strip Response Headers for Set-Cookie on non-static assets. Reserve header stripping strictly for images, fonts, CSS, and JS files.
Automating Edge Purges on Store Updates
Whenever you update pricing, alter shipping rules, or deploy theme changes to your checkout templates, you must purge edge copies without clearing static image caches. You can automate this pipeline using API hooks or through CI scripts like those in our guide on how to purge StackPath CDN cache with GitHub Actions.
To purge just the checkout assets and dynamic paths via the StackPath v2 API from a deploy script, run:
Execute this API request to clear specific paths:
curl -X POST https://gateway.stackpath.com/cdn/v2/stacks/${STACK_ID}/sites/${SITE_ID}/purge -H "Authorization: Bearer ${API_TOKEN}" -H "Content-Type: application/json" -d '{ "items": [ {"url": "https://example.com/cart/", "recursive": true}, {"url": "https://example.com/checkout/", "recursive": true} ] }'Targeted purges prevent cache stampedes on your product pages while ensuring stale cart code gets cleared immediately after deployments.
Frequently Asked Questions
Can I just tell StackPath to cache everything and exclude cart URLs?
No. Excluding only the cart and checkout URLs leaves your mini-cart headers broken on catalog and archive pages. You must also bypass the cache whenever WooCommerce session cookies are detected in the request.
Will bypassing checkout slow down my store’s Google PageSpeed score?
Not at all. Google crawls your store as an unauthenticated guest without items in a shopping cart. The crawler visits catalog pages, blog posts, and category archives, all of which remain heavily cached at the edge. Google does not index or score your checkout page performance.
Why does my checkout still show x-cache: HIT after setting EdgeRules?
Almost always rule ordering. If a broad rule like “Cache All HTML” sits above your bypass rules, StackPath executes that rule first. Drag the WooCommerce bypass rules to the top of the EdgeRules table and save your changes.
Does this work the same way if I use WooCommerce Blocks checkout?
Yes. The WooCommerce Cart and Checkout Blocks rely heavily on the WordPress REST API (/wp-json/wc/store/v1/cart). Make sure your EdgeRules also bypass any routes matching /wp-json/wc/* when session cookies are present.
Next Steps for Your Edge Stack
Once your cart rules are firing cleanly, review your remaining dynamic routes. If your store runs membership plugins, subscription modules, or customer dashboards, those endpoints need identical cookie-bypass rules.
Next, read our walkthrough on how to bypass CDN cache for logged-in WordPress users in StackPath to keep your store administrators and account holders running directly against origin workers.

