WooCommerce is awesome plugin, you can use it to make e-commerce on your website. But sometime we need add some country, state, or currency into this plugin. We can edit manually with edit some file in this plugin but if we updated the plugin the file will be replaced, and all customization what we have done is gone.
Now, i will be show you how to add currency and country with filter in this plugin. Remember that everything is filtered. Woo is using the woocommerce_currency_symbol
filter for filtered the currency and woocommerce_countries
filter for filtered country in woocommerce.php
. To add currencies to that list, you’d use:
function add_my_currency_symbol( $currency_symbol, $currency ) { if($currency == "IDR") { $currency_symbol = 'Rp'; } return $currency_symbol; } add_filter( 'woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2 );
Whenever Woo calls their function, they pass the currency symbol through a filter before returning it. You’re just hooking on to that filter, checking to see if the currency matches your custom value, and returning a custom symbol if so. I used Rupiah here as an example, but substitute whatever it is you need.
To add your currency to the settings page, you’ll hook into the woocommerce_currencies
filter:
function add_my_currency( $currencies ) {
$currencies["IDR"] = 'Rupiah';
return $currencies;
}
add_filter( 'woocommerce_currencies', 'add_my_currency', 10, 1 );
To add country to that list, you’d use:
function add_my_country( $country ) {
$country["NC"] = 'New Country';
return $country;
}
add_filter( 'woocommerce_countries', 'add_my_country', 10, 1 );
To add states to that list, you’d use:
function add_my_states( $states
) {
$states["ID"] = array( 'BA' => __('Bali', 'woocommerce') ,'JB' => __('Jawa Barat', 'woocommerce'));
return $states
;
}
add_filter( 'woocommerce_states
', 'add_my_states
', 10, 1 );
Woo is adding an array of currencies to their options panel. All this does is look at the array, add your custom currency, then return it so the function can operate as normal.
Where to put this code
To use these filters, you’ll have to write a that’s code in your function.php
at your theme file. When you update WooCommerce, so long as they don’t change their filter names, you shouldn’t lose any customizations.
I hope that can help you to make your website more awesome, keep on fire yeah 🙂
That is great !
Do you know how to add state actualy ?
Hi Stan,
try this one
function add_my_states( $states ) {
$states[‘JKT’][“NWST”] = ‘New States’;
return $states;
}
add_filter( ‘woocommerce_states’, ‘add_my_states’, 10, 1 );
.. so to add a country we are ONLY modifying the function.php file and nothing else. The article is great but where to put the code additions is … not clear as you mention several files. I’m trying to add Argentina, can you please elaborate : ) thanks!
hi brian,
thanks for your comment, okay please try this code to put your country
function dd_my_country( $country ) {
$country[“AR”] = ‘Argentina’;
return $country; }
add_filter( ‘woocommerce_countries’, ‘add_my_country’, 10, 1 );
and that’s anywhere…. in function.php
You have three sections of PHP code, I ask where we place those sections, and you respond with 1 section and do not confirm where I place it…
Hi brian,
yeah, you can add that script anywhere in your function.php
All works fine !
Nice…:)
It works great; a really time saver!
Thank you for that.
Your welcome
Hi there thank you very much for your help, i succesfully add a custom currency with this code
function add_my_currency( $currencies ) {
$currencies[“COP”] = ‘Peso Colombiano ($COP)’;
return $currencies;
}
add_filter( ‘woocommerce_currencies’, ‘add_my_currency’, 10, 1 );
now i have a question, how can i add a custom currency symbol like this $COP for woocomerce to display, because it still show me this £ in the shop
Here you are:
add_filter(‘woocommerce_currency_symbol’, ‘add_my_currency_symbol’, 10, 2);
function add_my_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case ‘ABC’: $currency_symbol = ‘Dhs’; break;
}
return $currency_symbol;
}
hi there, thank you very much for your help, i tried with the you gave me, i replace the ABC with COP and Dhs with $COP and i got this
Use of undefined constant ‘add_my_currency_symbol’ – assumed ‘‘add_my_currency_symbol’’ in functions.php on line 25.
what am i doing wrong? please help me!
Hi again…. I’m sorry, the mistake is mine…
This is your code:
############################################################
add_filter( ‘woocommerce_currencies’, ‘add_my_currency’ );
function add_my_currency( $currencies ) {
$currencies[‘COP’] = __( ‘Colombian pesos (COP)’, ‘woocommerce’ );
return $currencies;
}
add_filter(‘woocommerce_currency_symbol’, ‘add_my_currency_symbol’, 10, 2);
function add_my_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case ‘COP’: $currency_symbol = ‘COP’; break;
}
return $currency_symbol;
}
############################################################
Thank you very much, you are Awesome. Fully functional code, thanks for saving me!!! 😀 Thanks!
Thanks a lot Stanislav it is perfect! 🙂
I followed the instruction here, my currency symbol did not appear and when I copied the code and edited it, my site crash.
Don’t worry is a new site.
I need help, I am a Nigerian, based in Abuja, Nigeria’s capital.
My country’s currency symbol is: N
Why my country’s currency name is: Naira
Please, help me fix this,
Hi Eric,
Please try put this code into function.php on your themes
add_filter( ‘woocommerce_currencies’, ‘add_my_currency’ );
function add_my_currency( $currencies ) {
$currencies[‘NGN’] = __( ‘Naira (NGN)’, ‘woocommerce’ );
return $currencies;
}
add_filter(‘woocommerce_currency_symbol’, ‘add_my_currency_symbol’, 10, 2);
function add_my_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case ‘NGN’: $currency_symbol = ‘NGN’; break;
}
return $currency_symbol;
}
Thank you for doing all this just for me, I am grateful,
God Bless.
Having said that, it important I let you know that adding the above code to A DEMO site (for testing purpose): failed.
Theme Functions
(functions.php)
Crash the Demo website before I re-uploaded wordpress again and added it to:
woocommerce’s editor > woocommerce/woocommerce-functions.php
And I got the same negative result.
This is what normally shows up:
Parse error: syntax error, unexpected T_STRING in /home/udoka/public_html/wootesting/wp-content/themes/woostore/functions.php on line 40
I strongly believe that I am not doing it the right way,
Sorry to bother you again,
Please can you do a short video for me and post it on youtube on ‘How To Installed The Code’
Sorry again for bothering you.
Thanks in advance for helping out and God bless
Hi Eric,
Sorry for late to response your comment, put that your code into your function theme file, not into your plugin file. you can find the into wp-content/themes/yourtheme/functions.php.
If you still need my help, you can sent me your admin account and ftp account to https://anangpratika.wordpress.com/contact-me-2/, cause i still don’t have some time to make video tutorial.
Cheers,
Hi there i put the code in the functions.php file and im getting the error: Parse error: syntax error, unexpected T_STRING in /home/xxxxx/wp-content/themes/wpflexishoptwo/functions.php on line 11 what should i do, tx in advance
Dont worry about my last comment i manage to solve the problem, it was because i copy the code from one of your comments and it seems it has a lot af blank spaces, so i copied from here http://wcdocs.woothemes.com/snippets/add-a-custom-currency-symbol/ and edited the way you do it, thanks. for the tutorial
i need to add inr currency how to add pls say me.
pls
Hi Tantea,
Sorry to late reply your comment, to adding Indian rupee to your theme, please open your function.php of your theme (wp-content/themes/your-theme/function.php). And copy this code into your function.php
add_filter( ‘woocommerce_currencies’, ‘add_my_currency’ );
function add_my_currency( $currencies ) {
$currencies[‘INR’] = __( ‘Indian Rupee (INR)’, ‘woocommerce’ );
return $currencies;
}
add_filter(‘woocommerce_currency_symbol’, ‘add_my_currency_symbol’, 10, 2);
function add_my_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case ‘INR’: $currency_symbol = ‘INR’; break;
}
return $currency_symbol;
}
I hope that’s can help you. 🙂
buddy its not working for me plzz help
Hi Rahil,
Where did you put that’s code?
my way more easier—Open woocommerce/woocommerce-core-functions.php in wordpress plugin editor.theres a switch function–” function get_woocommerce_currency_symbol( $currency = ” ) ” just change the case condition like–“case ‘EUR’ : $currency_symbol = ‘Rs’; break;”..ha ha ha
Hi abhishek,
If you do with that way, you can’t update your woocommerce plugin. Cause if there is new version of woocommerce and you updating it, your customization will be removed and back it to the original. Am i right?