customer ); } // Not rounded to the price decimals: like product lines with prices including tax, the net // keeps WooCommerce's rounding precision so net + rounded tax is exactly the amount entered // (1.99 → 1.644628 + 0.35). WC_Cart_Totals rounds the totals afterwards. $taxes = \WC_Tax::calc_inclusive_tax( $amount, $rates ); return round( $amount - (float) array_sum( $taxes ), wc_get_rounding_precision() ); } /** * Estimated tax for a net amount and the current customer. * * @param float $net Net amount. * @param bool $taxable Taxable. * @param string $tax_class Tax class. * @param Context $context Context. */ public function tax_for( float $net, bool $taxable, string $tax_class, Context $context ): float { if ( ! $taxable || ! wc_tax_enabled() || $net <= 0 ) { return 0.0; } if ( $context->customer && $context->customer->get_is_vat_exempt() ) { return 0.0; } $rates = \WC_Tax::get_rates( $tax_class, $context->customer ); $taxes = \WC_Tax::calc_tax( $net, $rates, false ); return round( (float) array_sum( $taxes ), wc_get_price_decimals() ); } /** * Whether prices are displayed including tax in the cart/checkout. * * @param Context $context Context. */ public function display_including_tax( Context $context ): bool { if ( $context->cart ) { return (bool) $context->cart->display_prices_including_tax(); } return 'incl' === get_option( 'woocommerce_tax_display_cart' ); } }