/** * Formats price * * @access public * @param $price * @param bool $in_default_currency * @return bool|string */ public static function format_price($price, $in_default_currency = false) { if (empty($price) || !is_numeric($price)) { return false; } $currency_index = $in_default_currency ? 0 : Realia_Currencies::get_current_currency_index(); $currencies = get_theme_mod('realia_currencies'); if (!$in_default_currency) { $price = $price * Realia_Currencies::get_current_currency_rate(); } $price_parts_dot = explode('.', $price); $price_parts_col = explode(',', $price); if (count($price_parts_dot) > 1 || count($price_parts_col) > 1) { $decimals = !empty($currencies[$currency_index]['money_decimals']) ? $currencies[$currency_index]['money_decimals'] : '0'; } else { $decimals = 0; } $dec_point = !empty($currencies[$currency_index]['money_dec_point']) ? $currencies[$currency_index]['money_dec_point'] : '.'; $thousands_separator = !empty($currencies[$currency_index]['money_thousands_separator']) ? $currencies[$currency_index]['money_thousands_separator'] : ','; $price = number_format($price, $decimals, $dec_point, $thousands_separator); $currency_symbol = !empty($currencies[$currency_index]['symbol']) ? $currencies[$currency_index]['symbol'] : '$'; $currency_show_symbol_after = !empty($currencies[$currency_index]['show_after']) ? true : false; if (!empty($currency_symbol)) { if ($currency_show_symbol_after) { $price = $price . ' ' . $currency_symbol; } else { $price = $currency_symbol . ' ' . $price; } } return $price; }