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;
}
Add a Custom Currency or Symbol
You can add a custom WooCommerce currency or add a custom WooCommerce symbol using the code snippets
below :
* 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 :
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;
}
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.
Joe is an experienced full-stack web developer with a decade of industry experience in the LAMP & MERN stacks, WordPress, WooCommerce, and JavaScript – (diverse portfolio). He has a passion for creating elegant and user-friendly solutions and thrives in collaborative environments. In his spare time, he enjoys exploring new tech trends, tinkering with new tools, and contributing to open-source projects. You can hire me here for your next project.
Similar Articles
- How to use do_shortcode in WordPress (PHP)
- How Get Product ID on Checkout Page Or Order Page In WooCommerce
- How to Hide Any Tab My Account Page WooCommerce
- How to Get Order Details After Checkout In WooCommerce
- How to Clear Cart on Logout In WooCommerce
- WooCommerce Checkout Optimization Quick Guide
- How to Set Up WooCommerce Storefront Shipping Quick Guide
- How to Get Payment Methods in WooCommerce » Code Example
- How to Add Custom Shipping Method in WooCommerce
- How to Hide Price When Out of Stock In WooCommerce
- How to Check if User is Logged In WordPress
- How to Get Checkout URL In WooCommerce
- How to Hide Shipping Methods for Certain Conditions
- How to Hide Prices From Google In WooCommerce
- How to Change Checkout Endpoints WooCommerce
- WooCommerce Mobile Checkout Optimization Quick Guide
- How to Simplify Checkout Free Items Storefront Theme