Skip to content

Instantly share code, notes, and snippets.

@daigo75
Last active April 18, 2017 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daigo75/647dfb971c3bac3375b1 to your computer and use it in GitHub Desktop.
Save daigo75/647dfb971c3bac3375b1 to your computer and use it in GitHub Desktop.
WooCommerce 2.4 – Price cache workaround - Disable cache
// This code is no longer required as of WooCommerce 2.5
/**
* Disables the product price cache. This function looks for the cache key
* that is about to be retrieved by WooCommerce, and deletes the cached data
* associated to it.
*
* IMPORTANT
* This function can have an impact on WooCommerce's performance, and it
* should not be used unless necessary.
*
* @param array cache_key_args The arguments that form the cache key.
* @param WC_Product product The product for which the key is being generated.
* @param bool display Indicates if the prices are being retrieved for display
* purposes.
* @return array
* @since WooCommerce 2.4
* @author Aelia <support@aelia.co>
* @link http://aelia.co/2015/08/11/wc-2-4-workaround-for-price-cache
*/
function disable_variation_prices_cache($cache_key_args, $product, $display) {
// Delete the cached data, if it exists
$cache_key = 'wc_var_prices' . md5(json_encode($cache_key_args));
delete_transient($cache_key);
return $cache_key_args;
}
add_filter('woocommerce_get_variation_prices_hash', 'disable_variation_prices_cache', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment