diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index 4c794c8c1b2..c8469de8c84 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -1279,7 +1279,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { // If the prices include tax, discounts should be taken off the tax inclusive prices like in the cart. if ( $this->get_prices_include_tax() && wc_tax_enabled() && 'taxable' === $item->get_tax_status() ) { - $taxes = WC_Tax::calc_tax( $amount, WC_Tax::get_rates_from_location( $item->get_tax_class(), $tax_location ), true ); + $taxes = WC_Tax::calc_tax( $amount, $this->get_tax_rates( $item->get_tax_class(), $tax_location ), true ); // Use unrounded taxes so totals will be re-calculated accurately, like in cart. $amount = $amount - array_sum( $taxes ); @@ -1330,7 +1330,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { continue; } - $taxes = array_sum( WC_Tax::calc_tax( $item_discount_amount, WC_Tax::get_rates_from_location( $item->get_tax_class(), $tax_location ), $this->get_prices_include_tax() ) ); + $taxes = array_sum( WC_Tax::calc_tax( $item_discount_amount, $this->get_tax_rates( $item->get_tax_class(), $tax_location ), $this->get_prices_include_tax() ) ); if ( 'yes' !== get_option( 'woocommerce_tax_round_at_subtotal' ) ) { $taxes = wc_round_tax_total( $taxes ); } @@ -1524,6 +1524,21 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { return apply_filters( 'woocommerce_order_get_tax_location', $args, $this ); } + /** + * Get tax rates for an order. Use order's shipping or billing address, defaults to base location. + * + * @param string $tax_class Tax class to get rates for. + * @param array $location_args Location to compute rates for. Should be in form: array( country, state, postcode, city). + * @param object $customer Only used to maintain backward compatibility for filter `woocommerce-matched_rates`. + * + * @return mixed|void Tax rates. + */ + protected function get_tax_rates( $tax_class, $location_args = array(), $customer = null ) { + $tax_location = $this->get_tax_location( $location_args ); + $tax_location = array( $tax_location['country'], $tax_location['state'], $tax_location['postcode'], $tax_location['city'] ); + return WC_Tax::get_rates_from_location( $tax_class, $tax_location, $customer ); + } + /** * Calculate taxes for all line items and shipping, and store the totals and tax rows. *