Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active May 23, 2020 11:31
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 wpmudev-sls/a02d398fdfcc6208f7bf9def1724d2db to your computer and use it in GitHub Desktop.
Save wpmudev-sls/a02d398fdfcc6208f7bf9def1724d2db to your computer and use it in GitHub Desktop.
WooCommerce - Object cache compatibility
<?php
/**
* Plugin Name: WooCommerce - Object cache compatibility
* Plugin URI: https://premium.wpmudev.org/
* Description: Purge object cache when a woocommerce product variation is saved
* Author: Alessandro Kaounas @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* Task: 0/1135022585412927/1176162755229155
* License: GPLv2 or later
*/
$wc_ajax_events = array(
// Attributes
'add_attribute',
'add_new_attribute',
'save_attributes',
// Variations
'add_variation',
'remove_variation',
'remove_variations',
'link_all_variations',
'load_variations',
'save_variations',
'bulk_edit_variations',
);
foreach( $wc_ajax_events as $action ){
add_action( 'wp_ajax_woocommerce_' . $action, function() use( $action ) {
add_action( 'shutdown', function() use( $action ){
wp_cache_flush();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment