Created
September 15, 2020 17:54
-
-
Save akshuvo/e397b00b56fccfc43ce339d1143a6564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_user_geo_country(){ | |
$geo = new WC_Geolocation(); // Get WC_Geolocation instance object | |
$user_ip = $geo->get_ip_address(); // Get user IP | |
$user_geo = $geo->geolocate_ip( $user_ip ); // Get geolocated user data. | |
$country = $user_geo['country']; // Get the country code | |
return WC()->countries->countries[ $country ]; // return the country name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment