preloader

WP Rocket and WooCommerce: Fixing Cart, Checkout, and Price Display Issues

Caching and WooCommerce have a fundamental tension: caching serves the same HTML to every visitor, but WooCommerce needs to show personalised content – a cart with items, a checkout form with the right fields, prices after discount codes apply. WP Rocket handles most of this correctly when configured properly, but the default settings break a handful of WooCommerce behaviours that cost real sales. This article covers every common problem and its specific fix.

Why WP Rocket Breaks WooCommerce (The Short Version)

WP Rocket caches full HTML pages. When a visitor loads your product page, WP Rocket serves a stored HTML file rather than running PHP and querying the database. This is fast, but it means that the cached HTML does not know about this visitor’s cart, their location-based pricing, or whether they are logged in as a wholesale customer with special prices.

WooCommerce uses AJAX-loaded “cart fragments” to update dynamic elements after the page loads – the cart icon count, the cart total in the header, the “add to cart” button state. These fragments load via a separate AJAX request to wc-ajax=get_refreshed_fragments. WP Rocket does not cache AJAX requests by default, so fragments should work. But several specific configurations break this mechanism, and the symptoms are confusing because the page itself looks fine.

Problem 1: Cart Count Does Not Update After Adding a Product

A customer adds a product and the cart icon in the header stays at zero, or shows an old number. This is almost always the cart fragment AJAX request being blocked or cached. Diagnose in browser DevTools: open the Network tab, add a product to the cart, and look for a request to /?wc-ajax=get_refreshed_fragments. If it returns a 200 with JSON data, fragments are working but the theme is not processing them. If it returns a cached HTML page instead of JSON, something is caching the AJAX endpoint.

The fix for cached AJAX fragments: in WP Rocket settings, go to Advanced Rules and verify that wc-ajax is not listed in the “Cache query strings” field. Also check whether any CDN or server-level cache (Cloudflare, LiteSpeed, Nginx FastCGI) is caching POST requests or query strings – these need to be excluded at the server level separately from WP Rocket.

If fragments are returning correctly but the cart count still does not update, the problem is in your theme’s JavaScript. The theme needs to listen for the wc_fragment_refresh jQuery event and update cart count elements. Check your theme documentation for WooCommerce compatibility.

Problem 2: Checkout Page Is Cached and Shows Wrong Data

The checkout page should never be cached – it contains personalised order summary, shipping calculator, and payment fields that must be generated fresh for each visitor. WP Rocket automatically excludes the WooCommerce cart, checkout, and My Account pages from caching when the WooCommerce integration is enabled, but this automatic exclusion sometimes fails if your checkout page URL is non-standard.

Verify the exclusion is working: log out of WordPress, visit your checkout page, then check WP Rocket’s cache folder (wp-content/cache/wp-rocket/) for a cached file matching your checkout URL. If a file exists, the exclusion failed. Fix it manually: go to WP Rocket -> Settings -> Advanced Rules -> Never Cache URLs and add your checkout page URL explicitly, including any trailing slash variation.

Also add to the never-cache list: /cart/, /my-account/, and any custom WooCommerce endpoint URLs you have configured under WooCommerce -> Settings -> Advanced.

Still stuck after trying these steps? Describe the exact issue and get a free estimate from a developer who has seen this before.

Problem 3: Prices Look Wrong for Logged-In Users or Wholesale Customers

If you use a plugin that changes prices based on user role (wholesale pricing, member discounts, B2B pricing), those role-specific prices come from PHP logic that runs at page generation time. A cached page stores whatever price was calculated when the page was first cached – usually for a guest visitor at full retail price. A logged-in wholesale customer then sees the wrong price from cache.

The solution is user-role-based cache separation. WP Rocket does not have built-in role-based caching, but you can implement it using the cache-based on cookies mechanism. Most pricing plugins set a cookie when a wholesale customer logs in. Add that cookie name to WP Rocket -> Settings -> Advanced Rules -> Cache Lifespan -> Cache for logged-in users, or more precisely, configure separate cache buckets per role:

// Add to functions.php - tell WP Rocket to cache separately per user role
add_filter('rocket_cache_dynamic_cookies', function($cookies) {
    $cookies[] = 'wp_woocommerce_session_'; // WooCommerce session cookie
    $cookies[] = 'your_wholesale_plugin_cookie'; // Replace with actual cookie name
    return $cookies;
});

Alternatively, disable page caching entirely for logged-in users in WP Rocket -> Settings -> Cache -> Separate cache files for logged-in users. This is simpler but means logged-in users get no page cache benefit.

Problem 4: Minified JavaScript Breaks Add to Cart

WP Rocket minifies and combines JavaScript files to reduce page load time. Occasionally this breaks WooCommerce’s add-to-cart JavaScript, particularly on variable products or when a theme uses custom add-to-cart logic. The symptom is an add-to-cart button that does nothing, or a JavaScript error in the console when attempting to add a product.

Diagnose by temporarily disabling JavaScript optimisation in WP Rocket -> Settings -> File Optimization. If add-to-cart works after disabling, the problem is in the minification. To fix without disabling entirely: go to WP Rocket -> Settings -> File Optimization -> Excluded JavaScript Files and exclude the specific WooCommerce scripts causing the conflict. Common candidates to exclude: woocommerce.min.js, add-to-cart.min.js, and any theme-specific add-to-cart scripts.

Problem 5: Mobile and Desktop Showing Each Other’s Cached Pages

WooCommerce themes sometimes serve different layouts to mobile and desktop users, controlled by PHP logic rather than CSS media queries. If WP Rocket caches a desktop version and serves it to mobile visitors, the layout breaks. Enable “Separate cache files for mobile devices” in WP Rocket -> Settings -> Cache. This creates distinct cache files for mobile and desktop, preventing cross-device cache serving.

Keep Reading

Previous Post Simply Schedule Appointments vs FluentBooking: Which Is Better for Coaches and Consultants Next Post Elementor Editor Not Loading: How to Diagnose and Fix a White Screen or Blank Editor

Need Help With Your WordPress Site?

If you need help with WordPress fixes, plugin issues, theme customization, or development work, feel free to get in touch.

Get a Free Estimate