From 42f77950bde33ed703c5f37fdde12459e0156d62 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 11 Jan 2019 13:17:06 +0000 Subject: [PATCH] Make total recalc use unrounded tax values to fix test WC_Tests_Order_Coupons::test_add_coupon_to_order --- includes/abstracts/abstract-wc-order.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index e5e55e84445..c5ce6ce533c 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -1483,14 +1483,21 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { $this->calculate_taxes(); } - // Sum taxes. + // Sum taxes again so we can work out how much tax was discounted. This uses original values, not those possibly rounded to 2dp. foreach ( $this->get_items() as $item ) { - $cart_subtotal_tax += $item->get_subtotal_tax(); - $cart_total_tax += $item->get_total_tax(); + $taxes = $item->get_taxes(); + + foreach ( $taxes['total'] as $tax_rate_id => $tax ) { + $cart_total_tax += (float) $tax; + } + + foreach ( $taxes['subtotal'] as $tax_rate_id => $tax ) { + $cart_subtotal_tax += (float) $tax; + } } $this->set_discount_total( $cart_subtotal - $cart_total ); - $this->set_discount_tax( $cart_subtotal_tax - $cart_total_tax ); + $this->set_discount_tax( wc_round_tax_total( $cart_subtotal_tax - $cart_total_tax ) ); $this->set_total( round( $cart_total + $fee_total + $this->get_shipping_total() + $this->get_cart_tax() + $this->get_shipping_tax(), wc_get_price_decimals() ) ); do_action( 'woocommerce_order_after_calculate_totals', $and_taxes, $this );