WC_Cart_Totals::adjust_non_base_location_price()protectedWC 3.2.0

Only ran if woocommerce_adjust_non_base_location_prices is true.

If the customer is outside of the base location, this removes the base taxes. This is off by default unless the filter is used.

Uses edit context so unfiltered tax class is returned.

Method of the class: WC_Cart_Totals{}

No Hooks.

Return

Object.

Usage

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

Changelog

Since 3.2.0 Introduced.

WC_Cart_Totals::adjust_non_base_location_price() code WC 8.7.0

protected function adjust_non_base_location_price( $item ) {
	if ( $item->price_includes_tax && $item->taxable ) {
		$base_tax_rates = WC_Tax::get_base_tax_rates( $item->product->get_tax_class( 'unfiltered' ) );

		if ( $item->tax_rates !== $base_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 );
			$new_taxes = WC_Tax::calc_tax( $item->price - array_sum( $taxes ), $item->tax_rates, false );

			// Now we have a new item price.
			$item->price = $item->price - array_sum( $taxes ) + array_sum( $new_taxes );
		}
	}
	return $item;
}