YaSsine Tagmat Rakini
YaSsine Tagmat Rakini

Reputation: 35

How can I change currency symbol in woocommerce

I'm a beginner with WooCommerce and I have a question.
How can I change an existing currency symbol throughout the website.

I have tried this code but is not working :

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

Upvotes: 1

Views: 7434

Answers (3)

Mohammed Muzammil
Mohammed Muzammil

Reputation: 704

You just need to add few lines of code in your theme's functions.php file

/**
 * Change a currency symbol
 */
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);

function change_existing_currency_symbol( $currency_symbol, $currency ) {
     switch( $currency ) {
          case 'د.م.': $currency_symbol = 'MAD'; break;
     }
     return $currency_symbol;
}

Upvotes: 0

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

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

Upvotes: 1

Reigel Gallarde
Reigel Gallarde

Reputation: 65274

Why bother with code? You can do it in the settings page.

WooCommerce > Settings > General (tab) > Currency Options

enter image description here

update:

add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {

    return ( $currency == 'MAD' ) ? $currency : $currency_symbol ;
}

Upvotes: 1

Related Questions