First Name and Last Name are not translated into other languages
-
Hi!
The registration form displays the First Name and Last Name fields in English only, not being translated into other languages, in my case, Brazilian Portuguese.
-
Hello, I got the solution, if anyone needs:
1. Use the codes to create the fields as shown at https://www.cloudways.com/blog/add-woocommerce-registration-form-fields/
2. Add the following code in functions.php to disable the First Name and Last Name fields that were created by the plugin and are not translated:
Add_action ( ‘woocommerce_created_customer’, ‘wooc_save_extra_register_fields’);Oi Antonio,
Can you show to me exactly how to solve this? I’m having the same problem in translating this fields to Portuguese.
I’ve put all the code mentioned in the article at my functions.php but It didn’t work for me.
Thanks
Hi!
I hope it helps you.
The name fields (fist name and last name) only appear in English, so use the code below in the functions.php and these fields will be removed and others inserted and that will be translated:
/ ** ADD FIELDS FIRST NAME AND SURNAME IN THE FORM WOOCOMMERCE REGISTER WITHOUT PLUGIN AND THAT ARE TRANSLATED NORMALLY, SINCE THE PLUGIN WOOCOMMERCE SIMPLE REGISTRATION DOES NOT TRANSLATE NAME AND SURNAME, FIRST NAME AND LAST NAME IS.
THIS CODE IS DIVIDED INTO 4 PARTS – PART 1: ADD THE FIELDS
Fonte: https://www.cloudways.com/blog/add-woocommerce-registration-form-fields/
*
* @return string Register fields HTML.
*/
function wooc_extra_register_fields() {?>
<p class=”form-row form-row-first”>
<label for=”reg_billing_first_name”><?php _e( ‘First name’, ‘woocommerce’ ); ?><span class=”required”>*</span></label>
<input type=”text” class=”input-text” name=”billing_first_name” id=”reg_billing_first_name” value=”<?php if ( ! empty( $_POST[‘billing_first_name’] ) ) esc_attr_e( $_POST[‘billing_first_name’] ); ?>” />
</p>
<p class=”form-row form-row-last”>
<label for=”reg_billing_last_name”><?php _e( ‘Last name’, ‘woocommerce’ ); ?><span class=”required”>*</span></label>
<input type=”text” class=”input-text” name=”billing_last_name” id=”reg_billing_last_name” value=”<?php if ( ! empty( $_POST[‘billing_last_name’] ) ) esc_attr_e( $_POST[‘billing_last_name’] ); ?>” />
</p>
<div class=”clear”></div>
<?php
}
add_action( ‘woocommerce_register_form_start’, ‘wooc_extra_register_fields’ );
/ ** ADD FIELDS FIRST NAME AND SURNAME IN THE FORM WOOCOMMERCE REGISTRATION – PART 2: VALIDATE THE NEW FIELDS.
* Validate the extra register fields.
*
* @param string $username Current username.
* @param string $email Current email.
* @param object $validation_errorsWP_Error object.
*
* @return void
*/
function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
if ( isset( $_POST[‘billing_first_name’] ) && empty( $_POST[‘billing_first_name’] ) ) {
$validation_errors->add( ‘billing_first_name_error’, __( ‘Error: First name is required!’, ‘woocommerce’ ) );
}
if ( isset( $_POST[‘billing_last_name’] ) && empty( $_POST[‘billing_last_name’] ) ) {
$validation_errors->add( ‘billing_last_name_error’, __( ‘Error: Last name is required!.’, ‘woocommerce’ ) );
}
}
add_action( ‘woocommerce_register_post’, ‘wooc_validate_extra_register_fields’, 10, 3 );
/ ** ADD FIELDS FIRST NAME AND SURNAME ON FORM WOOCOMMERCE REGISTER – PART 3: SAVE THESE VALUES ON THE DATA BANK.
* Save the extra register fields.
*
* @paramint $customer_id Current customer ID.
*
* @return void
*/
function wooc_save_extra_register_fields( $customer_id ) {
if ( isset( $_POST[‘billing_first_name’] ) ) {
// WordPress default first name field.
update_user_meta( $customer_id, ‘first_name’, sanitize_text_field( $_POST[‘billing_first_name’] ) );
// WooCommerce billing first name.
update_user_meta( $customer_id, ‘billing_first_name’, sanitize_text_field( $_POST[‘billing_first_name’] ) );
}
if ( isset( $_POST[‘billing_last_name’] ) ) {
// WordPress default last name field.
update_user_meta( $customer_id, ‘last_name’, sanitize_text_field( $_POST[‘billing_last_name’] ) );
// WooCommerce billing last name.
update_user_meta( $customer_id, ‘billing_last_name’, sanitize_text_field( $_POST[‘billing_last_name’] ) );
}
}
add_action( ‘woocommerce_created_customer’, ‘wooc_save_extra_register_fields’ );
/ ** ADD FIELDS FIRST NAME AND SURNAME IN THE FORM WOOCOMMERCE REGISTRATION – PART 4: DISABLE THE FIRST NAME AND LAST NAMES CREATED BY PLUGIN WOOCOMMERCE SIMPLE REGISTRATION, BECAUSE THEY APPEAR IN ENGLISH ONLY, NOT BEING TRANSLATED AND WITH THE 3 CODE PARTS ABOVE THOSE FIELDS ARE CREATED AND TRANSLATED. * /
add_filter( ‘woocommerce_simple_registration_name_fields’, ‘__return_false’ );Antonio,
Muito obrigado mesmo, agora funcionou!Antonio,
Thanks once more!
Can’t believe it goes this long way to translate.Olá, estou com o mesmo problema da tradu??o do “First name e Last Name”
Inseri o código acima, mas n?o deu certo, alguém poderia me passar o código para inserir no function.php do meu tema?O erro aparece na etapa 3 da valida??o e os campos n?o s?o removidos, agrade?o desde já,
Obrigado!
- The topic ‘First Name and Last Name are not translated into other languages’ is closed to new replies.