FOX - Currency Switcher Professional for WooCommerce

How to get GEO IP data about the user on the site

Use the next WooCommerce code:

$pd = WC_Geolocation::geolocate_ip();

You can then do: print_r($pd) and see all info which are provided by WooCommerce GEO IP functionality

Or you can simply get country code by: (GEO IP should be enabled in WOOCS)


For example:

$pd = WC_Geolocation::geolocate_ip();
global $WOOCS;
if (isset($pd['country']) AND ! empty($pd['country'])) {
    //do smth here if user is from Spain, for example change currency to EUR
    if ('ES' == $pd['country']) {

Use Alpha-2 code for countries:

Read also: