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 );