我正在制作一个插件来显示估计的运输/交货时间取决于访问者的 IP 地址。要做到这一点,我正在使用,WC_Geolocation
但使用它我只能获得访客国家代码US
CA
等,如果县是美国,我如何获得访客州名称。
$geoData = WC_Geolocation::geolocate_ip();
$country = $geoData['country'];
echo $country;
将输出国家代码。如何获得州名?
要获取地理定位状态:
// 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 = isset($user_geodata['state']) ? $user_geodata['state'] : '';
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句