From c411c43fdf70e789d67717d286e62189dfed9bb5 Mon Sep 17 00:00:00 2001 From: Chunkford Date: Wed, 7 Mar 2018 13:14:59 +0000 Subject: [PATCH 1/3] Update wc-core-functions.php --- includes/wc-core-functions.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/includes/wc-core-functions.php b/includes/wc-core-functions.php index 6822904ec20..7bdba1ed0a3 100644 --- a/includes/wc-core-functions.php +++ b/includes/wc-core-functions.php @@ -2060,3 +2060,20 @@ function wc_decimal_to_fraction( $decimal ) { return array( $numerator, $denominator ); } + +/** + * Round discount. + * + * @param double $value Amount to round. + * @param int $precision DP to round. + * @return float + */ +function wc_round_discount( $value, $precision ) { + if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) { + return round( $value, $precision, WC_DISCOUNT_ROUNDING_MODE ); + } elseif ( 2 === WC_DISCOUNT_ROUNDING_MODE ) { + return wc_legacy_round_half_down( $value, $precision ); + } else { + return round( $value, $precision ); + } +} From 732416ff346eb4cfc7965064b4fe77a5f5bd8df1 Mon Sep 17 00:00:00 2001 From: Chunkford Date: Wed, 7 Mar 2018 13:21:23 +0000 Subject: [PATCH 2/3] Update wc-cart-functions.php --- includes/wc-cart-functions.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/includes/wc-cart-functions.php b/includes/wc-cart-functions.php index 4eff33189ec..a89786ea4e0 100644 --- a/includes/wc-cart-functions.php +++ b/includes/wc-cart-functions.php @@ -374,13 +374,7 @@ function wc_cart_totals_shipping_method_label( $method ) { * @return float */ function wc_cart_round_discount( $value, $precision ) { - if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) { - return round( $value, $precision, WC_DISCOUNT_ROUNDING_MODE ); - } elseif ( 2 === WC_DISCOUNT_ROUNDING_MODE ) { - return wc_legacy_round_half_down( $value, $precision ); - } else { - return round( $value, $precision ); - } + return wc_round_discount( $value, $precision ); } /** From 5416c58f4e2e7136d50e03da856dccedd04eae35 Mon Sep 17 00:00:00 2001 From: Chunkford Date: Wed, 7 Mar 2018 13:36:43 +0000 Subject: [PATCH 3/3] Update class-wc-discounts.php --- includes/class-wc-discounts.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-wc-discounts.php b/includes/class-wc-discounts.php index 15b32a138b4..a99cfb74ce3 100644 --- a/includes/class-wc-discounts.php +++ b/includes/class-wc-discounts.php @@ -379,7 +379,7 @@ class WC_Discounts { } } - $discount = wc_cart_round_discount( min( $discounted_price, $discount ), 0 ); + $discount = wc_round_discount( min( $discounted_price, $discount ), 0 ); $cart_total = $cart_total + $price_to_discount; $total_discount = $total_discount + $discount; $applied_count = $applied_count + $apply_quantity; @@ -389,7 +389,7 @@ class WC_Discounts { } // Work out how much discount would have been given to the cart as a whole and compare to what was discounted on all line items. - $cart_total_discount = wc_cart_round_discount( $cart_total * ( $coupon_amount / 100 ), 0 ); + $cart_total_discount = wc_round_discount( $cart_total * ( $coupon_amount / 100 ), 0 ); if ( $total_discount < $cart_total_discount && $adjust_final_discount ) { $total_discount += $this->apply_coupon_remainder( $coupon, $items_to_apply, $cart_total_discount - $total_discount );