diff --git a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php index a534fba5af3..b999500b7df 100644 --- a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php +++ b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php @@ -445,6 +445,16 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { 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. * @@ -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. diff --git a/plugins/woocommerce/includes/class-wc-discounts.php b/plugins/woocommerce/includes/class-wc-discounts.php index 8b2c5b4aabc..407c10de959 100644 --- a/plugins/woocommerce/includes/class-wc-discounts.php +++ b/plugins/woocommerce/includes/class-wc-discounts.php @@ -948,7 +948,7 @@ class WC_Discounts { if ( $this->object->get_prices_include_tax() ) { // 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;