Now after posting this article online on how to add a currency and a new symbol in WooCommerce, I got a number of questions asking me how you can actually edit those kind of symbols that are already existing, so I have that question appearing twice on the same article. So let’s dive into how to do that.
So on my cpanel I’m going to go to my file manager and inside here in my root folder, and inside my root folder I’m going to go to wp content, I’ll go to my plugins, and then I’m going to create a new folder which I’ll call techiepress woo currency.
Inside it I’ll create another file, techiepress woo currency.php, and when I edit this, this is what I have. So I have started my php and I’ve started the comments that will allow WordPress to recognize my code as a plugin. The reason I do this is because I want this to change, every time I change my theme I still want the same functionality to go on, so that’s why I don’t put this code inside my functions.php.
So let’s start writing some code. We’re going to use the add filter function in WordPress, and inside here we shall use a WooCommerce filter which is called woocommerce currency symbol, and we’re going to use this again so I’ll copy this, and then write our own function, and our function I’ll prefix it with techiepress then do the same thing, and I’ll give this a priority of 10 so that it kicks off very early in all the stages, and we’ll pass in the two arguments that come with this particular filter.
Now as we write this function, I’ll copy its name from here and add it here, and then close off the function itself, and then I’ll quickly pass in the arguments that we get. So the first argument is actually currency symbol, and then the next one is currency.
So let me var_dump what we have in currency symbol, so that we can see what is actually going on. So I’ll start off with my pre tags, I’ll duplicate that so that I can quickly code, then what I’m going to do is var_dump the currency symbol.
So besides var_dumping the currency symbol I’m also going to var_dump the currency so that we can see what’s going on inside both items. So currency, I’ll save this and then I’ll reload, so we see the currency symbol here and we also see the currency that we’re talking about. So that’s why when we start writing our functions, I’m going to comment this out, I am going to return a currency symbol here, I’m going to look through the array of the currency symbol and I’m going to pick out one particular symbol that I want to change.
So what I’m going to do is use a switch statement here and say switch the currency, and I’m going to look for the case where I’m looking for something particular let’s say USD, and with this I am going to set the currency symbol, I’m going to say its currency symbol should now be called American USD, and then after doing that I’m going to hit the break.
So let’s save this and then reload here, and I’m going to just go to WooCommerce and then go inside the settings, and then I’ll scroll all the way down, and you will see that we have United States where we had, previously we had a dollar we now have a USD.
So if we are looking for the United Arab Emirates dirham like this, we’re going to have to look for the code in the array that adds this currency. I’m going to quickly go to my WooCommerce, but in this case I’m going to go to the WooCommerce github repository, and I’m going to look at how the code is passed in to give us this particular language. So I’m going to go into the includes, I’ll look for the wc core functions, and when I look through it there are a number of files that we are seeing here.
What we are actually looking for is the WooCommerce currencies and you’ll see that the United Arab Emirates dirham is actually called AED, it’s not in the Arabic language, it’s in plain old English letters.
So what I’m going to do is just copy the AED here, and I’m going to paste it here. Now what I want to do is I want my currency it will also be called AED. I’ll remove these comments and then I’ll click save. And once I come back into my admin area and reload, you’ll see that for our United Arab Emirates dirham we have AED instead of the Arabic. Feel free to go to this link find out your country code, and then you can change the currency that you want to change.
That’s it for the article. If you enjoyed it give it a thumbs up, share it with your friends if you find the content helpful. Leave me a comment about what you think about this. Otherwise, peace.