Created
March 27, 2019 20:56
-
-
Save danielmcclure/13ff685b8db26174a257c4b60f99d225 to your computer and use it in GitHub Desktop.
Get Current User Country (Geolocation) & Customise Output with WooCommerce
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
/** | |
* @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