This documentation is only valid for older versions of Wordfence. If you are using Wordfence 7 or later, please visit our new documentation.

Set up Falcon cache with WooCommerce

From Wordfence Documentation
Revision as of 23:04, 23 September 2015 by WFMattr (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

WooCommerce is Officially Supported

WooCommerce is officially supported by Wordfence. You can use Wordfence with Falcon Engine caching enabled alongside WooCommerce without any modifications.

WooCommerce already adds information to pages that must not be cached and passes this on to Wordfence. So for example, we won't cache the page where a customer views their shopping cart.

If you are a developer, you can find the code where WooCommerce tells us what we should not cache in the includes/class-wc-cache-helper.php file in the WooCommerce source code. There WooCommerce sets the DONOTCACHEPAGE constant. You can find the place we check for this constant in the lib/wfCache.php file in the Wordfence source code.

If You Display a WooCommerce Cart on Every Page

Note that if you're using WooCommerce and you are allowing visitors to see the contents of their shopping cart on every page, then you need to make a small change. You can use the technique we will show you below for any theme or plugin where you don't want Wordfence to cache the content you're generating.

This page on documentation, for example, contains some PHP code that lets you show your visitors the contents of their WooCommerce shopping cart on each page. You need to modify the PHP code to include the wordfence::doNotCache() function which tells Wordfence to not cache any pages that contain this dynamically generated content.

So in this case:

<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>"
title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php
echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'),
$woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>


<a class="cart-contents" href="<?php wordfence::doNotCache(); echo $woocommerce->cart->get_cart_url(); ?>"
title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php
echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'),
$woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>

Notice that we added the wordfence::doNotCache(); function which makes sure that Wordfence does not cache this content.

You can use this technique for any theme or plugin where you don't want a piece of content you're generating to be cached.