Php 在WooCommerce结帐页面上获取实时客户发货位置

Php 在WooCommerce结帐页面上获取实时客户发货位置,php,wordpress,woocommerce,hook-woocommerce,shipping-method,Php,Wordpress,Woocommerce,Hook Woocommerce,Shipping Method,我正试图在结帐页面上,在WooCommerce中的发货价格下,将预计交货时间添加到订单中 我已经想出了如何做到这一点,例如: add_action( 'woocommerce_after_shipping_rate', 'blm_action_after_shipping_rate', 20, 2 ); function blm_action_after_shipping_rate ( $method, $index ) { if( is_cart() ) { retu

我正试图在结帐页面上,在WooCommerce中的发货价格下,将预计交货时间添加到订单中

我已经想出了如何做到这一点,例如:

add_action( 'woocommerce_after_shipping_rate', 'blm_action_after_shipping_rate', 20, 2 );

function blm_action_after_shipping_rate ( $method, $index ) {
    if( is_cart() ) {
        return; // Exit on cart page
    }

    // Use $method->method_id in here to check delivery option

}

现在,为了能够估计天数(不幸的是,shipping API没有返回此数据),我需要在这里找到装运国家和装运州/省-有办法做到这一点吗?

运费是根据客户装运地点计算的

因此,您询问了客户发货国家,并声明您可以使用以下专用方法从
WC\u customer
对象获取:

add_action( 'woocommerce_after_shipping_rate', 'blm_action_after_shipping_rate', 20, 2 );
function blm_action_after_shipping_rate ( $method, $index ) {
    if( is_cart() ) {
        return; // Exit on cart page
    }

    $shipping_country = WC()->customer->get_shipping_country();
    $shipping_state   = WC()->customer->get_shipping_state();

    // Testing output
    echo '<br><small>Country code:' . $shipping_country . ' | State code: ' . $shipping_state . '</small>';
}
add_action('woocommerce_后加运费','blm_action后加运费',20,2);
功能blm\U行动\U装运后\U费率($method,$index){
if(is_cart()){
return;//退出购物车页面
}
$shipping_country=WC()->customer->get_shipping_country();
$shipping_state=WC()->customer->get_shipping_state();
//测试输出
echo“
国家代码:”.$shipping_Country.”州代码:“.$shipping_State.”; }
代码进入活动子主题(或活动主题)的function.php文件。测试和工作


如果客户更改了国家/地区和州,则会刷新数据,并在
WC_customer
对象中设置新的国家/地区和州。

是客户装运国家/地区还是装运区国家/地区?将是他们将项目装运到的国家/地区(与计算装运价格的国家/地区相同).所以WC_Customer对象给出了您想要的…然后回答。。。