Tweaking BatCache to play nicely with Woocommerce

Are you caching your WordPress sites with MemCache object cache and BatCache advanced cache? Well you should be.
Here’s a tweak to stop the advanced cache caching dynamic WooCommerce pages like the cart and checkout.

Edit advanced-cache.php, find the comment

// Never batcache interactive scripts or API endpoints.

and add the following snippet of code

// never cache woocommerce
$wc_page_uris = array(
	'/cart', //your cart uri
	'/checkout', //your checkout uri
	'/my-account', //your page for your users
);
 
foreach( $wc_page_uris as $wc_uri )
	if( strstr( $_SERVER['REQUEST_URI'], $wc_uri ) )
	return;

Author: Kieran Barnes

Kieran is a PHP developer with 15 years commercial experience. Specialist in WordPress, CakePHP, CubeCart and all things PHP.

1 thought on “Tweaking BatCache to play nicely with Woocommerce”

  1. Hi Kieran,

    What would you do in instances where you need to show a live cart on all pages. Even something such as the numbers of items in your cart, or the total value of the cart.

    Can you exclude fragments from being cached?

    Cheers.

Leave a Reply

Your email address will not be published. Required fields are marked *