From d0f47a7980650ea6fae98325a4f405f969acd095 Mon Sep 17 00:00:00 2001 From: Claudiu Lodromanean Date: Tue, 7 Mar 2017 13:17:36 -0800 Subject: [PATCH] Revert to original behavior --- includes/class-wc-cart.php | 30 +++++++++++++++--------------- tests/unit-tests/cart/cart.php | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/includes/class-wc-cart.php b/includes/class-wc-cart.php index 56c80acd041..951a9fc63fe 100644 --- a/includes/class-wc-cart.php +++ b/includes/class-wc-cart.php @@ -1736,21 +1736,6 @@ class WC_Cart { return false; } - // Check to see if an individual use coupon is set - if ( $this->applied_coupons ) { - foreach ( $this->applied_coupons as $code ) { - $coupon = new WC_Coupon( $code ); - - if ( $coupon->get_individual_use() && false === apply_filters( 'woocommerce_apply_with_individual_use_coupon', false, $the_coupon, $coupon, $this->applied_coupons ) ) { - - // Reject new coupon - $coupon->add_coupon_message( WC_Coupon::E_WC_COUPON_ALREADY_APPLIED_INDIV_USE_ONLY ); - - return false; - } - } - } - // If its individual use then remove other coupons if ( $the_coupon->get_individual_use() ) { $coupons_to_keep = apply_filters( 'woocommerce_apply_individual_use_coupon', array(), $the_coupon, $this->applied_coupons ); @@ -1769,6 +1754,21 @@ class WC_Cart { } } + // Check to see if an individual use coupon is set + if ( $this->applied_coupons ) { + foreach ( $this->applied_coupons as $code ) { + $coupon = new WC_Coupon( $code ); + + if ( $coupon->get_individual_use() && false === apply_filters( 'woocommerce_apply_with_individual_use_coupon', false, $the_coupon, $coupon, $this->applied_coupons ) ) { + + // Reject new coupon + $coupon->add_coupon_message( WC_Coupon::E_WC_COUPON_ALREADY_APPLIED_INDIV_USE_ONLY ); + + return false; + } + } + } + $this->applied_coupons[] = $coupon_code; // Choose free shipping diff --git a/tests/unit-tests/cart/cart.php b/tests/unit-tests/cart/cart.php index 5145de7c2e9..e0a1983f6cc 100644 --- a/tests/unit-tests/cart/cart.php +++ b/tests/unit-tests/cart/cart.php @@ -645,7 +645,7 @@ class WC_Tests_Cart extends WC_Unit_Test_Case { $coupons = WC()->cart->get_coupons(); $this->assertEquals( count( $coupons ), 1 ); - $this->assertEquals( 'code1', reset( $coupons )->get_code() ); + $this->assertEquals( 'code2', reset( $coupons )->get_code() ); // Clean up WC()->cart->empty_cart();