Use fixed transient naming in wc_get_shipping_method_count

This commit is contained in:
Mike Jolley 2019-01-21 12:05:58 +00:00
parent 5280ceb8d9
commit 0cf82b8937
1 changed files with 26 additions and 18 deletions

View File

@ -1451,27 +1451,35 @@ function wc_postcode_location_matcher( $postcode, $objects, $object_id_key, $obj
function wc_get_shipping_method_count( $include_legacy = false ) {
global $wpdb;
$transient_name = 'wc_shipping_method_count_' . ( $include_legacy ? 1 : 0 ) . '_' . WC_Cache_Helper::get_transient_version( 'shipping' );
$method_count = get_transient( $transient_name );
$transient_name = $include_legacy ? 'wc_shipping_method_count_legacy' : 'wc_shipping_method_count';
$transient_version = WC_Cache_Helper::get_transient_version( 'shipping' );
$transient_value = get_transient( $transient_name );
if ( false === $method_count ) {
$method_count = absint( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_shipping_zone_methods" ) );
if ( $include_legacy ) {
// Count activated methods that don't support shipping zones.
$methods = WC()->shipping()->get_shipping_methods();
foreach ( $methods as $method ) {
if ( isset( $method->enabled ) && 'yes' === $method->enabled && ! $method->supports( 'shipping-zones' ) ) {
$method_count++;
}
}
}
set_transient( $transient_name, $method_count, DAY_IN_SECONDS * 30 );
if ( isset( $transient_value['value'], $transient_value['version'] ) && $transient_value['version'] === $transient_version ) {
return absint( $transient_value['value'] );
}
return absint( $method_count );
$method_count = absint( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_shipping_zone_methods" ) );
if ( $include_legacy ) {
// Count activated methods that don't support shipping zones.
$methods = WC()->shipping()->get_shipping_methods();
foreach ( $methods as $method ) {
if ( isset( $method->enabled ) && 'yes' === $method->enabled && ! $method->supports( 'shipping-zones' ) ) {
$method_count++;
}
}
}
$transient_value = array(
'version' => $transient_version,
'value' => $method_count,
);
set_transient( $transient_name, $transient_value, DAY_IN_SECONDS * 30 );
return $method_count;
}
/**