Skip to content

Instantly share code, notes, and snippets.

@danielmcclure
Created March 27, 2019 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielmcclure/13ff685b8db26174a257c4b60f99d225 to your computer and use it in GitHub Desktop.
Save danielmcclure/13ff685b8db26174a257c4b60f99d225 to your computer and use it in GitHub Desktop.
Get Current User Country (Geolocation) & Customise Output with WooCommerce
/**
* @snippet Get Current User Country (Geolocation) - WooCommerce
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
* @sourcecode https://businessbloomer.com/?p=72811
* @author Rodolfo Melogli
* @compatible Woo 3.5.3
* @donate $9 https://businessbloomer.com/bloomer-armada/
*/
function bbloomer_use_geolocated_user_country(){
// Geolocation must be enabled @ Woo Settings
$location = WC_Geolocation::geolocate_ip();
$country = $location['country'];
// Lets use the country to e.g. echo greetings
switch ($country) {
case "IE":
$hello = "Howya!";
break;
case "IN":
$hello = "Namaste!";
break;
default:
$hello = "Hello!";
}
echo $hello;
}
add_action( '_______', 'bbloomer_use_geolocated_user_country' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment