Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing Checkout Fields and issue translation

I'm having problems with WordPress as a multi-site. I have Woocommerce installed on several language sites.

The problem I'm having is, I have a custom language file for Netherlands (NL), which seems to have a translation for 'Apartment' when it comes to checkout. But when it comes to core-fields, the same english text always appears.

Does anyone know what might be wrong with this?

I also noticed that the Postcode field DOESN'T have a placeholder, so it doesn't pickup translation with a checkout field editor. If someone could advise me on how to add this placeholder, that might fix my issue.

Here's the live link in question.

Thanks.

like image 348
Paul M Avatar asked Feb 20 '26 20:02

Paul M


1 Answers

Adding a custom function hooked in woocommerce_default_address_fields filter hook, you can change the 'address_2' placeholder field in to something localisable, this way:

add_filter( 'woocommerce_default_address_fields' , 'overriding_postcode_placeholder_address_fields' );

function overriding_postcode_placeholder_address_fields( $address_fields ) {

     // Set HERE your theme domain (the theme slug used for translations)
     $domain = 'your_theme_domain';

     // For 'address_2' fields
     $address_fields['address_2']['placeholder'] = __('Apartment, suite, unit etc.', $domain);

     // For 'postcode' fields
     $address_fields['postcode']['placeholder'] = __('your placeholder text here', $domain);

     return $address_fields;
} 

I have Add to 'postcode' field, a place holder. So now you have to set your theme domain in this function and also the place holder text for 'postcode' field. depending on what tool or plugin you ara using for translations, this translations will be available within your theme domain.

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

The code is tested and working


Reference: Customizing checkout fields using actions and filters

Advices:

  • On multi-site Wordpress installation, WooCommerce is not recommended, as it's a very sensible plugin that needs more heavy separate server ressources. Also all update process is much more sensible and so on…

  • For WooCommerce multilingual, please have a look to this: Comparing WPML to Free and Paid Alternatives

like image 114
LoicTheAztec Avatar answered Feb 22 '26 15:02

LoicTheAztec