Fixed object subtotal retrieved in Discounts class for orders when prices include tax
This commit is contained in:
parent
f3927c786a
commit
eac4750cb0
|
@ -445,6 +445,16 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
||||||
return apply_filters( 'woocommerce_order_get_subtotal', (float) $subtotal, $this );
|
return apply_filters( 'woocommerce_order_get_subtotal', (float) $subtotal, $this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets order subtotal tax.
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function get_subtotal_tax() {
|
||||||
|
$subtotal = NumberUtil::round( $this->get_cart_subtotal_tax_for_order(), wc_get_price_decimals() );
|
||||||
|
return apply_filters( 'woocommerce_order_get_subtotal_tax', (float) $subtotal, $this );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get taxes, merged by code, formatted ready for output.
|
* Get taxes, merged by code, formatted ready for output.
|
||||||
*
|
*
|
||||||
|
@ -1695,6 +1705,19 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Helper function.
|
||||||
|
* If you add all items in this order in cart again, this would be the cart subtotal tax (assuming all other settings are same).
|
||||||
|
*
|
||||||
|
* @return float Cart subtotal tax.
|
||||||
|
*/
|
||||||
|
protected function get_cart_subtotal_tax_for_order() {
|
||||||
|
return wc_remove_number_precision(
|
||||||
|
$this->get_rounded_items_total(
|
||||||
|
$this->get_values_for_total( 'subtotal_tax' )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function.
|
* Helper function.
|
||||||
|
|
|
@ -948,7 +948,7 @@ class WC_Discounts {
|
||||||
|
|
||||||
if ( $this->object->get_prices_include_tax() ) {
|
if ( $this->object->get_prices_include_tax() ) {
|
||||||
// Add tax to tax-exclusive subtotal.
|
// Add tax to tax-exclusive subtotal.
|
||||||
$subtotal = $subtotal + wc_add_number_precision( NumberUtil::round( $this->object->get_total_tax(), wc_get_price_decimals() ) );
|
$subtotal = $subtotal + wc_add_number_precision( NumberUtil::round( $this->object->get_subtotal_tax(), wc_get_price_decimals() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $subtotal;
|
return $subtotal;
|
||||||
|
|
Loading…
Reference in New Issue