我正在制作一个插件,以显示估计的运输/交付时间取决于访问者的IP地址。为此,我使用的是WC_Geolocation
,但是使用此方法,我只能获得US
CA
之类的访问者国家/地区代码,等等,如果县是美国,如何获取访问者的州名。
$geoData = WC_Geolocation::geolocate_ip();
$country = $geoData['country'];
echo $country;
将输出国家代码。如何获得州名?
答案 0 :(得分:2)
要获取地理位置:
// Get an instance of the WC_Geolocation object class
$geo_instance = new WC_Geolocation();
// Get geolocated user geo data.
$user_geodata = $geo_instance->geolocate_ip();
// Get current user GeoIP Country
$country = $user_geodata['country'];
// Get current user GeoIP State
$state = $user_geodata['state'];