public function before_rendering_field($field) { if ('currency_identifier' == $field['name'] || 'currency_position' == $field['name']) { $currency = APP_Currencies::get_currency(APP_Gateway_Registry::get_options()->currency_code); foreach ($field['values'] as $key => $value) { $field['values'][$key] = str_replace(array('{symbol}', '{code}'), array($currency['symbol'], $currency['code']), $value); } } return $field; }
/** * Returns the price given the arguments in add_theme_support for 'app-price-format' * Note: if hide_decimals is turned on, the amount will be rounded. * * @param int $price The numerical value to format * @param string $override_currency The currency the value is in (defaults to 'currency_default') * @param string $override_format The format the value is in (defaults to 'currency_identifier') * @return string The formatted price */ function appthemes_get_price($price, $override_currency = '', $override_identifier = '') { $format_args = appthemes_price_format_get_args(); $decimals = $format_args['hide_decimals'] ? 0 : 2; $base_price = number_format($price, $decimals, $format_args['decimal_separator'], $format_args['thousands_separator']); $currency_code = empty($override_currency) ? $format_args['currency_default'] : $override_currency; $currency_identifier = empty($override_identifier) ? $format_args['currency_identifier'] : $override_identifier; $position = $format_args['currency_position']; $identifier = APP_Currencies::get_currency($currency_code, $currency_identifier); return _appthemes_format_display_price($base_price, $identifier, $position); }
/** * Verify that retrieving an unregistered currency returns false */ public function test_get_bad_currency() { $this->assertFalse(APP_Currencies::get_currency('not-a-real-currency')); }