custom field - Unable to change checkout placeholder text

admin2025-01-07  4

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;
       }   

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

  • https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/ https://stackoverflow.com/questions/46326620/custom-placeholder-for-all-woocommerce-checkout-fields
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;
       }   

Share Improve this question asked May 15, 2019 at 14:51 cassiopeiacassiopeia 101
Add a comment  | 

1 Answer 1

Reset to default 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

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

最新回复(0)