Created
November 18, 2020 13:29
-
-
Save gaelbillon/57cb153477c08492df0853e25ec2b4f3 to your computer and use it in GitHub Desktop.
Get user continent with Woocommerce
This file contains hidden or 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
// 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