0

I'm trying to customize labels from checkout fields in WooCommerce.

Here my code :

add_filter('woocommerce_checkout_fields', 'custom_override_checkout_labels');

function custom_override_checkout_labels($fields)
{
$fields['billing']['billing_first_name']['label'] = 'Prénom';
$fields['billing']['billing_last_name']['label'] = 'Nom';
$fields['billing']['billing_country']['label'] = 'Pays';
$fields['billing']['billing_address_1']['label'] = 'Adresse';
$fields['billing']['billing_postcode']['label'] = 'Code Postal';
return $fields;
}

It work for billing_first_name, billing_last_name and billing_country. But not for the last two. When I refresh the page my custom label appear 1sec and disappear with the default value which takes his place.

I tried to put a priority like this :

add_filter('woocommerce_checkout_fields', 'custom_override_checkout_labels', 90);

But it does not work even if I put 9999999.

What am I missing?

Best regards.

Hildon
  • 1

1 Answers1

3

From Woo's documentation here: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

"In specific cases you need to use the woocommerce_default_address_fields filter. This filter is applied to all billing and shipping default fields"

How about you try this:

add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields', 10, 1 );

function custom_override_default_address_fields( $address_fields ) {
     $address_fields['address_1']['label'] = 'Adresse';
     $address_fields['postcode']['label'] = 'Code Postal';
     return $address_fields;
}
Tami
  • 686
  • 4
  • 8