How to Customize WooCommerce Currency [Code Snippets]

woocommerce currency code

When you are customizing WooCommerce, you may want to change the WooCommerce currency code to reflect your custom options. I helps to know where the WooCommerce currency code is located and the various ways you can customize the WooCommerce currency to suit your needs.

In this post, I want to show you all the details about WooCommerce currency code and how you can go about customizing the WooCommerce currency code using specific filters.

WooCommerce Currency Code

WooCommerce Currency symbols and names follow the Unicode CLDR recommendation  and the most important function that controls the WooCommerce currency is  :

$array = get_woocommerce_currencies();

This method is located in the following path of the WooCommerce plugin directory :

woocommerce/includes/wc-core-functions.php

You can click on this link to access the  WooCommerce currency code method that controls the functionality of all the currency codes.

WooCommerce Currency Code Custom Code Snippets

You can change the currency symbol using the code snippet below :

[php]

add_filter( ‘woocommerce_currency_symbol’, ‘njengah_change_currency_symbols’, 10, 2 );

function njengah_change_currency_symbols( $currency_symbols, $currency ) {

if ( ‘USD’ === $currency ) {
return ‘USD’;
}

if ( ‘EUR’ === $currency ) {
return ‘Euro’;
}

if ( ‘AED’ === $currency ) {
return ‘AED’;
}

return $currency_symbols;
}

[/php]

Add a Custom Currency or Symbol

You can add a custom WooCommerce currency or add a custom WooCommerce symbol using the code snippets
below :

[php] /**
* Custom currency and currency symbol
*/
add_filter( ‘woocommerce_currencies’, ‘njengah_add_my_currency’ );

function njengah_add_my_currency( $currencies ) {

$currencies[‘ABC’] = __( ‘Currency name’, ‘woocommerce’ );
return $currencies;

}

add_filter(‘woocommerce_currency_symbol’, ‘njengah_add_my_currency_symbol’, 10, 2);

function njengah_add_my_currency_symbol( $currency_symbol, $currency ) {

switch( $currency ) {
case ‘ABC’: $currency_symbol = ‘$’; break;
}
return $currency_symbol;

}

[/php]

You can view this WooCommerce code snippet from gist.

Add Currency Code As Suffix To Prices

You can add WooCommerce currency symbol as a price suffix using the code snippet
below :

[php]

add_action(‘woocommerce_price_format’, ‘njengah_add_price_suffix’, 1, 2);

function njengah_add_price_suffix($format, $currency_position) {

switch ( $currency_position ) {
case ‘left’ :
$currency = get_woocommerce_currency();
$format = ‘%1$s%2$s ’ . $currency;
break;
}

return $format;
}

[/php]

Conclusion

In this post we have shared the different ways you can change the WooCommerce currency using code snippets and the location of the WooCommerce code for the currency to help you understand how WooCommerce currency works as a WooCommerce developer.

Similar Articles