Have all WC_Coupon calls use is_valid() method to check #1994

This commit is contained in:
Coen Jacobs 2012-12-19 15:52:16 +01:00
parent 3d2c18db6b
commit 314af74f3d
2 changed files with 9 additions and 7 deletions

View File

@ -398,7 +398,7 @@ class WC_Cart {
foreach ( $this->applied_coupons as $key => $code ) {
$coupon = new WC_Coupon( $code );
if ( is_array( $coupon->customer_email ) && sizeof( $coupon->customer_email ) > 0 ) {
if ( ! is_wp_error( $coupon->is_valid() ) && is_array( $coupon->customer_email ) && sizeof( $coupon->customer_email ) > 0 ) {
$coupon->customer_email = array_map( 'sanitize_email', $coupon->customer_email );
@ -1104,9 +1104,11 @@ class WC_Cart {
do_action( 'woocommerce_product_discount_after_tax_' . $coupon->type, $coupon, $values, $price );
if ( ! $coupon->is_valid() ) continue;
if ( $coupon->type != 'fixed_product' && $coupon->type != 'percent_product' ) continue;
if ( !$coupon->apply_before_tax() && $coupon->is_valid() ) {
if ( ! $coupon->apply_before_tax() ) {
$product_cats = wp_get_post_terms( $values['product_id'], 'product_cat', array("fields" => "ids") );
@ -1181,7 +1183,7 @@ class WC_Cart {
do_action( 'woocommerce_cart_discount_after_tax_' . $coupon->type, $coupon );
if ( !$coupon->apply_before_tax() && $coupon->is_valid() ) {
if ( ! $coupon->apply_before_tax() && $coupon->is_valid() ) {
switch ( $coupon->type ) {
@ -1745,7 +1747,7 @@ class WC_Cart {
foreach ( $this->applied_coupons as $code ) {
$coupon = new WC_Coupon($code);
if ( $coupon->individual_use == 'yes' ) {
if ( $coupon->is_valid() && $coupon->individual_use == 'yes' ) {
$this->applied_coupons = array();
}
}
@ -1793,7 +1795,7 @@ class WC_Cart {
if ( $this->applied_coupons ) {
foreach ( $this->applied_coupons as $index => $code ) {
$coupon = new WC_Coupon( $code );
if ( $coupon->apply_before_tax() ) unset( $this->applied_coupons[ $index ] );
if ( $coupon->is_valid() && $coupon->apply_before_tax() ) unset( $this->applied_coupons[ $index ] );
}
}
@ -1802,7 +1804,7 @@ class WC_Cart {
if ( $this->applied_coupons ) {
foreach ( $this->applied_coupons as $index => $code ) {
$coupon = new WC_Coupon( $code );
if ( ! $coupon->apply_before_tax() ) unset( $this->applied_coupons[ $index ] );
if ( $coupon->is_valid() && ! $coupon->apply_before_tax() ) unset( $this->applied_coupons[ $index ] );
}
}

View File

@ -187,7 +187,7 @@ class WC_Free_Shipping extends WC_Shipping_Method {
foreach ($woocommerce->cart->applied_coupons as $code) {
$coupon = new WC_Coupon( $code );
if ( $coupon->enable_free_shipping() )
if ( $coupon->is_valid() && $coupon->enable_free_shipping() )
$has_coupon = true;
}
}