This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by Dennis 7 months, 1 week ago.

Assigned support staff: Dennis.

Author Posts
March 11, 2019 at 12:22 pm #3310883

andreaT-28

I am trying to: Translate strings on Registration Page. I've set up custom code to let customer choose between two user roles on registration. The code works fine and WPML lets me translate some strings of it but not all.

Link to a page where the issue can be seen: hidden link

I expected to see: Complete translation for options values (artist/customer and "Choose an Option")

Instead, I got: no translation

March 12, 2019 at 6:14 am #3318655

Dennis
Supporter

Languages: English (English )

Timezone: Asia/Manila (GMT+08:00)

Hi,

Welcome to WPML Support forum.

Could you tell me more about the issue? Does the string appears in WPML > String Translation page?

If not, could you please check that the string in your custom code are properly wrapped with GetTxt calls?

You might find this documentation helpful: https://wpml.org/faq/language-setup/

Then, re-scan strings from your themes at WPML > Theme and plugins localization

Please let me know how it goes.

Kind regards,
Dennis

March 12, 2019 at 10:57 am #3321183

andreaT-28

Hi Dennis, thank you for your help. I'll post the code here because I've tried several things but they do not work.

I can't translate "Customer" and "Artist"

/* ADD ROLE SELECT*/

//1. Add a new form element...
add_action( 'woocommerce_register_form', 'myplugin_register_form' );
function myplugin_register_form() {

global $wp_roles;

echo __( '<label for="role">Register as...</label>', 'mydomain' );
echo '<select name="role" class="input">';
echo __( '<option selected>-- Choose an Option --</option>', 'mydomain' );
foreach ( $wp_roles->roles as $key=>$value ) {
   // Exclude default roles such as administrator etc. Add your own
   if ( in_array( $value['name'], [ 'Customer', 'Artist'] )) {
   echo '<option value="'.$key.'">'.$value['name'].'</option>';
   }
echo '</select>';
}

//2. Add validation.
add_filter( 'woocommerce_registration_errors', 'myplugin_registration_errors', 10, 3 );
function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {

if ( empty( $_POST['role'] ) || ! empty( $_POST['role'] ) && trim( $_POST['role'] ) == '' ) {
     $errors->add( 'role_error', __( '<strong>ERROR</strong>: You must select a role.', 'mydomain' ) );
}

return $errors;
}

//3. Finally, save our extra registration user meta.
add_action( 'woocommerce_created_customer', 'myplugin_user_register' );
function myplugin_user_register( $user_id ) {

$user_id = wp_update_user( array( 'ID' => $user_id, 'role' => $_POST['role'] ) );
}
March 13, 2019 at 4:21 am #3329737

Dennis
Supporter

Languages: English (English )

Timezone: Asia/Manila (GMT+08:00)

Hi,

Thank you for your reply.

I would like to request temporary access (/wp-admin and FTP) to your site to take a better look at the issue. You will find the needed fields for this below the comment area when you log in to leave your next reply. Your next reply will be set to private.

Maybe I'll need to replicate your site locally to continue debugging and escalate if necessary. For this I’ll need to temporarily install a plugin called “Duplicator” on your site. This will allow me to create a copy of your site and your content. Once the problem is resolved I will delete the local site. Please confirm if this okay with you.

Our Debugging Procedures
I will be checking various settings in the backend to see if the issue can be resolved. Although I won't be making changes that affect the live site, it is still good practice to BACKUP the site before providing us access.

Privacy and Security Policy
We have strict policies regarding privacy and access to your information. Please see:
https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

Kind regards,
Dennis

March 14, 2019 at 7:05 am #3340809

Dennis
Supporter

Languages: English (English )

Timezone: Asia/Manila (GMT+08:00)

Hi,

Our support policy does not allow us to write custom code, but I can point you in the right direction 🙂

I noticed that 'Choose option..' string appears to be translated. However, for the 'Artist' and 'Customer' strings, I think you need to apply a hook to retrieve the string translation for each role. You can find a list of our available API hooks here: https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

I think the one you're looking for is this hook: https://wpml.org/wpml-hook/wpml_translate_single_string/

If you need further assistance, I would suggest you consider contacting one of our certified partners from this link: https://wpml.org/contractors/

Kind regards,
Dennis