wc_get_price_excluding_tax

For a given product, and optionally price/qty, work out the price with tax excluded, based on store settings.

Description

(float) wc_get_price_excluding_tax( (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_excluding_tax' ) ) { 
  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_excluding_tax($product, $args); 
  12.  

Defined (1)

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

/includes/wc-product-functions.php  
  1. function wc_get_price_excluding_tax( $product, $args = array() ) { 
  2. $args = wp_parse_args( $args, array( 
  3. 'qty' => '',  
  4. 'price' => '',  
  5. ) ); 
  6.  
  7. $price = '' !== $args['price'] ? max( 0.0, (float) $args['price'] ) : $product->get_price(); 
  8. $qty = '' !== $args['qty'] ? max( 0.0, (float) $args['qty'] ) : 1; 
  9.  
  10. if ( '' === $price ) { 
  11. return ''; 
  12. } elseif ( empty( $qty ) ) { 
  13. return 0.0; 
  14.  
  15. if ( $product->is_taxable() && wc_prices_include_tax() ) { 
  16. $tax_rates = WC_Tax::get_base_tax_rates( $product->get_tax_class( 'unfiltered' ) ); 
  17. $taxes = WC_Tax::calc_tax( $price * $qty, $tax_rates, true ); 
  18. $price = WC_Tax::round( $price * $qty - array_sum( $taxes ) ); 
  19. } else { 
  20. $price = $price * $qty; 
  21.  
  22. return apply_filters( 'woocommerce_get_price_excluding_tax', $price, $qty, $product );