Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
Emails generated by the plugin "Custom User Registration Fields for WooCommerce" that are triggered by an admin action (approve or disapprove the user account) are sent in the admin language instead of the user language. So here the user receives an email in FR even if he registered in NL.

Solution:
There is no simple solution here. You should push the plugin author to join our Go Global program and make his plugin compatible.
https://wpml.org/documentation/support/go-global-program/

Having said that we were able to make it work by modifying the plugin's code. Please follow the instructions in the link below.

Documentation/Workaround:
https://wpml.org/forums/topic/compatibility-issue-between-the-wpml-plugin-and-the-custom-user-registration-fields-for-woocommerce/page/2/#post-14149545

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.

Tagged: 

This topic contains 24 replies, has 2 voices.

Last updated by Nicolas V. 1 year, 5 months ago.

Assisted by: Nicolas V..

Author Posts
July 25, 2023 at 2:28 pm #14097317

mohammedS-28

Hey Nico,

Hope you had a great weekend, I have not received any response from the other side of the registration plugin, I have tried reaching out to them and yet have not received any response. Wanted to update you regarding the same and is it possible to figure out the key if they are unable to assist?

Thanks and regards,

July 26, 2023 at 5:52 pm #14106461

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hi Mohammed,

I hope you had a great one too! I asked my colleagues from second tier support about it. I'll probably get some ideas/answers tomorrow. And if nothing works, I'll escalate your ticket.

Thanks for your patience,
Nico

July 28, 2023 at 12:01 am #14114139

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hello,

I talked about your case with my colleagues and I will need to escalate it to our compatibility team but I need to reproduce the issue on our servers first.

For this, you need to temporarily install a plugin called “Duplicator” on your site. This will allow you to create a copy of your site and your content.
I have activated a private field for you where you can share those files (package + installer).
- You can exclude /wp-uploads from the copy to reduce the size
- Once the package is ready, if the files are too large to upload them to the private field, you can share a link to Google Drive, Dropbox, WeTransfer or any other similar service.

Once the problem is resolved I will delete the local site. Let me know if this is ok with you.
https://wpml.org/faq/provide-supporters-copy-site/

July 29, 2023 at 2:00 pm
July 31, 2023 at 12:49 pm #14127385

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hello,

Thank you for the package. I have escalated your ticket but please on your side keep contacting their support as compatibility is often a two way street where both teams need to collaborate.

I'll come back to you as soon as I have some feedback from our end.

July 31, 2023 at 5:55 pm #14129023

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hi Again,

I found that documentation that you can share with the support team from "Custom User Registration Fields for WooCommerce":
https://wpml.org/documentation/support/sending-emails-with-wpml/
That should help them achieve compatibility.

I also managed to reproduced the issue from scratch on a brand new sandbox site so it's clear that the problem is not related to your configuration but a compatibility issue.

I'll get back to you when I have some feedback from our team.

August 1, 2023 at 11:51 am #14133391

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hello,

We found a solution! Following our documentation here: https://wpml.org/documentation/support/sending-emails-with-wpml/

- Edit the file user-registration-plugin-for-woocommerce/classes/afreg-approved-user-email-class.php (using FTP or Cpanel)
- Line 104 after:

$user_email = stripslashes($customer->user_email);

Add the following code:

//WPML
do_action('wpml_switch_language_for_email', $user_email);

PS: same thing for user-registration-plugin-for-woocommerce/classes/afreg-disapproved-user-email-class.php (line 102 this time) or any other email that is triggered by an admin in the backend and must be switched to the user language.

IMPORTANT: Please note that making changes directly in the plugin's code is not recommended because every time you will update that plugin, your changes will be overwritten.
That's why I would insist on contacting their support to report the issue and ask them to join our Go Global compatibility program. Our developers will be happy to assist them in making their plugin WPML-compatible and getting them added to our compatibility list.
https://wpml.org/documentation/support/go-global-program/

August 1, 2023 at 6:03 pm #14136591

mohammedS-28

Hi Nico,

I hope this message finds you well. I want to express my gratitude for the guidance you provided regarding the WPML compatibility issue I encountered with the User Registration Plugin. I followed the steps you outlined in the documentation, but unfortunately, it didn't resolve the problem.

To give you a brief overview, I added the following code to the afreg-approved-user-email-class.php and afreg-disapproved-user-email-class.php files:

//WPML
do_action('wpml_switch_language_for_email', $user_email);

Despite implementing the suggested changes, the emails triggered by an admin in the backend are still not being switched to the user's preferred language.

