/** * Format a price amount. * * The available options that you can specify in the $args argument include: * 'display_currency_symbol' - Whether to attach the currency symbol to the figure. * Defaults to true. * 'display_decimal_point' - Whether to display the decimal point. * Defaults to true. * 'display_currency_code' - Whether to attach the currency code to the figure. * Defaults to fault. * 'isocode' - Specify the isocode of the base country that you want to use for * this price. * Defaults to the settings in Settings->Store->General. * * @since 4.0 * @uses apply_filters() Applies 'wpsc_format_currency' filter * @uses apply_filters() Applies 'wpsc_format_currency_currency_code' filter. * @uses apply_filters() Applies 'wpsc_format_currency_currency_symbol' filter. * @uses apply_filters() Applies 'wpsc_format_currency_decimal_separator' filter. * @uses apply_filters() Applies 'wpsc_format_currency_thousands_separator' filter. * @uses apply_filters() Applies 'wpsc_modify_decimals' filter. * @uses get_option() Gets the value of 'currency_sign_location' in Settings->Store->General. * @uses get_option() Gets the value of 'currency_type' in Settings->Store->General. * @uses WPSC_Country::__construct() * @uses WPSC_Country::get() * @uses wp_parse_args() * * @param float|int|string $amt The price you want to format. * @param string|array $args A query string or array containing the options. Defaults to ''. * @return string The formatted price. */ function wpsc_format_currency($amt, $args = '') { $defaults = array('display_currency_symbol' => true, 'display_decimal_point' => true, 'display_currency_code' => false, 'isocode' => false, 'currency_code' => false); $args = wp_parse_args($args); // Either display symbol or code, not both if (array_key_exists('display_currency_symbol', $args)) { $args['display_currency_code'] = !$args['display_currency_symbol']; } elseif (array_key_exists('display_currency_code', $args)) { $args['display_currency_symbol'] = !$args['display_currency_code']; } $r = wp_parse_args($args, $defaults); extract($r); $currencies_without_fractions = WPSC_Payment_Gateways::currencies_without_fractions(); if ($isocode) { $currency = new WPSC_Country($isocode); } else { $currency = new WPSC_Country(get_option('currency_type')); } $currency_code = $currency->get_currency_code(); // No decimal point, no decimals if (!$display_decimal_point || in_array($currency_code, $currencies_without_fractions)) { $decimals = 0; } else { $decimals = 2; // default is 2 } $decimals = apply_filters('wpsc_modify_decimals', $decimals, $isocode); $decimal_separator = apply_filters('wpsc_format_currency_decimal_separator', wpsc_get_option('decimal_separator'), $isocode); $thousands_separator = apply_filters('wpsc_format_currency_thousands_separator', wpsc_get_option('thousands_separator'), $isocode); // Format the price for output $formatted = number_format($amt, $decimals, $decimal_separator, $thousands_separator); if (!$display_currency_code) { $currency_code = ''; } $symbol = $display_currency_symbol ? $currency->get_currency_symbol() : ''; $symbol = esc_html($symbol); $symbol = apply_filters('wpsc_format_currency_currency_symbol', $symbol, $isocode); $currency_sign_location = get_option('currency_sign_location'); // Rejig the currency sign location switch ($currency_sign_location) { case 1: $format_string = '%3$s%1$s%2$s'; break; case 2: $format_string = '%3$s %1$s%2$s'; break; case 4: $format_string = '%1$s%2$s %3$s'; break; case 3: default: $format_string = '%1$s %2$s%3$s'; break; } $currency_code = apply_filters('wpsc_format_currency_currency_code', $currency_code, $isocode); // Compile the output $output = trim(sprintf($format_string, $currency_code, $symbol, $formatted)); return $output; }
private function get_shipping_method_js_vars() { global $wpsc_cart; $js_var = array('subtotal' => (double) $wpsc_cart->calculate_subtotal(), 'shipping' => array(), 'tax' => wpsc_is_tax_enabled() && !wpsc_is_tax_included() ? (double) wpsc_cart_tax(false) : 0, 'discount' => wpsc_coupon_amount(false) > 0 ? wpsc_coupon_amount(false) : 0); foreach ($this->shipping_calculator->sorted_quotes as $module_name => $quotes) { foreach ($quotes as $option => $cost) { $id = $this->shipping_calculator->ids[$module_name][$option]; $js_var['shipping'][$id] = $cost; } } $currency = new WPSC_Country(get_option('currency_type')); $currency_code = $currency->get_currency_code(); $isocode = $currency->get_isocode(); $without_fractions = in_array($currency_code, WPSC_Payment_Gateways::currencies_without_fractions()); $decimals = $without_fractions ? 0 : 2; $decimals = apply_filters('wpsc_modify_decimals', $decimals, $isocode); $decimal_separator = apply_filters('wpsc_format_currency_decimal_separator', wpsc_get_option('decimal_separator'), $isocode); $thousands_separator = apply_filters('wpsc_format_currency_thousands_separator', wpsc_get_option('thousands_separator'), $isocode); $symbol = apply_filters('wpsc_format_currency_currency_symbol', $currency->get_currency_symbol()); $sign_location = get_option('currency_sign_location'); $js_var['formatter'] = array('currency_code' => $currency_code, 'without_fractions' => $without_fractions, 'decimals' => $decimals, 'decimal_separator' => $decimal_separator, 'thousands_separator' => $thousands_separator, 'symbol' => $symbol, 'sign_location' => $sign_location); return $js_var; }