- 28 March, 2023
- by admin
- 0 Comments
How to configure cache plugins with WooCommerce
What Is Caching?
Put simply caching is when a website is “saved,” allowing the end-user to load the site faster than if all aspects of the website had to be loaded each time.
A cached website’s assets are already loaded and thus can be served quicker than if a website has to load and “build” the page each time it’s requested.
How Does Caching Affect WooCommerce?
Caching plugins like WP Rocket doesn’t cache logged-in users by default, but what happens when you do cache logged in users, and your site isn’t set up in the necessary way?
Have you run into any of these?
- Customers seeing other customers’ account details?
- Customers having mystery items in their shopping cart that they swear they didn’t add?
- Customers complaining about seeing someone else’s address at checkout?
Then you have caching with WooCommerce set up incorrectly! Don’t worry, we’ll get into how to fix it in a moment.
But it’s essential to know the pitfalls of this.
- Customers losing trust.
- Potential data protection issues
As a store owner, it is your responsibility to ensure that your store is secure and follows all legal compliances.
Why Do I Need to Configure Caching for WooCommerce Explicitly?
When you cache content on your website, it’s no longer dynamic, the content is saved and then served to your visitors in precisely the same manner each and every-time. This means if you cache your checkout page, it’s never going to show the customer their correct shopping cart.
WooCommerce is dynamic, and you need to ensure that dynamic pages are excluded from the cache.
How to Setup WooCommerce Caching?
If you’re using one of the popular caching plugins like W3 Total Cache, WP Super Cache or WP Fastest Cache you need to do the following:
Step1: Excluding pages from the cache
Oftentimes if using caching plugins they’ll already exclude these pages. Otherwise make sure you exclude the following pages from the cache through your caching systems respective settings.
- Cart
- My Account
- Checkout
These pages need to stay dynamic since they display information specific to the current customer and their cart
Step 2: Excluding WooCommerce session from the cache
If the caching system you’re using offers database caching, it might be helpful to exclude _wc_session_
from being cached. This will be dependent on the plugin or host caching so refer to the specific instructions or docs for that system.
Step 3: Excluding WooCommerce cookies from the cache
Cookies in WooCommerce help track the products in your customers cart, can keep their cart in the database if they leave the site, and powers the recently viewed widget. Below is a list of the cookies WooCommerce uses for this, which you can exclude from caching.
COOKIE NAME | DURATION | PURPOSE |
---|---|---|
woocommerce_cart_hash |
session | Helps WooCommerce determine when cart contents/data changes. |
woocommerce_items_in_cart |
session | Helps WooCommerce determine when cart contents/data changes. |
wp_woocommerce_session_ |
2 days | Contains a unique code for each customer so that it knows where to find the cart data in the database for each customer. |
woocommerce_recently_viewed |
session | Powers the Recent Viewed Products widget. |
store_notice[notice id] |
session | Allows customers to dismiss the Store Notice. |
W3 Total Cache Minify Settings
Ensure you add ‘mfunc’ to the ‘Ignored comment stems’ option in the Minify settings.
WP-Rocket
WooCommerce is fully compatible with WP-Rocket. Please ensure that the following pages (Cart, Checkout, My Account) are not to be cached in the plugin’s settings.
WP Super Cache
WooCommerce is compatible with WP Super Cache. Please ensure that the following pages (Cart, Checkout, My Account) are not to be cached by placing the corresponding endpoints here WP Admin > Settings > WP Super Cache > Advanced.
Varnish
if (req.url ~ "^/(cart|my-account|checkout|addons)") { return (pass); } if ( req.url ~ "\?add-to-cart=" ) { return (pass); }
Why is my Varnish configuration not working in WooCommerce?
Check out the following WordPress.org Support forum post on how cookies may be affecting your varnish coding.
Add this to vcl_recv above "if (req.http.cookie) {": # Unset Cookies except for WordPress admin and WooCommerce pages if (!(req.url ~ "(wp-login|wp-admin|cart|my-account/*|wc-api*|checkout|addons|logout|lost-password|product/*)")) { unset req.http.cookie; } # Pass through the WooCommerce dynamic pages if (req.url ~ "^/(cart|my-account/*|checkout|wc-api/*|addons|logout|lost-password|product/*)") { return (pass); } # Pass through the WooCommerce add to cart if (req.url ~ "\?add-to-cart=" ) { return (pass); } # Pass through the WooCommerce API if (req.url ~ "\?wc-api=" ) { return (pass); } # Block access to php admin pages via website if (req.url ~ "^/phpmyadmin/.*$" || req.url ~ "^/phppgadmin/.*$" || req.url ~ "^/server-status.*$") { error 403 "For security reasons, this URL is only accesible using localhost (127.0.0.1) as the hostname"; } # Add this to vcl_fetch: # Unset Cookies except for WordPress admin and WooCommerce pages if ( (!(req.url ~ "(wp-(login|admin)|login|cart|my-account/*|wc-api*|checkout|addons|logout|lost-password|product/*)")) || (req.request == "GET") ) { unset beresp.http.set-cookie; } #
Why is my Password Reset stuck in a loop?
This is due to the My Account page being cached, Some hosts with server-side caching don’t prevent my-account.php
from being cached.
If you’re unable to reset your password and keep being returned to the login screen, please speak to your host to make sure this page is being excluded from their caching.
Recent Posts
5 Expert Tips To Improve Your Workflow With Elementor
1 April, 2023How to Add Variable Product in WooCommerce
29 March, 2023Featured products
-
Beauty Care – The Elementor Cosmetic & Spa WordPress theme
$69.00Original price was: $69.00.$49.00Current price is: $49.00. -
-
Fruits Store - The Elementor Fruits WordPress theme
$69.00Original price was: $69.00.$49.00Current price is: $49.00. -
-
Coffee House - The elementor coffee WordPress Theme
$69.00Original price was: $69.00.$49.00Current price is: $49.00. -
-
GoodTaste - The elementor restaurant WordPress theme
$49.00
-