中更改结帐帐单字段占位符

中更改结帐帐单字段占位符

本文介绍了在 Woocommerce 中更改结帐帐单字段占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码更改结帐页面中帐单地址 2"的字段占位符:

I'm trying to change the fields placeholder of "billing address 2" in the checkout page, using the following code:

add_filter( 'woocommerce_checkout_fields' ,  'custom_override_checkout_fields',9999 );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
   $fields['billing']['billing_address_2']['placeholder']="dssfsd";
   return $fields;
}

它只改变片刻,然后返回到它的默认值.请参阅以下视频(10 秒):https://www.youtube.com/watch?v=-qOZ67gFQ98

it changes only for a moment than return back to it's defualt value.see the following video (10s):https://www.youtube.com/watch?v=-qOZ67gFQ98

推荐答案

获得它的唯一方法是使用 woocommerce_default_address_fields,但它会更改地址 2 结帐字段的计费和运输占位符:

The only way to get this is using woocommerce_default_address_fields, but it will change both billing and shipping placeholder for Address 2 checkout fields:

add_filter( 'woocommerce_default_address_fields', 'custom_override_default_checkout_fields', 10, 1 );
function custom_override_default_checkout_fields( $address_fields ) {
    $address_fields['address_2']['placeholder'] = __( 'dssfsd', 'woocommerce' );

    return $address_fields;
}

代码位于活动子主题(或活动主题)的 function.php 文件中.

经过测试并有效

现在,如果您要更改地址 2 帐单 字段占位符,您将:

Now if you want to change only the Address 2 billing field placeholder you will:

  1. 取消设置默认地址 2 字段占位符(用于运输和计费字段)
  2. 仅自定义帐单地址 2 字段占位符
  3. 放回送货地址 2 字段占位符

这是两个挂钩函数的代码:

Here is the code on two hooked function:

add_filter( 'woocommerce_default_address_fields', 'custom_override_default_checkout_fields', 10, 1 );
function custom_override_default_checkout_fields( $address_fields ) {
    // Remove labels for "address 2" shipping fields
    unset($address_fields['address_2']['placeholder']);

    return $address_fields;
}

add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields', 90, 1 );
function custom_override_checkout_fields( $fields ) {
    // Add custom billing "address 2" label
    $fields['billing']['billing_address_2']['placeholder'] = __( 'dssfsd', 'woocommerce' );
    // Put back shipping "address 2" label
    $fields['shipping']['shipping_address_2']['placeholder'] = __( 'Apartment, suite, unit etc. (optional)', 'woocommerce' );

    return $fields;
}

代码位于活动子主题(或活动主题)的 function.php 文件中.

经过测试并有效

这篇关于在 Woocommerce 中更改结帐帐单字段占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 05:02