Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Created December 12, 2018 06:05
Show Gist options
  • Save xlplugins/ce5b3de5645d576fb264c3d1725fb745 to your computer and use it in GitHub Desktop.
Save xlplugins/ce5b3de5645d576fb264c3d1725fb745 to your computer and use it in GitHub Desktop.
WooCommerce User Countery Name Shortcode
add_shortcode( 'wc_geo_country_name', 'wcct_custom_get_user_geo_country_name' );
function wcct_custom_get_user_geo_country_name() {
$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 ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment