wc_get_price_to_display()
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.
No Hooks.
Returns
float.
Usage
wc_get_price_to_display( $product, $args );
- $product(WC_Product) (required)
- WC_Product object.
- $args(array)
- Optional arguments to pass product quantity and price.
Default:array()
Changelog
| Since 3.0.0 | Introduced. |
| Since 7.6.0 | Added display_context argument. |
wc_get_price_to_display() wc get price to display code WC 10.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,
)
);
}