Automattic\WooCommerce\StoreApi\Utilities

ProductQuery::adjust_price_filter_for_tax_class()protectedWC 1.0

Adjusts a price filter based on a tax class and whether or not the amount includes or excludes taxes.

This calculation logic is based on wc_get_price_excluding_tax and wc_get_price_including_tax in core.

{} Это метод класса: ProductQuery{}

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

Возвращает

float.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->adjust_price_filter_for_tax_class( $price_filter, $tax_class );
$price_filter(float) (обязательный)
Price filter amount as entered.
$tax_class(строка) (обязательный)
Tax class for adjustment.

Код ProductQuery::adjust_price_filter_for_tax_class() WC 6.9.4

protected function adjust_price_filter_for_tax_class( $price_filter, $tax_class ) {
	$tax_display    = get_option( 'woocommerce_tax_display_shop' );
	$tax_rates      = WC_Tax::get_rates( $tax_class );
	$base_tax_rates = WC_Tax::get_base_tax_rates( $tax_class );

	// If prices are shown incl. tax, we want to remove the taxes from the filter amount to match prices stored excl. tax.
	if ( 'incl' === $tax_display ) {
		/**
		 * Filters if taxes should be removed from locations outside the store base location.
		 *
		 * The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing
		 * with out of base locations. e.g. If a product costs 10 including tax, all users will pay 10
		 * regardless of location and taxes.
		 *
		 * @internal Matches filter name in WooCommerce core.
		 *
		 * @param boolean $adjust_non_base_location_prices True by default.
		 * @return boolean
		 */
		$taxes = apply_filters( 'woocommerce_adjust_non_base_location_prices', true ) ? WC_Tax::calc_tax( $price_filter, $base_tax_rates, true ) : WC_Tax::calc_tax( $price_filter, $tax_rates, true );
		return $price_filter - array_sum( $taxes );
	}

	// If prices are shown excl. tax, add taxes to match the prices stored in the DB.
	$taxes = WC_Tax::calc_tax( $price_filter, $tax_rates, false );

	return $price_filter + array_sum( $taxes );
}