functions - change billing and shipping address 1 and 2 field placeholders

admin2025-06-03  3

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I'm trying to change the placeholder text for the billing and shipping address 1 and address 2 fields but I can't get it to change at all. This is what I have for billing address 1

// This function sets the address 1 placeholder
add_filter( 'woocommerce_checkout_fields', 'uwc_new_address_one_placeholder' );
function uwc_new_address_one_placeholder($fields){

        $fields['billing']['billing_address_1']['placeholder'] = 'over the hill';

    return $fields;
}

This works for every other field except for address 1 and 2. What am I doing wrong?

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I'm trying to change the placeholder text for the billing and shipping address 1 and address 2 fields but I can't get it to change at all. This is what I have for billing address 1

// This function sets the address 1 placeholder
add_filter( 'woocommerce_checkout_fields', 'uwc_new_address_one_placeholder' );
function uwc_new_address_one_placeholder($fields){

        $fields['billing']['billing_address_1']['placeholder'] = 'over the hill';

    return $fields;
}

This works for every other field except for address 1 and 2. What am I doing wrong?

Share Improve this question asked Feb 20, 2019 at 6:43 John CookJohn Cook 673 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Prior to the address fields being passed through the woocommerce_checkout_fields hook, they are retrieved by WC_Countries::get_address_fields(), and inside that function there is a comment before its filter that reads:

Important note on this filter: Changes to address fields can and will be overridden by the woocommerce_default_address_fields. The locales/default locales apply on top based on country selection. If you want to change things like the required status of an address field, filter woocommerce_default_address_fields instead.

It seems likely to me that the same issue would affect the woocommerce_checkout_fields filter.

So my recommendation would be to use the woocommerce_default_address_fields filter instead:

function uwc_new_address_one_placeholder( $fields ) {
    $fields['address_1']['placeholder'] = 'over the hill';

    return $fields;
}
add_filter( 'woocommerce_default_address_fields', 'uwc_new_address_one_placeholder' );

Note that this filter applies to both shipping and billing addresses, and should not require the shipping_ or billing_ prefixes on the field names.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748886770a314543.html

最新回复(0)