在 Woocommerce 3 中获取地理定位的国家和州
Get the geo located Country and State in Woocommerce 3
我正在制作一个插件来显示估计 shipping/delivery 时间取决于访问者的 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'] : '';
我正在制作一个插件来显示估计 shipping/delivery 时间取决于访问者的 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'] : '';