From d222dd4c3773ee743614dc309d97464f06ad11f8 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 5 Aug 2015 13:45:28 +0100 Subject: [PATCH] Don't apply product discount if price is already 0 Closes #8725 --- includes/class-wc-coupon.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/includes/class-wc-coupon.php b/includes/class-wc-coupon.php index db18257e6a7..3c8068fdeac 100644 --- a/includes/class-wc-coupon.php +++ b/includes/class-wc-coupon.php @@ -634,16 +634,18 @@ class WC_Coupon { // Handle the limit_usage_to_x_items option if ( $this->is_type( array( 'percent_product', 'fixed_product' ) ) ) { - if ( '' === $this->limit_usage_to_x_items ) { - $limit_usage_qty = $cart_item_qty; - } else { - $limit_usage_qty = min( $this->limit_usage_to_x_items, $cart_item_qty ); - $this->limit_usage_to_x_items = max( 0, $this->limit_usage_to_x_items - $limit_usage_qty ); - } - if ( $single ) { - $discount = ( $discount * $limit_usage_qty ) / $cart_item_qty; - } else { - $discount = ( $discount / $cart_item_qty ) * $limit_usage_qty; + if ( $discounting_amount ) { + if ( '' === $this->limit_usage_to_x_items ) { + $limit_usage_qty = $cart_item_qty; + } else { + $limit_usage_qty = min( $this->limit_usage_to_x_items, $cart_item_qty ); + $this->limit_usage_to_x_items = max( 0, $this->limit_usage_to_x_items - $limit_usage_qty ); + } + if ( $single ) { + $discount = ( $discount * $limit_usage_qty ) / $cart_item_qty; + } else { + $discount = ( $discount / $cart_item_qty ) * $limit_usage_qty; + } } }