Very often there are cases when you need to replace the currency symbol with text or add some custom values. In Woocommerce, this is done quite easily. I will show you an example of replacing the Ukrainian hryvnia currency symbol. In my case, I needed to get the currency symbol in the following format: грн/sq.m.
So, let’s begin. To replace the currency symbol in Woocommerce, follow these two steps:
- Open the functions.php file in your theme (path to the file on FTP – wp-content/themes/your_theme/functions.php)
- Add the following code at the very end of the file:
1 2 3 4 5 6 7 8 9 10 11 |
function add_my_currency( $currencies ) { $currencies['UAH'] = __( 'Ukrainian Hryvnia', 'woocommerce' ); return $currencies; } function add_my_currency_symbol( $currency_symbol, $currency ) { switch( $currency ) { case 'UAH': $currency_symbol = 'грн/sq.m'; break; } return $currency_symbol; } add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2); |
Note that you can do the same with any other symbol. In general, give it a try. I believe you won’t have any issues. In the end, you will get the following result:
And finally, I want to share one more useful hack related to currency symbols in Woocommerce.
This hack will come in handy if you plan to display different currency symbols depending on the categories. For example, in our work, in some sections the price is displayed as грн/sq.m, and in others as грн/linear.m.
So, to change the currency symbol in a specific section (Woocommerce category), add the following code at the end of the functions.php file in your theme:
1 2 3 4 5 6 7 8 9 10 11 12 |
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2); function change_existing_currency_symbol( $currency_symbol, $currency ) { global $post, $product; if ( has_term( 'Clothing', 'product_cat' ) ) { switch( $currency ) { case 'UAH': $currency_symbol = 'грн/linear.m'; break; } } return $currency_symbol; // <== HERE } |
Where Clothing is the name of your section.
Enjoy using it. I hope our article “Woocommerce currency symbol replacement + different symbols in different categories” was helpful to you.
Leave a Reply