Do it your self hobby code

Woocommerce: How to change currency symbol programmatically

Woocommerce change currency programmatically

In this tutorial, we will discuss two ways of changing currency symbol by editing the plugins or by code snippet. Either one should work.

Editing Woocommerce plugin php file:

The file that holds the code is:

File: wc-core-functions.php
Location: /[your-theme-folder]/wp-content/plugins/woocommerce/includes

On line 520, you will see this:

$symbols = apply_filters(
    'woocommerce_currency_symbols',
        array(
            'AED' => 'د.إ',
...

In this example, we will change the AED arabic currency symbol to AED.

$symbols         = apply_filters(
    'woocommerce_currency_symbols',
        array(
            'AED' => 'AED',

That’s it! You are done.

Woocommerce: Change currency programmatically using code snippet

If you don’t want to edit the woocommerce plugins, you can use code snippet plugins and add this code below:

add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
     switch( $currency ) {
          case 'AED': $currency_symbol = 'AED'; break;
     }
     return $currency_symbol;
}

The advantage of this is that when you update your woocommerce plugin, your changes on currency symbol will still be there.

I hope this helps

Leave a Comment

Your email address will not be published.