Set up Falcon cache with WooCommerce

From Wordfence Documentation
Jump to: navigation, search
Support for the Falcon and Basic cache has been removed in version 6.2.8. If you previously used Falcon or Basic caching, we recommend choosing another caching plugin that works for your site, alongside Wordfence for security -- most caching plugins work well with Wordfence. If enabled, caching will be disabled automatically in version 6.2.8.

Since Falcon cache was open source, another developer has "forked" the code, essentially making a separate plugin with nearly the same functionality. While this plugin is not affiliated with Wordfence, Vendi cache is based on Falcon's original code and may work well if your site previously used Falcon: https://wordpress.org/plugins/vendi-cache/

More details on discontinuing the caching feature in Wordfence are available on our blog:
https://www.wordfence.com/blog/2016/10/removing-falcon-cache-wordfence-heres-need-know/.


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 WooThemes.com 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>

Becomes:

<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.