在 Woocommerce 结帐中设置 billing_address_2 标签

3 woocommerce

我正在尝试为 Woocommerce 结帐页面上的 billing_address_2 字段设置/显示标签,但找不到执行此操作的方法。有谁知道解决方案?

下面的代码(在其他领域工作正常)不能完成这项工作。

add_filter( 'woocommerce_checkout_fields' , 'custom_rename_wc_checkout_fields' );

function custom_rename_wc_checkout_fields( $fields ) {

    $fields['billing']['billing_address_2']['label'] = 'Building number';
    return $fields;

}
Run Code Online (Sandbox Code Playgroud)

use*_*138 6

为了将来的读者,用答案更新这个问题。

从 WooCommerce 3.5.1 开始,提交87054ece9a4c05db72e139730ed1764c63fab635将“屏幕阅读器文本”label_class 添加到帐单和送货地址 2 字段中,以便根据问题#21182进行访问。此类将保持标签隐藏,除非它也被更改(例如,将其设为空白,如地址 1 字段)。

以下是我如何更新我的 functions.php 以获取 billing/shipping_address_2 标签(我使用单独的账单/运输过滤器,因为我对其他字段进行了更改,为了简洁起见,我没有包含在代码中)。

// Billing Fields.
add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );
function custom_woocommerce_billing_fields( $fields ) {
    $fields['billing_address_2']['label'] = 'Address 2';
    $fields['billing_address_2']['label_class'] = '';
    
    return $fields;
}

// Shipping Fields.
add_filter( 'woocommerce_shipping_fields', 'custom_woocommerce_shipping_fields' );
function custom_woocommerce_shipping_fields( $fields ) {
    $fields['shipping_address_2']['label'] = 'Address 2';
    $fields['shipping_address_2']['label_class'] = '';
    
    return $fields;
}
Run Code Online (Sandbox Code Playgroud)