rounding fixes for #2020
This commit is contained in:
parent
9ab2b8b4c7
commit
e0a67b3387
|
@ -1246,30 +1246,31 @@ class WC_Cart {
|
|||
|
||||
// ADJUST BASE if tax rate is different (different region or modified tax class)
|
||||
if ( $tax_rates !== $base_tax_rates ) {
|
||||
$base_taxes = $this->tax->calc_tax( $row_base_price, $base_tax_rates, true, true );
|
||||
$modded_taxes = $this->tax->calc_tax( $row_base_price - array_sum( $base_taxes ), $tax_rates, false );
|
||||
$row_base_price = ( $row_base_price - array_sum( $base_taxes ) ) + array_sum( $modded_taxes );
|
||||
$base_taxes = $this->tax->calc_tax( $row_base_price, $base_tax_rates, true, true );
|
||||
$modded_taxes = $this->tax->calc_tax( $row_base_price - array_sum( $base_taxes ), $tax_rates, false );
|
||||
$row_base_price = ( $row_base_price - array_sum( $base_taxes ) ) + array_sum( $modded_taxes );
|
||||
}
|
||||
|
||||
$taxes = $this->tax->calc_tax( $row_base_price, $tax_rates, true );
|
||||
$tax_amount = $this->tax->get_tax_total( $taxes );
|
||||
$taxes = $this->tax->calc_tax( $row_base_price, $tax_rates, true );
|
||||
$tax_amount = get_option('woocommerce_tax_round_at_subtotal') == 'no' ? $this->tax->get_tax_total( $taxes ) : array_sum( $taxes );
|
||||
|
||||
}
|
||||
|
||||
// Sub total is based on base prices (without discounts)
|
||||
$this->subtotal = $this->subtotal + $row_base_price;
|
||||
$this->subtotal_ex_tax = $this->subtotal_ex_tax + ( $row_base_price - $tax_amount);
|
||||
$this->subtotal = $this->subtotal + $row_base_price;
|
||||
$this->subtotal_ex_tax = $this->subtotal_ex_tax + ( $row_base_price - $tax_amount);
|
||||
|
||||
} else {
|
||||
|
||||
if ( $_product->is_taxable() ) {
|
||||
$tax_rates = $this->tax->get_rates( $_product->get_tax_class() );
|
||||
$taxes = $this->tax->calc_tax( $row_base_price, $tax_rates, false );
|
||||
$tax_amount = $this->tax->get_tax_total( $taxes );
|
||||
$tax_rates = $this->tax->get_rates( $_product->get_tax_class() );
|
||||
$taxes = $this->tax->calc_tax( $row_base_price, $tax_rates, false );
|
||||
$tax_amount = get_option('woocommerce_tax_round_at_subtotal') == 'no' ? $this->tax->get_tax_total( $taxes ) : array_sum( $taxes );
|
||||
}
|
||||
|
||||
// Sub total is based on base prices (without discounts)
|
||||
$this->subtotal = $this->subtotal + $row_base_price + $tax_amount;
|
||||
$this->subtotal_ex_tax = $this->subtotal_ex_tax + $row_base_price;
|
||||
$this->subtotal = $this->subtotal + $row_base_price + $tax_amount;
|
||||
$this->subtotal_ex_tax = $this->subtotal_ex_tax + $row_base_price;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -245,9 +245,9 @@ class WC_Checkout {
|
|||
woocommerce_add_order_item_meta( $item_id, '_product_id', $values['product_id'] );
|
||||
woocommerce_add_order_item_meta( $item_id, '_variation_id', $values['variation_id'] );
|
||||
woocommerce_add_order_item_meta( $item_id, '_line_subtotal', woocommerce_format_decimal( $values['line_subtotal'] ) );
|
||||
woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $values['line_subtotal_tax'] ) );
|
||||
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $values['line_total'] ) );
|
||||
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $values['line_tax'] ) );
|
||||
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $values['line_tax'], 4 ) );
|
||||
woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $values['line_subtotal_tax'], 4 ) );
|
||||
|
||||
// Store variation data in meta so admin can view it
|
||||
if ( $values['variation'] && is_array( $values['variation'] ) )
|
||||
|
|
|
@ -653,8 +653,11 @@ function woocommerce_trim_zeros( $price ) {
|
|||
* @param mixed $number
|
||||
* @return string
|
||||
*/
|
||||
function woocommerce_format_decimal( $number ) {
|
||||
$number = number_format( (float) $number, (int) get_option( 'woocommerce_price_num_decimals' ), '.', '' );
|
||||
function woocommerce_format_decimal( $number, $dp = '' ) {
|
||||
if ( $dp == '' )
|
||||
$dp = intval( get_option( 'woocommerce_price_num_decimals' ) );
|
||||
|
||||
$number = number_format( (float) $number, (int) $dp, '.', '' );
|
||||
|
||||
if ( strstr( $number, '.' ) )
|
||||
$number = rtrim( rtrim( $number, '0' ), '.' );
|
||||
|
|
Loading…
Reference in New Issue