Search code examples
wordpresswoocommercehook-woocommerce

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;
}

Solution

  • 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 ;
    }