Skip to content

Commit

Permalink
Append codes from get_woocommerce_currency_symbol to option names ins…
Browse files Browse the repository at this point in the history
…tead of defining them in the strings.
  • Loading branch information
mikejolley committed Feb 2, 2013
1 parent 8b06ab4 commit 8b5c946
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 48 deletions.
38 changes: 7 additions & 31 deletions admin/settings/settings-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
'default' => 'no',
) : array();

$currency_code_options = get_woocommerce_currencies();

foreach ( $currency_code_options as $code => $name ) {
$currency_code_options[ $code ] = $name . ' (' . get_woocommerce_currency_symbol( $code ) . ')';
}

$woocommerce_settings['general'] = apply_filters('woocommerce_general_settings', array(

array( 'title' => __( 'General Options', 'woocommerce' ), 'type' => 'title', 'desc' => '', 'id' => 'general_options' ),
Expand All @@ -45,37 +51,7 @@
'type' => 'select',
'class' => 'chosen_select',
'desc_tip' => true,
'options' => array_unique( apply_filters( 'woocommerce_currencies', array(
'AUD' => __( 'Australian Dollars ($)', 'woocommerce' ),
'BRL' => __( 'Brazilian Real ($)', 'woocommerce' ),
'CAD' => __( 'Canadian Dollars ($)', 'woocommerce' ),
'RMB' => __( 'Chinese Yuan (¥)', 'woocommerce' ),
'CZK' => __( 'Czech Koruna (Kč)', 'woocommerce' ),
'DKK' => __( 'Danish Krone', 'woocommerce' ),
'EUR' => __( 'Euros (€)', 'woocommerce' ),
'HKD' => __( 'Hong Kong Dollar ($)', 'woocommerce' ),
'HUF' => __( 'Hungarian Forint', 'woocommerce' ),
'IDR' => __( 'Indonesia Rupiah (Rp)', 'woocommerce' ),
'ILS' => __( 'Israeli Shekel', 'woocommerce' ),
'JPY' => __( 'Japanese Yen (¥)', 'woocommerce' ),
'MYR' => __( 'Malaysian Ringgits (RM)', 'woocommerce' ),
'MXN' => __( 'Mexican Peso ($)', 'woocommerce' ),
'NOK' => __( 'Norwegian Krone', 'woocommerce' ),
'NZD' => __( 'New Zealand Dollar ($)', 'woocommerce' ),
'PHP' => __( 'Philippine Pesos', 'woocommerce' ),
'PLN' => __( 'Polish Zloty', 'woocommerce' ),
'GBP' => __( 'Pounds Sterling (£)', 'woocommerce' ),
'RON' => __( 'Romanian Leu (RON)', 'woocommerce' ),
'SGD' => __( 'Singapore Dollar ($)', 'woocommerce' ),
'ZAR' => __( 'South African rand (R)', 'woocommerce' ),
'SEK' => __( 'Swedish Krona', 'woocommerce' ),
'CHF' => __( 'Swiss Franc', 'woocommerce' ),
'TWD' => __( 'Taiwan New Dollars', 'woocommerce' ),
'THB' => __( 'Thai Baht', 'woocommerce' ),
'TRY' => __( 'Turkish Lira (TL)', 'woocommerce' ),
'USD' => __( 'US Dollars ($)', 'woocommerce' ),
) )
)
'options' => $currency_code_options
),

array(
Expand Down
86 changes: 69 additions & 17 deletions woocommerce-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ function woocommerce_locate_template( $template_name, $template_path = '', $defa


/**
* Get Currency.
* Get Base Currency Code.
*
* @access public
* @return string
Expand All @@ -651,6 +651,49 @@ function get_woocommerce_currency() {
}


/**
* Get full list of currency codes.
*
* @access public
* @return void
*/
function get_woocommerce_currencies() {
return array_unique(
apply_filters( 'woocommerce_currencies',
array(
'AUD' => __( 'Australian Dollars', 'woocommerce' ),
'BRL' => __( 'Brazilian Real', 'woocommerce' ),
'CAD' => __( 'Canadian Dollars', 'woocommerce' ),
'RMB' => __( 'Chinese Yuan', 'woocommerce' ),
'CZK' => __( 'Czech Koruna', 'woocommerce' ),
'DKK' => __( 'Danish Krone', 'woocommerce' ),
'EUR' => __( 'Euros', 'woocommerce' ),
'HKD' => __( 'Hong Kong Dollar', 'woocommerce' ),
'HUF' => __( 'Hungarian Forint', 'woocommerce' ),
'IDR' => __( 'Indonesia Rupiah', 'woocommerce' ),
'ILS' => __( 'Israeli Shekel', 'woocommerce' ),
'JPY' => __( 'Japanese Yen', 'woocommerce' ),
'MYR' => __( 'Malaysian Ringgits', 'woocommerce' ),
'MXN' => __( 'Mexican Peso', 'woocommerce' ),
'NOK' => __( 'Norwegian Krone', 'woocommerce' ),
'NZD' => __( 'New Zealand Dollar', 'woocommerce' ),
'PHP' => __( 'Philippine Pesos', 'woocommerce' ),
'PLN' => __( 'Polish Zloty', 'woocommerce' ),
'GBP' => __( 'Pounds Sterling', 'woocommerce' ),
'RON' => __( 'Romanian Leu', 'woocommerce' ),
'SGD' => __( 'Singapore Dollar', 'woocommerce' ),
'ZAR' => __( 'South African rand', 'woocommerce' ),
'SEK' => __( 'Swedish Krona', 'woocommerce' ),
'CHF' => __( 'Swiss Franc', 'woocommerce' ),
'TWD' => __( 'Taiwan New Dollars', 'woocommerce' ),
'THB' => __( 'Thai Baht', 'woocommerce' ),
'TRY' => __( 'Turkish Lira', 'woocommerce' ),
'USD' => __( 'US Dollars', 'woocommerce' ),
)
)
);
}

/**
* Get Currency symbol.
*
Expand All @@ -659,21 +702,30 @@ function get_woocommerce_currency() {
* @return string
*/
function get_woocommerce_currency_symbol( $currency = '' ) {
if ( ! $currency ) $currency = get_woocommerce_currency();
$currency_symbol = '';
switch ( $currency ) :
case 'BRL' : $currency_symbol = 'R$'; break;
case 'AUD' : $currency_symbol = '$'; break;
case 'CAD' : $currency_symbol = '$'; break;
case 'MXN' : $currency_symbol = '$'; break;
case 'NZD' : $currency_symbol = '$'; break;
case 'HKD' : $currency_symbol = '$'; break;
case 'SGD' : $currency_symbol = '$'; break;
case 'USD' : $currency_symbol = '$'; break;
case 'EUR' : $currency_symbol = '€'; break;
case 'CNY' : $currency_symbol = '¥'; break;
case 'RMB' : $currency_symbol = '¥'; break;
case 'JPY' : $currency_symbol = '¥'; break;
if ( ! $currency )
$currency = get_woocommerce_currency();

switch ( $currency ) {
case 'BRL' :
$currency_symbol = 'R$';
break;
case 'AUD' :
case 'CAD' :
case 'MXN' :
case 'NZD' :
case 'HKD' :
case 'SGD' :
case 'USD' :
$currency_symbol = '$';
break;
case 'EUR' :
$currency_symbol = '€';
break;
case 'CNY' :
case 'RMB' :
case 'JPY' :
$currency_symbol = '¥';
break;
case 'TRY' : $currency_symbol = 'TL'; break;
case 'NOK' : $currency_symbol = 'kr'; break;
case 'ZAR' : $currency_symbol = 'R'; break;
Expand All @@ -692,7 +744,7 @@ function get_woocommerce_currency_symbol( $currency = '' ) {
case 'GBP' : $currency_symbol = '£'; break;
case 'RON' : $currency_symbol = 'lei'; break;
default : $currency_symbol = ''; break;
endswitch;
}

return apply_filters( 'woocommerce_currency_symbol', $currency_symbol, $currency );
}
Expand Down

0 comments on commit 8b5c946

Please sign in to comment.