WC_Cart_Totals::remove_item_base_taxes()protectedWC 3.2.2

Ran to remove all base taxes from an item. Used when prices include tax, and the customer is tax exempt.

Method of the class: WC_Cart_Totals{}

Return

Object.

Usage

// protected - for code of main (parent) or child class
$result = $this->remove_item_base_taxes( $item );
$item(object) (required)
Item to adjust the prices of.

Changelog

Since 3.2.2 Introduced.

WC_Cart_Totals::remove_item_base_taxes() code WC 8.7.0

protected function remove_item_base_taxes( $item ) {
	if ( $item->price_includes_tax && $item->taxable ) {
		if ( apply_filters( 'woocommerce_adjust_non_base_location_prices', true ) ) {
			$base_tax_rates = WC_Tax::get_base_tax_rates( $item->product->get_tax_class( 'unfiltered' ) );
		} else {
			/**
			 * If we want all customers to pay the same price on this store, we should not remove base taxes from a VAT exempt user's price,
			 * but just the relevant tax rate. See issue #20911.
			 */
			$base_tax_rates = $item->tax_rates;
		}

		// Work out a new base price without the shop's base tax.
		$taxes = WC_Tax::calc_tax( $item->price, $base_tax_rates, true );

		// Now we have a new item price (excluding TAX).
		$item->price              = NumberUtil::round( $item->price - array_sum( $taxes ) );
		$item->price_includes_tax = false;
	}
	return $item;
}