Created
December 12, 2018 06:05
-
-
Save xlplugins/ce5b3de5645d576fb264c3d1725fb745 to your computer and use it in GitHub Desktop.
WooCommerce User Countery Name Shortcode
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
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