wc_price

Format the price with a currency symbol.

Description

(string) wc_price( (float) $price, (array) $args = array() ); 

Returns (string)

Parameters (2)

0. $price (float)
The price.
1. $args — Optional. (array) => array()
(default: array())

Usage

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

Defined (1)

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

/includes/wc-formatting-functions.php  
  1. function wc_price( $price, $args = array() ) { 
  2. extract( apply_filters( 'wc_price_args', wp_parse_args( $args, array( 
  3. 'ex_tax_label' => false,  
  4. 'currency' => '',  
  5. 'decimal_separator' => wc_get_price_decimal_separator(),  
  6. 'thousand_separator' => wc_get_price_thousand_separator(),  
  7. 'decimals' => wc_get_price_decimals(),  
  8. 'price_format' => get_woocommerce_price_format(),  
  9. ) ) ) ); 
  10.  
  11. $negative = $price < 0; 
  12. $price = apply_filters( 'raw_woocommerce_price', floatval( $negative ? $price * -1 : $price ) ); 
  13. $price = apply_filters( 'formatted_woocommerce_price', number_format( $price, $decimals, $decimal_separator, $thousand_separator ), $price, $decimals, $decimal_separator, $thousand_separator ); 
  14.  
  15. if ( apply_filters( 'woocommerce_price_trim_zeros', false ) && $decimals > 0 ) { 
  16. $price = wc_trim_zeros( $price ); 
  17.  
  18. $formatted_price = ( $negative ? '-' : '' ) . sprintf( $price_format, '<span class="woocommerce-Price-currencySymbol">' . get_woocommerce_currency_symbol( $currency ) . '</span>', $price ); 
  19. $return = '<span class="woocommerce-Price-amount amount">' . $formatted_price . '</span>'; 
  20.  
  21. if ( $ex_tax_label && wc_tax_enabled() ) { 
  22. $return .= ' <small class="woocommerce-Price-taxLabel tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>'; 
  23.  
  24. return apply_filters( 'wc_price', $return, $price, $args );