Understanding WooCommerce Build-In Geolocation/ Geo_IP classes

This is how I used WooCommerce to get the country code on a recent project, using the geolocate_ip method of the WC_Geolocation class.

$country = 'US';

if (class_exists('WC_Geolocation')) {
    $location = WC_Geolocation::geolocate_ip('', true, false);

    if (isset($location['country'])) {
        $country = $location['country'];
    }
}

switch ($country) {
    case 'AU':
        break;
    case 'US':
        break:
}