From 33e046a4d0c3e28a61712b7bf999ce7b76711fa8 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 19 Jan 2015 13:19:41 +0000 Subject: [PATCH] Use WC_Cache_Helper to expire shipping cache on setting save, and transient clear Closes #7151 --- includes/admin/class-wc-admin-status.php | 1 + includes/admin/settings/class-wc-settings-shipping.php | 5 +++-- includes/class-wc-shipping.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/admin/class-wc-admin-status.php b/includes/admin/class-wc-admin-status.php index 58e212f913e..b8d916616ab 100644 --- a/includes/admin/class-wc-admin-status.php +++ b/includes/admin/class-wc-admin-status.php @@ -47,6 +47,7 @@ class WC_Admin_Status { case 'clear_transients' : wc_delete_product_transients(); wc_delete_shop_order_transients(); + WC_Cache_Helper::get_transient_version( 'shipping', true ); echo '

' . __( 'Product Transients Cleared', 'woocommerce' ) . '

'; break; diff --git a/includes/admin/settings/class-wc-settings-shipping.php b/includes/admin/settings/class-wc-settings-shipping.php index ad41e5ef669..f48eb611f67 100644 --- a/includes/admin/settings/class-wc-settings-shipping.php +++ b/includes/admin/settings/class-wc-settings-shipping.php @@ -260,7 +260,7 @@ class WC_Settings_Shipping extends WC_Settings_Page { * Save settings */ public function save() { - global $current_section, $wpdb; + global $current_section; if ( ! $current_section ) { @@ -276,7 +276,8 @@ class WC_Settings_Shipping extends WC_Settings_Page { do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section_class->id ); } - $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_ship_%') OR `option_name` LIKE ('_transient_timeout_wc_ship_%')" ); + // Increments the transient version to invalidate cache + WC_Cache_Helper::get_transient_version( 'shipping', true ); } } diff --git a/includes/class-wc-shipping.php b/includes/class-wc-shipping.php index 4c0edc0ef8d..46abeab96e6 100644 --- a/includes/class-wc-shipping.php +++ b/includes/class-wc-shipping.php @@ -339,7 +339,7 @@ class WC_Shipping { if ( ! $package ) return false; // Check if we need to recalculate shipping for this package - $package_hash = 'wc_ship_' . md5( json_encode( $package ) ); + $package_hash = 'wc_ship_' . md5( json_encode( $package ) . WC_Cache_Helper::get_transient_version( 'shipping' ) ); $status_options = get_option( 'woocommerce_status_options', array() ); if ( false === ( $stored_rates = get_transient( $package_hash ) ) || ( ! empty( $status_options['shipping_debug_mode'] ) && current_user_can( 'manage_options' ) ) ) {