Skip to content

Instantly share code, notes, and snippets.

@kittenlane
Created May 3, 2015 22:49
Show Gist options
  • Save kittenlane/09d48c9be015bd2cfcb8 to your computer and use it in GitHub Desktop.
Save kittenlane/09d48c9be015bd2cfcb8 to your computer and use it in GitHub Desktop.
Add currency code as suffix to prices in WooCommerce
//* http://www.codemyownroad.com/add-currency-code-suffix-prices-woocommerce/
// Location: add to functions.php
// Output: displays $0.00 AUD on all pages
function addPriceSuffix($format, $currency_pos) {
switch ( $currency_pos ) {
case 'left' :
$currency = get_woocommerce_currency();
$format = '%1$s%2$s ' . $currency;
break;
}
return $format;
}
add_action('woocommerce_price_format', 'addPriceSuffix', 1, 2);
//* http://www.codemyownroad.com/add-currency-code-suffix-prices-woocommerce/
// Location: add to functions.php
// Output: displays $0.00 AUD on cart and checkout pages ONLY
function addPriceSuffix($format, $currency_pos) {
switch ( $currency_pos ) {
case 'left' :
$currency = get_woocommerce_currency();
$format = '%1$s%2$s ' . $currency;
break;
}
return $format;
}
function addPriceSuffixAction() {
add_action('woocommerce_price_format', 'addPriceSuffix', 1, 2);
}
add_action('woocommerce_before_cart', 'addPriceSuffixAction');
add_action('woocommerce_review_order_before_order_total', 'addPriceSuffixAction');
//* http://docs.woothemes.com/document/change-a-currency-symbol/
// Location: add to functions.php
// Output: adds AUD in front of $
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'AUD': $currency_symbol = 'AUD$'; break;
}
return $currency_symbol;
}
@myabos
Copy link

myabos commented Mar 28, 2023

@kittenlane: Works great for one currency, thank you! However, when using multiple currencies, WooCommerce shows always the same currency code on the orders tab.

Could you please advise on how to adjust the code from [add_currency_code_suffix.php] to set a specific currency code for every currency? (e.g. when you have USD, AUD and CAD as currencies, it should display USD for USD, AUD for AUD and CAD for CAD).

I appreciate your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment