Skip to content

Instantly share code, notes, and snippets.

@akshuvo
Created September 15, 2020 17:54
Show Gist options
  • Save akshuvo/e397b00b56fccfc43ce339d1143a6564 to your computer and use it in GitHub Desktop.
Save akshuvo/e397b00b56fccfc43ce339d1143a6564 to your computer and use it in GitHub Desktop.
<?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