Q:

Issue in Changing WooCommerce Currency Symbol

I wrote a code to change WooCommerce currency symbol based on the Country selection from the Checkout page. Below is the code:
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);

function change_existing_currency_symbol( $currency_symbol, $currency ) {
    global $post, $woocommerce;
    $my_country = WC()->customer->get_shipping_country();
    /*echo $my_country;
    echo "<br>";
    echo $country;*/
     switch( $my_country ) {
          case 'GB': $currency_symbol = '£'; 
          break;

          case 'NZ': $currency_symbol = '$'; 
          break;

          case 'IE': $currency_symbol = '€'; 
          break;

          default:
                    $currency_symbol = '$'; 

     }
     return $currency_symbol;
}

The code is working fine and when Country is select from the Checkout page, the Symbol appeared well. However, we see that we can't access the admin section as it says:
This page isn’t working
www.XXXXXX-XX.com is currently unable to handle this request.
HTTP ERROR 500
When I removed the code: $my_country = WC()->customer->get_shipping_country(); , the admin panel opens but Symbol did not appear. 
Seeking your help.

A:

Use a conditional check so that it only runs the code on the checkout page.
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);

function change_existing_currency_symbol( $currency_symbol, $currency ) {
    if ( is_checkout() ) {
        $my_country = WC()->customer->get_shipping_country();

        switch( $my_country ) {
            case 'GB': 
                $currency_symbol = '£'; 
            break;

            case 'NZ': 
                $currency_symbol = '$'; 
            break;

            case 'IE': 
                $currency_symbol = '€'; 
            break;

            default:
                $currency_symbol = '$'; 

        }
    }

    return $currency_symbol;
}