As you have access to our WordPress site, I kindly request your assistance in investigating this matter further. It seems that we may need some additional adjustments to ensure proper WPML compatibility for the User Registration Plugin.

I have also attempted to reach out to the plugin's support team, but unfortunately, I have not received a response yet.

If possible, could you please take a closer look at the plugin and help us achieve WPML compatibility? I highly appreciate your expertise and support in resolving this matter.

Thank you once again for your kind help and understanding. Your assistance in making the User Registration Plugin WPML-compatible will be of great value to our multilingual website.

Looking forward to hearing from you and hoping for a positive resolution.

Best regards,

Screenshot 2023-08-01 232947.png
Screenshot 2023-08-01 233049.png
August 1, 2023 at 10:11 pm #14137937

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hello again,

You're right. I retested it on both your production site and the copy you provided and it doesn't work on your production site.
I asked my colleague if he has an idea.

I'll get back to you as soon as possible.

August 2, 2023 at 1:10 pm #14142633

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hello,

Just a quick message to let you know that we're making some progress.

We added the following code in your functions.php file:

/**
 * @see compsupp-6901
 */
add_filter('insert_user_meta', function($meta, $user, $update){
	global $sitepress;
	if ( !$update && $sitepress instanceof SitePress ) {
		$meta['locale'] = $sitepress->get_locale_from_language_code( apply_filters( 'wpml_current_language', 'en' ) );
	}

	return $meta;
}, 10, 3);

This code will change the profile language before updating the usermeta.

I did some tests and now I'm receiving the approved/disapproved emails with mix content. I mean that the header of the email is in NL but the content remains in EN.
I checked in "WPML > String Translation" and all translation are made.
I informed my colleagues about this, I'll get back to you when I have some feedback.

Don't hesitate to run some tests on your side too.

August 2, 2023 at 5:23 pm #14144051

mohammedS-28

Hey Nico, that sounds great! Thank you again for your consistent support and assistance, sure take your time! I will do tests from my side too.

regards,

August 3, 2023 at 12:42 pm #14149545

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hey Mohammed,

I think we fixed the issue!
I will resume the entire ticket here in case another client uses the same plugin:

1. Add the following into your functions.php file

/**
 * @see compsupp-6901
 */
add_filter('insert_user_meta', function($meta, $user, $update){
    global $sitepress;
    if ( !$update && $sitepress instanceof SitePress ) {
        $meta['locale'] = $sitepress->get_locale_from_language_code( apply_filters( 'wpml_current_language', 'en' ) );
    }
 
    return $meta;
}, 10, 3);

2. Edit wp-content/plugins/user-registration-plugin-for-woocommerce/classes/afreg-approved-user-email-class.php
- line 102 after:

$user_email = stripslashes($customer->user_email);

- add:

//WPML
do_action('wpml_switch_language_for_email', $user_email);

- line 108 after:

$email_content = get_option('afreg_approved_email_text');

- add:

//WPML
do_action('wpml_switch_language_for_email', $user_email);
$email_content = apply_filters( 'wpml_translate_single_string', $email_content, 'admin_texts_afreg_approved_email_text', 'afreg_approved_email_text', apply_filters( 'wpml_user_language', null, $user_email ) );

3. Edit wp-content/plugins/user-registration-plugin-for-woocommerce/classes/afreg-disapproved-user-email-class.php
- line 102 after:

$user_email = stripslashes($customer->user_email);

- add:

//WPML
do_action('wpml_switch_language_for_email', $user_email);

- line 108 after:

$email_content = get_option('afreg_disapproved_email_text');

- add:

//WPML
do_action('wpml_switch_language_for_email', $user_email);
$email_content = apply_filters( 'wpml_translate_single_string', $email_content, 'admin_texts_afreg_disapproved_email_text', 'afreg_disapproved_email_text', apply_filters( 'wpml_user_language', null, $user_email ) );

4. Make sure that all email strings are translated in "WPML > String Translation", domains are:
admin_texts_woocommerce_afreg_approved_user_email_user_settings admin_texts_afreg_approved_email_text
admin_texts_afreg_disapproved_email_text

I did all the changes necessary on your production site. Please test it and confirm the issue is solved.

Thanks,
Nico

August 4, 2023 at 10:33 am #14154317

mohammedS-28

Hey Nico,

I have done a decent amount of tests and everything seems to be perfectly working now! Thank you so much for your dedication to solving this and your time. Hope you have a good day!

regards

August 4, 2023 at 3:03 pm #14155615

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hey Mohammed,

Thanks for your feedback and the kind words. Have a great weekend 😉