Custom Currency
From: https://www.cloudways.com/blog/add-custom-currency-symbol-in-woocommerce/
By default, WooCommerce comes with many currency options. However, if you wish to add another currency (and its symbol), the process is very straightforward.
For the purpose of this tutorial, I will add a dummy currency with the name CLOUDWAYS CURRENCY and will use the symbol, ‘CW$’ for it.
Open the functions.php, located in the theme folder.
Now, add the following lines of code at the end of the file and save the file.
1
2
3
4
5
6
7
8
9
10
11
12
add_filter( 'woocommerce_currencies', 'add_cw_currency' );
function add_cw_currency( $cw_currency ) {
$cw_currency['CLOUDWAYS'] = __( 'CLOUDWAYS CURRECY', 'woocommerce' );
return $cw_currency;
}
add_filter('woocommerce_currency_symbol', 'add_cw_currency_symbol', 10, 2);
function add_cw_currency_symbol( $custom_currency_symbol, $custom_currency ) {
switch( $custom_currency ) {
case 'CLOUDWAYS': $custom_currency_symbol = 'CW$'; break;
}
return $custom_currency_symbol;
}
Now, go to backend of the WordPress website, navigate to the WooCommerce tab and then Settings.
Click the Currency drop down under Currency Options, you will see the newly added custom currency at the end of the dropdown.
Select the newly added currency from here and save the settings.
Code Explanation
The following function adds a custom currency:
1
2
3
4
5
add_filter( 'woocommerce_currencies', 'add_cw_currency' );
function add_cw_currency( $cw_currency ) {
$cw_currency['CLOUDWAYS'] = __( 'CLOUDWAYS CURRECY', 'woocommerce' );
return $cw_currency;
}
Since I created a custom currency, CLOUDWAYS CURRENCY that appears on the backend:
1
2
3
4
5
6
7
add_filter('woocommerce_currency_symbol', 'add_cw_currency_symbol', 10, 2);
function add_cw_currency_symbol( $custom_currency_symbol, $custom_currency ) {
switch( $custom_currency ) {
case 'CLOUDWAYS': $custom_currency_symbol = 'CW$'; break;
}
return $custom_currency_symbol;
}
The above function adds the currency symbol. I have use CW$ as the currency symbol.
Go to the front end, and refresh the page. You will see the newly added custom currency being displayed at product pages.
Conclusion:
In this tutorial, I discussed how to add custom currency and symbol in WooCommerce. The code is pretty simple and involves adding a custom filter to the functions.php. If you need further help with the topic, Do leave a comment below and I will get back to you.