Merge pull request #4488 from GeertDD/cached_tax_rates
Cached tax rates
This commit is contained in:
commit
2e0291eff1
|
@ -237,6 +237,12 @@ class WC_Tax {
|
|||
$valid_postcodes[] = $wildcard_postcode . '*';
|
||||
}
|
||||
|
||||
// Build transient key and try to retrieve them from cache
|
||||
$rates_transient_key = 'wc_tax_rates_' . md5( sprintf( '%s+%s+%s+%s+%s', $country, $state, $city, implode( ',', $valid_postcodes), $tax_class ) );
|
||||
$matched_tax_rates = get_transient( $rates_transient_key );
|
||||
|
||||
if ( false === $matched_tax_rates ) {
|
||||
|
||||
// Run the query
|
||||
$found_rates = $wpdb->get_results( $wpdb->prepare( "
|
||||
SELECT * FROM (
|
||||
|
@ -309,7 +315,12 @@ class WC_Tax {
|
|||
'compound' => $found_rate->tax_rate_compound ? 'yes' : 'no'
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_matched_tax_rates', $matched_tax_rates, $country, $state, $postcode, $city, $tax_class );
|
||||
$matched_tax_rates = apply_filters( 'woocommerce_matched_tax_rates', $matched_tax_rates, $country, $state, $postcode, $city, $tax_class );
|
||||
|
||||
set_transient( $rates_transient_key, $matched_tax_rates, DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $matched_tax_rates;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue