Use WC_Cache_Helper to expire shipping cache on setting save, and transient clear

Closes #7151
This commit is contained in:
Mike Jolley 2015-01-19 13:19:41 +00:00
parent 354a0ff0a3
commit 33e046a4d0
3 changed files with 5 additions and 3 deletions

View File

@ -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 '<div class="updated"><p>' . __( 'Product Transients Cleared', 'woocommerce' ) . '</p></div>';
break;

View File

@ -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 );
}
}

View File

@ -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' ) ) ) {