Merge pull request #9336 from woothemes/issue/9268-get-coupon-id-from-code-caching

Cache coupon id from code lookup in a transient.
This commit is contained in:
Mike Jolley 2015-10-22 09:19:37 -06:00
commit 63947376db
1 changed files with 9 additions and 1 deletions

View File

@ -145,7 +145,15 @@ class WC_Coupon {
private function get_coupon_id_from_code( $code ) {
global $wpdb;
return absint( $wpdb->get_var( $wpdb->prepare( apply_filters( 'woocommerce_coupon_code_query', "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish'" ), $this->code ) ) );
$coupon_code_query = $wpdb->prepare( apply_filters( 'woocommerce_coupon_code_query', "SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish'" ), $this->code );
$transient_name = 'wc_cid_by_code_' . md5( $coupon_code_query . WC_Cache_Helper::get_transient_version( 'coupons' ) );
if ( false === ( $result = get_transient( $transient_name ) ) ) {
$result = $wpdb->get_var( $coupon_code_query );
set_transient( $transient_name, $result, DAY_IN_SECONDS * 30 );
}
return absint( $result );
}
/**