wc_get_price_to_display

Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.

Description

(float) wc_get_price_to_display( (WC_Product) $product, (array) $args = array() ); 

Returns (float)

Parameters (2)

0. $product (WC_Product)
The product.
1. $args — Optional. (array) => array()
The args.

Usage

  1. if ( !function_exists( 'wc_get_price_to_display' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-product-functions.php'; 
  3.  
  4. // The product. 
  5. $product = null; 
  6.  
  7. // The args. 
  8. $args = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_get_price_to_display($product, $args); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-product-functions.php  
  1. function wc_get_price_to_display( $product, $args = array() ) { 
  2. $args = wp_parse_args( $args, array( 
  3. 'qty' => 1,  
  4. 'price' => $product->get_price(),  
  5. ) ); 
  6.  
  7. $price = $args['price']; 
  8. $qty = $args['qty']; 
  9.  
  10. return 'incl' === get_option( 'woocommerce_tax_display_shop' ) ? wc_get_price_including_tax( $product, array( 'qty' => $qty, 'price' => $price ) ) : wc_get_price_excluding_tax( $product, array( 'qty' => $qty, 'price' => $price ) );