Fix issues with NGINX configuration and WooCommerce cookies

Note: Since WP Rocket 2.8.11, if you're using our NGINX configuration, you don't have to do anything.

As you may know, some cart widgets use AJAX and will work fine with caching, but not the ones using PHP.
As we suggest here, if you have a PHP driven cart widget, you should exclude the page from the cache based on the presence of WooCommerce cookies, woocommerce_items_in_cart and woocommerce_cart_hash: you simply have to add those 2 cookies to the exclusion box: Don't cache pages that use the following cookies

This will update the .htaccess file to take those cookies into consideration.

But if your website is running on NGINX and you're also using WooCommerce with a PHP-driven cart widget, you may find it hard to exclude pages from cache and synchronise the number of items in your cart. In fact, the problem which prevents your cart from rendering correctly is the combination of NGINX configuration + WooCommerce cookies.

NGINX configuration

When you have NGINX configuration and the WP Rocket cache is served by NGINX, things can get a bit tricky because there's no .htaccess, so no files to update.

Since the rocket-nginx.conf file can’t be updated automatically, the exclusion of the cache based on the cookies has to be done manually.

You have 2 solutions:

Enter your NGINX configuration for WP Rocket and go to line 85:

Add the 2 WooCommerce cookies in this way:
if ($http_cookie ~* "(wordpress_logged_in_|wp\-postpass_|woocommerce_items_in_cart|woocommerce_cart_hash)")
Enter your NGINX configuration for WP Rocket and go to line 23 :

and set $rocket_bypass to 0 instead of 1.

Whether you choose option A or B, remember to restart NGINX after editing the configuration!

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.