Add code comments for confusing changes.
This commit is contained in:
parent
6c2f30132d
commit
18411d2b3b
|
@ -189,7 +189,10 @@ if ( wc_tax_enabled() ) {
|
|||
<td class="label"><?php echo esc_html( $tax_total->label ); ?>:</td>
|
||||
<td width="1%"></td>
|
||||
<td class="total">
|
||||
<?php echo wc_price( wc_round_tax_total( $tax_total->amount ), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php
|
||||
// We use wc_round_tax_total here because tax may need to be round up or round down depending upon settings, whereas wc_price alone will always round it down.
|
||||
echo wc_price( wc_round_tax_total( $tax_total->amount ), array( 'currency' => $order->get_currency() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
|
|
@ -750,6 +750,7 @@ final class WC_Cart_Totals {
|
|||
|
||||
$items_subtotal = $this->get_rounded_items_total( $this->get_values_for_total( 'subtotal' ) );
|
||||
|
||||
// Prices are not rounded here because they should already be rounded based on settings in `get_rounded_items_total` and in `round_line_tax` method calls.
|
||||
$this->set_total( 'items_subtotal', $items_subtotal );
|
||||
$this->set_total( 'items_subtotal_tax', array_sum( $merged_subtotal_taxes ), 0 );
|
||||
|
||||
|
@ -863,7 +864,7 @@ final class WC_Cart_Totals {
|
|||
protected function calculate_totals() {
|
||||
$this->set_total( 'total', NumberUtil::round( $this->get_total( 'items_total', true ) + $this->get_total( 'fees_total', true ) + $this->get_total( 'shipping_total', true ) + array_sum( $this->get_merged_taxes( true ) ), 0 ) );
|
||||
$items_tax = array_sum( $this->get_merged_taxes( false, array( 'items' ) ) );
|
||||
// Shipping and fee taxes are rounded because they were entered excluding taxes.
|
||||
// Shipping and fee taxes are rounded seperately because they were entered excluding taxes (as opposed to item prices, which may or may not be including taxes depending upon settings).
|
||||
$shipping_and_fee_taxes = NumberUtil::round( array_sum( $this->get_merged_taxes( false, array( 'fees', 'shipping' ) ) ), wc_get_price_decimals() );
|
||||
$this->cart->set_total_tax( $items_tax + $shipping_and_fee_taxes );
|
||||
|
||||
|
|
|
@ -73,8 +73,8 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
|
|||
|
||||
$this->assertEquals( '13.58', WC()->cart->get_total( 'edit' ) );
|
||||
$this->assertEquals( 0.66, WC()->cart->get_total_tax() );
|
||||
$this->assertEquals( 0.83, wc_round_tax_total( WC()->cart->get_discount_tax() ) );
|
||||
$this->assertEquals( 4.17, \Automattic\WooCommerce\Utilities\NumberUtil::round( WC()->cart->get_discount_total(), 2 ) );
|
||||
$this->assertEquals( 0.83, wc_format_decimal( WC()->cart->get_discount_tax(), 2 ) );
|
||||
$this->assertEquals( 4.17, wc_format_decimal( WC()->cart->get_discount_total(), 2 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue