I am using the woocommerce_checkout_fields
filter to edit the value of a woocommerce field label. It works fine on the checkout page (as you would expect), but I can't understand why it doesn't work on the account page. I thought the fields were still taken from the same place? More specifically, I'm talking about the address field on the edit address endpoint on the woocommerce account page?
My code to try:
function custom_woocommerce_fields( $fields ) { // Billing Fields $fields['billing']['billing_first_name']['label'] = 'First name'; $fields['billing']['billing_last_name']['label'] = 'Last name'; $fields['billing']['billing_company']['label'] = 'Company name'; $fields['billing']['billing_address_1']['label'] = 'Street address'; $fields['billing']['billing_address_2']['label'] = 'Apartment, unit, etc.'; $fields['billing']['billing_city']['label'] = 'City'; $fields['billing']['billing_country']['label'] = 'Country'; $fields['billing']['billing_state']['label'] = 'County/State'; $fields['billing']['billing_postcode']['label'] = 'Postcode'; $fields['billing']['billing_email']['label'] = 'Email'; $fields['billing']['billing_phone']['label'] = 'Phone'; // Shipping Fields $fields['shipping']['shipping_first_name']['label'] = 'First name'; $fields['shipping']['shipping_last_name']['label'] = 'Last name'; $fields['shipping']['shipping_company']['label'] = 'Company name'; $fields['shipping']['shipping_address_1']['label'] = 'Street address'; $fields['shipping']['shipping_address_2']['label'] = 'Apartment, unit, etc.'; $fields['shipping']['shipping_city']['label'] = 'City'; $fields['shipping']['shipping_country']['label'] = 'Country'; $fields['shipping']['shipping_state']['label'] = 'County/State'; $fields['shipping']['shipping_postcode']['label'] = 'Postcode'; $fields['shipping']['shipping_email']['label'] = 'Email'; $fields['shipping']['shipping_phone']['label'] = 'Phone'; // Account Fields $fields['account']['account_username']['label'] = 'Username or email'; $fields['account']['account_password']['label'] = 'Password'; // Order Fields $fields['order']['order_comments']['label'] = 'Order notes'; return $fields; } add_filter( 'woocommerce_checkout_fields' , 'custom_woocommerce_fields' );
The fields in My Account >Addresses are not customized (editing billing or shipping addresses).
The following will affect the My Account "Address" section fields and checkout fields, allowing customization of billing and shipping fields on the relevant My Account section.
1) For My Account and the address field on checkout (Billing and Shipping) :
In some cases you need to use this filter on the address field and it will be applied to all Billing and shipping default fields :
You can use the WooCommerce conditional tags is_account_page() and is_checkout() to target the My Account page or the Checkout page...
2) For the Billing fields on My Account, edit address and checkout:
3) For the Shipping field on My Account, Edit Address and Checkout
4) All (other) fields are only used during checkout:
5) Additionally, depending on the selected country, you should need to use filters:
woocommerce_country_locale_field_selectors
woocommerce_get_country_locale_default
These are located in the
WC_Country
class.The code is located in the functions.php file of the active child theme (or active theme).
Related official documentation: Customize checkout fields using actions and filters