change billing and shipping address 1 and 2 field placeholders [closed]
IT Nursery
May 28, 2022
0
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?
1 Answer 1
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.