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.

Метод класса: WC_Cart_Totals{}

Хуки из метода

Возвращает

Объект.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->remove_item_base_taxes( $item );
$item(объект) (обязательный)
Item to adjust the prices of.

Список изменений

С версии 3.2.2 Введена.

Код WC_Cart_Totals::remove_item_base_taxes() 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;
}