Configuration Guide for WooCommerce Cache Plugin

After using theWooCommercein the website, using theCaching PluginCan effectively improvePage loading speedImprovementuser experience. However, since pages such as shopping carts, user accounts, etc. involve dynamic data about the user, these pages should usually not be cached or they may result in incorrect information being displayed. In this article, we will detail how to use the caching plugin whenProperly Configure WooCommerce Cache SettingsThis ensures the accuracy of the page data and a smooth shopping experience.

图片[1]-WooCommerce缓存插件的配置指南-光子波动网 | 专业WordPress修复服务,全球范围,快速响应

I. Troubleshooting WooCommerce Page Cache

Typically, if the caching plugin used is already compatible with WooCommerce, it will exclude the following pages from the cache by default:

  • shopping cart page: Display the current customer's shopping information, which needs to be kept dynamically updated.
  • My Account Page: Displays the user's account information and order history, which needs to be dynamically displayed based on the logged-in user.
  • checkout page: Involves a checkout process that contains the user's payment and delivery information, and needs to ensure that the information is real-time.

Make sure that in the settings of the caching plugin, these pages will bemanual exclusion(math.) genusPreventing them from being cached and causing data inaccuracies. Each cache plugin has a different setup interface, just refer to the plugin's documentation for details.

II. Troubleshooting WooCommerce Session Data Caching

In some caching systems, database caching may be provided. If the plugin or server cache allows database caching, it is recommended that the_wc_session_Exclude from cache. This is because WooCommerce manages the cart and user state via Session data, and caching this data may cause the cart information to be out of sync.

图片[2]-WooCommerce缓存插件的配置指南-光子波动网 | 专业WordPress修复服务,全球范围,快速响应

III. Excluding WooCommerce Cookies Cache

WooCommerce uses cookies to track a user's cart status and recently viewed items. Below are the main cookies used in WooCommerce, it is recommended to exclude these cookies in your cache settings to ensure a consistent shopping experience:

Cookie Namevalidity periodcorresponds English -ity, -ism, -ization
woocommerce_cart_hashsessionUsed to determine if the cart contents are updated
woocommerce_items_in_cartsessionUsed to determine if the cart contents are updated
wp_woocommerce_session_2 daysContains a unique code that identifies where each user's shopping cart data is stored
woocommerce_recently_viewedsessionFor managing the "Recently Viewed Items" widget.
store_notice[notice id]sessionAllow users to turn off store announcements

IV. WooCommerce Compatibility Settings for Common Caching Plugins

1. W3 Total Cache

图片[3]-WooCommerce缓存插件的配置指南-光子波动网 | 专业WordPress修复服务,全球范围,快速响应

In the W3 Total Cache setup, make sure that the "Minimize settings"Under."Ignored comment prefixes"Add "mfunc" to avoid affecting WooCommerce's dynamic content during the minimization process.

2. WP-Rocket

图片[4]-WooCommerce缓存插件的配置指南-光子波动网 | 专业WordPress修复服务,全球范围,快速响应

WooCommerce is fully compatible with WP-Rocket, in the settings make sure "cart","pay the bill"and"My Account page is not cached. It is also recommended to avoid minimizing JavaScript files to prevent causing page loading problems.

3. WP Super Cache

图片[5]-WooCommerce缓存插件的配置指南-光子波动网 | 专业WordPress修复服务,全球范围,快速响应

WooCommerce has natural compatibility with WP Super Cache.WooCommerce automatically sends messages to WP Super Cache and does not cache them by default"cart","pay the bill"and"My Account"Page.

4. Varnish

图片[6]-WooCommerce缓存插件的配置指南-光子波动网 | 专业WordPress修复服务,全球范围,快速响应

If using Varnish caching, it is recommended to add the following code to exclude dynamic pages from caching:

if (req.url ~ "^/(cart|my-account|checkout|addons)") {
  return (pass);
}
if (req.url ~ "\\?add-to-cart=") {
  return (pass); }
}

For WooCommerce API and dynamic page access requests, you can also add the following settings:

		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 accessible 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-cookies;
} 

V. Common Problems and Troubleshooting

1. Varnish Configuration Doesn't Work in WooCommerce

  • If the Varnish cache is not working correctly, check again and make sure that the configuration related to Session and Cookies for the pages that need to be excluded and WooCommerce has been done. You can also check the WordPress.org support forum for Cookies related code settings.

2. Password Reset Page Loop

  • When the "My Account" page is cached, it may cause the password reset operation to be stuck at the login screen. Please contact your server provider to make sure the page is not cached on the server side.

With the above configuration, you can effectively improve the performance of your WooCommerce site while ensuring that dynamic pages such as the shopping cart, checkout, etc. are not cached to cause data display errors. If you have any specific questions, we recommend that you follow the caching plugin documentation or contact the relevant technical support team.


Contact Us
Can't read the article? Contact us for free answers! Free help for personal, small business sites!
Tel: 020-2206-9892
QQ咨询:1025174874
(iii) E-mail: info@361sale.com
Working hours: Monday to Friday, 9:30-18:30, holidays off
© Reprint statement
This article was written by Harry
THE END
If you like it, support it.
kudos9 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments