访问woocommerce_cart_shipping_method_full_label过滤器上的国家/地区

问题描述 投票:0回答:2

使用下面的代码,我可以在WooCommerce购物车和结帐页面上更改特定运输方式的完整标签的显示:

add_filter( 'woocommerce_cart_shipping_method_full_label', 'custom_shipping_labels', 10000, 2 );

function custom_shipping_labels($label, $method){   
    $shpmethod = $label;

    if(strpos($shpmethod, 'Express Shipping') !== false){
        $shpmethod = str_replace('Express Shipping',' test express lbl',$shpmethod);
    }
    elseif(strpos($shpmethod, 'Free Standard Shipping') !== false){
        $shpmethod = str_replace('Free Standard Shipping',' test free lbl',$shpmethod);
    }
    return $shpmethod;       
}

现在,我需要访问挂钩在woocommerce_cart_shipping_method_full_label过滤器挂钩中的自定义功能内的客户选择的县。

是否有可能通过该挂钩功能让客户选择国家/地区?

php wordpress woocommerce country shipping-method
2个回答
0
投票

0
投票

[出于测试目的,此处带有以下代码,显示所选的[[(或客户)开票国家

代码,并带有每种运输方式的完整标签:

WC()->checkout->get_value('shipping_country')现在在您的代码中,您可以使用WC()->customer->get_shipping_country() 定位每个目标定义的运输方法标签字符串,它更轻便,更有效。因此您的代码将是:
WC()->customer->get_shipping_country()

代码进入您的活动子主题(活动主题)的functions.php文件中。经过测试和工作。

现在您可以根据需要使用所选的运送国家/地区。
© www.soinside.com 2019 - 2024. All rights reserved.