From aea9f5f55ee47741a322c764938387ab117ba9bf Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 20 Mar 2012 18:36:25 +0000 Subject: [PATCH] fix coupon check --- classes/class-wc-cart.php | 5 ++++- classes/class-wc-coupon.php | 2 +- readme.txt | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/classes/class-wc-cart.php b/classes/class-wc-cart.php index b16e8f61112..8ca1c8bcbe4 100644 --- a/classes/class-wc-cart.php +++ b/classes/class-wc-cart.php @@ -246,13 +246,16 @@ class WC_Cart { $coupon = new WC_Coupon( $code ); if ( is_array( $coupon->customer_email ) && sizeof( $coupon->customer_email ) > 0 ) { + if ( is_user_logged_in() ) { $current_user = wp_get_current_user(); $check_emails[] = $current_user->user_email; } $check_emails[] = $posted['billing_email']; - if ( ! in_array($check_emails, $coupon->customer_email) ) { + $check_emails = array_map( 'strtolower', $check_emails ); + + if ( sizeof( array_intersect( $check_emails, $coupon->customer_email ) ) == 0 ) { $woocommerce->add_error( sprintf( __('Sorry, it seems the coupon "%s" is not yours - it has now been removed from your order.', 'woocommerce'), $code ) ); // Remove the coupon unset( $this->applied_coupons[$key] ); diff --git a/classes/class-wc-coupon.php b/classes/class-wc-coupon.php index 3913b7bc1a6..e81e68bc287 100644 --- a/classes/class-wc-coupon.php +++ b/classes/class-wc-coupon.php @@ -95,7 +95,7 @@ class WC_Coupon { $this->expiry_date = ($this->expiry_date) ? strtotime($this->expiry_date) : ''; $this->product_categories = array_filter(array_map('trim', (array) maybe_unserialize($this->product_categories))); $this->exclude_product_categories = array_filter(array_map('trim', (array) maybe_unserialize($this->exclude_product_categories))); - $this->customer_email = array_filter(array_map('trim', (array) maybe_unserialize($this->customer_email))); + $this->customer_email = array_filter(array_map('trim', array_map('strtolower', (array) maybe_unserialize($this->customer_email)))); return true; endif; diff --git a/readme.txt b/readme.txt index efc89f37c0e..b444464f126 100644 --- a/readme.txt +++ b/readme.txt @@ -149,6 +149,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc * Tweak - Order items table (for emails) moved to template file * Tweak - Queries on report pages to replace get_posts to resolve issues on stores with a shed load of orders * Tweak - Remove case sensitively from order tracking and force email lowercase on checkout +* Fix - User email check for coupons * Fix - Put chosen frontend script back * Fix - Make download links use billing email, not user email * Fix - ' in prices (thousand separator)