pmpro_formatPrice

Format a price per the currency settings.

Description

pmpro_formatPrice( $price ); 

Parameters (1)

0. $price
The price.

Usage

  1. if ( !function_exists( 'pmpro_formatPrice' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // The price. 
  5. $price = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = pmpro_formatPrice($price); 
  9.  

Defined (1)

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

/includes/functions.php  
  1. function pmpro_formatPrice($price) 
  2. global $pmpro_currency, $pmpro_currency_symbol, $pmpro_currencies; 
  3.  
  4. //start with the price formatted with two decimals 
  5. $formatted = number_format((double)$price, 2); 
  6.  
  7. //settings stored in array? 
  8. if(!empty($pmpro_currencies[$pmpro_currency]) && is_array($pmpro_currencies[$pmpro_currency])) 
  9. //format number do decimals, with decimal_separator and thousands_separator 
  10. $formatted = number_format($price,  
  11. (isset($pmpro_currencies[$pmpro_currency]['decimals']) ? (int)$pmpro_currencies[$pmpro_currency]['decimals'] : 2),  
  12. (isset($pmpro_currencies[$pmpro_currency]['decimal_separator']) ? $pmpro_currencies[$pmpro_currency]['decimal_separator'] : '.'),  
  13. (isset($pmpro_currencies[$pmpro_currency]['thousands_separator']) ? $pmpro_currencies[$pmpro_currency]['thousands_separator'] : ', ') 
  14. ); 
  15.  
  16. //which side is the symbol on? 
  17. if(!empty($pmpro_currencies[$pmpro_currency]['position']) && $pmpro_currencies[$pmpro_currency]['position']== 'left') 
  18. $formatted = $pmpro_currency_symbol . $formatted; 
  19. else 
  20. $formatted = $formatted . $pmpro_currency_symbol; 
  21. else 
  22. $formatted = $pmpro_currency_symbol . $formatted; //default to symbol on the left 
  23.  
  24. //filter 
  25. return apply_filters('pmpro_format_price', $formatted, $price, $pmpro_currency, $pmpro_currency_symbol);