wordpress function breaks wp-admin

I’ve created a function in my custom WooCommerce site. This works great on the frontend, but wp-admin breaks. Wp-admin shows a http-500 error.

This is the function:

// Set currency based on visitor country

function geo_client_currency($client_currency) {
        $country = WC()->customer->get_shipping_country();
           switch ($country) {
            case 'GB': return 'GBP'; break;
            default: return 'EUR'; break;
        }

}
add_filter('wcml_client_currency','geo_client_currency');

I’ve set the wp-debug on true and it will throw this message:

Fatal error: Uncaught Error: Call to a member function get_shipping_country() on null in

So it has to do something with: $country = WC()->customer->get_shipping_country(); but I can’t find it.
Maybe someone can help me with this.

Thanks in advanced.

Read more here: wordpress function breaks wp-admin

Leave a Reply

Your email address will not be published. Required fields are marked *