Ejemplo n.º 1
1
 /**
  * Currency switcher
  *
  * @access public
  * @return void|bool|string
  */
 public static function currencies($atts)
 {
     $atts = shortcode_atts(array(), $atts, 'realia_currencies');
     if (!current_theme_supports('realia-currencies')) {
         return;
     }
     $currencies = get_theme_mod('realia_currencies');
     if ($currencies == false) {
         $currencies = array(array('symbol' => '$', 'code' => 'USD', 'show_after' => false, 'money_decimals' => 2, 'money_dec_point' => '.', 'money_thousands_separator' => ','));
     } elseif (!is_array($currencies)) {
         return false;
     }
     array_splice($currencies, get_theme_mod('realia_currencies_other', 0) + 1);
     $result = '';
     if (!empty($currencies) && is_array($currencies)) {
         ksort($currencies);
         $currency_code = Realia_Currencies::get_current_currency_code();
         $result = '';
         ob_start();
         include Realia_Template_Loader::locate('misc/currencies');
         $result = ob_get_contents();
         ob_end_clean();
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
    public static function get_current_currency_index()
    {
        $currency_code = self::get_current_currency_code();
        if (!empty($currency_code)) {
            $currencies = get_theme_mod('realia_currencies');
            if (!empty($currencies) && is_array($currencies)) {
                foreach ($currencies as $key => $currency) {
                    if ($currency['code'] == self::get_current_currency_code()) {
                        return $key;
                    }
                }
            }
        }
        return 0;
    }
    /**
     * Gets current currency rate
     *
     * @access public
     * @return float
     */
    public static function get_current_currency_rate()
    {
        $currencies = get_theme_mod('realia_currencies');
        $currency_index = self::get_current_currency_index();
        $rate = !empty($currencies[$currency_index]['rate']) ? $currencies[$currency_index]['rate'] : 1;
        return $rate;
    }
}
Realia_Currencies::init();