yith_get_formatted_price

Format the price with a currency symbol.

Description

(string) yith_get_formatted_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( 'yith_get_formatted_price' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'yith-woocommerce-compare/plugin-fw/yit-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 = yith_get_formatted_price($price, $args); 
  12.  

Defined (1)

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

/plugin-fw/yit-functions.php  
  1. function yith_get_formatted_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, get_woocommerce_currency_symbol ( $currency ), $price ); 
  19. $return = $formatted_price; 
  20.  
  21. return apply_filters ( 'wc_price', $return, $price, $args );