0

I am using woocommerce with storefront and on the checkout the placeholder text for address 1 is "street name" and address 2 is "apartment number".

In my country it should be the opposite, or all in one field.

I have tried changing this with code snippets I found online. They change the placeholder but only for a split second while the page is loading. After that they change back to the default values

add_filter( 'woocommerce_checkout_fields' 'override_billing_checkout_fields', 10, 1 );

   function override_billing_checkout_fields( $fields ) {
       $fields['billing']['billing_address_1']['placeholder'] = 'Address line 1';
       $fields['billing']['billing_address_2']['placeholder'] = 'Address line 2';

       $fields['Shipping']['shipping_address_1']['placeholder'] = 'Address line 1';
       $fields['Shipping']['shipping_address_2']['placeholder'] = 'Address line 2'; 
       return $fields;
       }


   add_filter( 'woocommerce_default_address_fields', 'uwc_new_address_one_placeholder', 1 );

   function uwc_new_address_one_placeholder( $fields ) {
       $address_fields['address_1']['placeholder'] = 'Address line 1';
       $address_fields['address_2']['placeholder'] = 'Address line 2';
       return $address_fields;
       }   

1 Answer 1

0

I needed to change the default fields, but there was a small mistake in my code. The correct code was:

add_filter( 'woocommerce_default_address_fields', 'uwc_new_address_one_placeholder', 1 );

   function uwc_new_address_one_placeholder( $address_fields) {
       $address_fields['address_1']['placeholder'] = 'Address line 1';
       $address_fields['address_2']['placeholder'] = 'Address line 2';
       return $address_fields;
       }   

Notice the change to $address_fields on line 3

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.