wc_get_price_to_display()WC 3.0.0

Returns the price including or excluding tax.

By default it's based on the 'woocommerce_tax_display_shop' setting. Set $arg['display_context'] to 'cart' to base on the 'woocommerce_tax_display_cart' setting instead.

Хуков нет.

Возвращает

float.

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

wc_get_price_to_display( $product, $args );
$product(WC_Product) (обязательный)
WC_Product object.
$args(массив)
Optional arguments to pass product quantity and price.
По умолчанию: array()

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

С версии 3.0.0 Введена.
С версии 7.6.0 Added display_context argument.

Код wc_get_price_to_display() WC 8.7.0

function wc_get_price_to_display( $product, $args = array() ) {
	$args = wp_parse_args(
		$args,
		array(
			'qty'             => 1,
			'price'           => $product->get_price(),
			'display_context' => 'shop',
		)
	);

	$price       = $args['price'];
	$qty         = $args['qty'];
	$tax_display = get_option(
		'cart' === $args['display_context'] ? 'woocommerce_tax_display_cart' : 'woocommerce_tax_display_shop'
	);

	return 'incl' === $tax_display ?
		wc_get_price_including_tax(
			$product,
			array(
				'qty'   => $qty,
				'price' => $price,
			)
		) :
		wc_get_price_excluding_tax(
			$product,
			array(
				'qty'   => $qty,
				'price' => $price,
			)
		);
}