set_coupon_discount_amounts should support woocommerce_tax_round_at_subtotal

This commit is contained in:
Mike Jolley 2019-01-11 13:09:20 +00:00
parent caffa319f4
commit 50ca24e5d9
1 changed files with 15 additions and 4 deletions

View File

@ -1124,11 +1124,22 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
$item = $this->get_item( $item_id, false );
if ( $this->get_prices_include_tax() && wc_tax_enabled() ) {
$amount_tax = array_sum( WC_Tax::calc_tax( $item_discount_amount, WC_Tax::get_rates( $item->get_tax_class() ), true ) );
$discount_tax += $amount_tax;
$amount = $amount - $amount_tax;
$taxes = WC_Tax::calc_tax( $item_discount_amount, WC_Tax::get_rates( $item->get_tax_class() ), true );
if ( 'yes' !== get_option( 'woocommerce_tax_round_at_subtotal' ) ) {
$taxes = array_map( 'wc_round_tax_total', $taxes );
}
$discount_tax += array_sum( $taxes );
$amount = $amount - array_sum( $taxes );
} else {
$discount_tax += array_sum( WC_Tax::calc_tax( $item_discount_amount, WC_Tax::get_rates( $item->get_tax_class() ) ) );
$taxes = WC_Tax::calc_tax( $item_discount_amount, WC_Tax::get_rates( $item->get_tax_class() ) );
if ( 'yes' !== get_option( 'woocommerce_tax_round_at_subtotal' ) ) {
$taxes = array_map( 'wc_round_tax_total', $taxes );
}
$discount_tax += array_sum( $taxes );
}
}