【问题标题】:Get the geo located Country and State in Woocommerce 3在 Woocommerce 3 中获取地理位置的国家和地区
【发布时间】:2018-08-13 10:28:31
【问题描述】:

我正在制作一个插件来显示估计的运输/交货时间,具体取决于访问者的 IP 地址。为此,我使用WC_Geolocation,但使用它我只能获得访客国家代码,如US CA 等,如果县是美国,我如何获得访客州名称。

 $geoData   = WC_Geolocation::geolocate_ip();
 $country   = $geoData['country'];
 echo $country;

将输出国家代码。如何获取州名?

【问题讨论】:

    标签: php wordpress woocommerce geolocation geoip


    【解决方案1】:

    要获得地理定位状态

    // 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'] : '';
       
    

    【讨论】:

    • 如何找到包含 $user_geodata 的数组键,如 country state
    • 如果你使用print_r($user_geodata)var_dump($user_geodata) 你会看到你得到一个country + state 的数组…
    • 谢谢你拯救我的一天
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-30
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2016-01-01
    相关资源
    最近更新 更多