Skip to content

Instantly share code, notes, and snippets.

@gaelbillon
Created November 18, 2020 13:29
Show Gist options
  • Save gaelbillon/57cb153477c08492df0853e25ec2b4f3 to your computer and use it in GitHub Desktop.
Save gaelbillon/57cb153477c08492df0853e25ec2b4f3 to your computer and use it in GitHub Desktop.
Get user continent with Woocommerce
// Need enable geolocation in Woocomerce settings
// Check if user is in Europe
function get_user_geo_continent () {
$location = WC_Geolocation::geolocate_ip();
$country = $location['country']; // Get the country code
$WC_Countries = new WC_Countries(); // Get WC_Countries instance object
$continent = $WC_Countries->get_continent_code_for_country( $country ); // Get continent
return $continent;
}
// Do something only for users in Europe
if ( get_user_geo_continent() !== 'EU' ) { return; };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment