Merge pull request #4488 from GeertDD/cached_tax_rates

Cached tax rates
This commit is contained in:
Mike Jolley 2014-01-13 03:19:52 -08:00
commit 2e0291eff1
1 changed files with 77 additions and 66 deletions

View File

@ -237,6 +237,12 @@ class WC_Tax {
$valid_postcodes[] = $wildcard_postcode . '*'; $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 // Run the query
$found_rates = $wpdb->get_results( $wpdb->prepare( " $found_rates = $wpdb->get_results( $wpdb->prepare( "
SELECT * FROM ( SELECT * FROM (
@ -309,7 +315,12 @@ class WC_Tax {
'compound' => $found_rate->tax_rate_compound ? 'yes' : 'no' '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;
} }
/** /**