How to add custom currency symbol to Woocommerce

Woocommerce is one of the best online shopping carts we have today. I really love to work with Woocommerce. It’s powerful, easy to extend and very flexible. Woocommerce developers did a great job, kudos guys keep up the good work. Recently I had a chance to work a lot with Woocommerce based online stores. For the fact these days I’m developing another online store with WordPress and Woocommerce. Last month I was developing this online store. The currency is Sri Lankan Rupees (LKR) and default symbol is “රු” (Sinhalese letter that symbolizes the LKR currency). But my client wanted to display currency symbol as “RS”. In this post, I’m going to describe the simple solution I used to resolve this issue. Of course, this is not my finding. This is the standard way to add a custom currency symbol to Woocommerce.

As I mentioned earlier Woocommerce is very flexible. It provides a long list of hooks we can use to extend, modify its capabilities. to add a custom currency symbol woocommerce_currency_symbol filter comes in handyHere is the code snippet.

add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);

function change_existing_currency_symbol( $currency_symbol, $currency ) {
 switch( $currency ) {
 case 'LKR': $currency_symbol = 'Rs '; break;
 }
 return $currency_symbol;
}

It’s a simple function and I think it’s self-explanatory. Leave a comment if you need any clarification. See you from the next post.

 

Photo by Mike Petrucci on Unsplash

Leave a Reply

Your email address will not be published. Required fields are marked *