pierrebalian of Rocket55 Web Team
6/19/2017 - 4:07 PM

function to return woocommerce geolocation

function to return woocommerce geolocation

/**
 * wcj_get_user_location.
 *
 * @version 2.5.0
 */
function wcj_get_user_location()
{
    $country = '';
    if (isset($_GET['country']) && '' != $_GET['country'] && wcj_is_user_role('administrator')) {
        $country = $_GET['country'];
    } else {
        // Get the country by IP
        $location = WC_Geolocation::geolocate_ip();
        // Base fallback
        if (empty($location['country'])) {
            $location = wc_format_country_state_string(apply_filters('woocommerce_customer_default_location', get_option('woocommerce_default_country')));
        }
        $country = isset($location['country']) ? $location['country'] : '';
    }
    return $country;
}