DEV3 Technologies home

DEV3 Developer Forum

Why do WooCommerce cart items disappear or show to other users when caching is on?

WordPress helpSolved0 views
dev3 ·

Since I enabled page caching, customers report an empty cart or the wrong mini-cart count. How should caching be configured for WooCommerce?

#woocommerce#caching#performance

0

1 reply

dev3 · Accepted answer

Cart and session data is per visitor. A full-page cache that serves one stored HTML copy to everyone breaks that.

Never cache these

  • Cart, Checkout, My Account pages.
  • Any request carrying cookies woocommerce_cart_hash, woocommerce_items_in_cart, wp_woocommerce_session_*.
  • Paths with ?wc-ajax= and add-to-cart query strings.

WooCommerce sends DONOTCACHEPAGE for those pages and most caching plugins respect it, but confirm in the plugin's exclusion list. For server-level caches (Nginx fastcgi_cache, Varnish, Cloudflare page rules), add the rules yourself:

set $skip_cache 0;
if ($request_uri ~* "/(cart|checkout|my-account)/") { set $skip_cache 1; }
if ($http_cookie ~* "woocommerce_items_in_cart|wp_woocommerce_session|wordpress_logged_in") { set $skip_cache 1; }
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;

Mini-cart fragments: WooCommerce refreshes the cart count with an AJAX fragments request, so the rest of the page can stay cached. Do not disable cart fragments unless your theme updates the count another way.

Object cache (Redis or Memcached) is safe and helps a lot: it caches database results, not whole pages.

Pitfalls

  • Cloudflare "Cache Everything" overrides origin headers; bypass on those paths and on cookies.
  • Logged-in users should bypass the page cache.
  • After changes, purge all caches and test with two different browsers.
0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.