Woocommerce 在电子商务签出中设置帐单地址标签

Woocommerce 在电子商务签出中设置帐单地址标签,woocommerce,Woocommerce,我正在尝试在Woocommerce结帐页面上设置/显示billing_address_2字段的标签,但找不到执行此操作的方法。有人知道解决办法吗 下面的代码(在其他字段中可以正常工作)不起作用 add_filter( 'woocommerce_checkout_fields' , 'custom_rename_wc_checkout_fields' ); function custom_rename_wc_checkout_fields( $fields ) { $fields['b

我正在尝试在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;

}

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

从WooCommerce 3.5.1开始,commit将“屏幕阅读器文本”标签_类添加到计费和发货地址2字段中,以便根据问题进行访问。此类将隐藏标签,除非它也被更改(例如,将其设置为空,如地址1字段)

下面是我如何更新我的functions.php以恢复billing/shipping_address_2标签(为了简洁起见,我使用了单独的billing/shipping过滤器,因为我对代码中未包含的其他字段进行了更改)


这应该在结帐页面上起作用。
// 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;
}