Special shortcode to show current country only
Question: “Hello team, is there a shortcode just to display the country name?”
Answer: “No, but it is possible to add by the next code example”
add_shortcode('woocs_get_current_country', function($atts) { $pd = array(); $countries = array(); if (class_exists('WC_Geolocation')) { $c = new WC_Countries(); $countries = $c->get_countries(); $pd = WC_Geolocation::geolocate_ip(); } if (!empty($pd) AND!empty($countries)) { return $countries[$pd['country']]; } return 'Country is not defined'; });