Search code examples
phpwordpresswoocommercecurrency

Removing currency symbol, except on Woocommerce cart and checkout pages


I want to remove the currency symbol from my webshop, except on the shopping-cart page and the checkout.

So I do NOT want a currency symbol on:

  • category pages
  • product pages
  • home page
  • landing pages
  • blogs

But I DO want the currency symbol on:

  • shopping cart
  • checkout pages
  • confirmation e-mail

I have been given this code:

function avia_remove_wc_currency_symbol( $currency_symbol, $currency ) {
    if ( !is_cart() || !is_checkout()){
        $currency_symbol = '';
        return $currency_symbol;
    }
}
add_filter('woocommerce_currency_symbol', 'avia_remove_wc_currency_symbol', 10, 2);

Which removes the currency symbol from all pages. It doesn't make it reappear on the shopping cart or checkout pages.


Solution

  • Try this:

    <?php
        function avia_remove_wc_currency_symbol( $currency_symbol, $currency ) 
        {
            $currency_symbol = '';
            if ( is_cart() || is_checkout()) 
                $currency_symbol = '$';
            return $currency_symbol;
        } 
        add_filter('woocommerce_currency_symbol', 'avia_remove_wc_currency_symbol', 10, 2);
    
    ?>