Skip Navigation

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

Problem:
The client is developing a plugin that adds custom emails to WooCommerce and is using WPML to send emails in the current user's language. While the text within the email translates correctly, the WooCommerce email footer, which is an option fetched by a hook, does not translate as expected.

Solution:
We recommend following our documentation on sending emails with WPML, which provides guidance on correctly implementing email translations via WPML/WCML. If you're triggering the email from custom code, you should use the WPML hooks provided in the documentation:

Additionally, to ensure the translation of admin options in the backend, you should use the

wpml_st_force_translate_admin_options

hook when needed. This hook forces the translation of admin texts and can be implemented as follows:

do_action( 'wpml_st_force_translate_admin_options' );

Please note that the solution provided might be irrelevant if it's outdated or not applicable to your case. If the issue persists, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please open a new support ticket with us.
WPML Support Forum

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 19 replies, has 2 voices.

Last updated by johannesG-17 1 year, 2 months ago.

Assisted by: Dražen.

Author Posts
February 20, 2024 at 1:48 pm #15323103

johannesG-17

I'm currently developing a plugin which adds custom email to WooCommerce. To send them within the current users language, I use the following code inside an email:

do_action( 'wpml_switch_language_for_email', $this->get_recipient() );
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
do_action( 'wpml_restore_language_from_email' );

This works good for the text inside this email translated with __('Text','Domain');

But there is one big issue: the additional footer from WooCommerce which is fetched at the end of a template:

/*
* @hooked WC_Emails::email_footer() Output the email footer
*/
do_action( 'woocommerce_email_footer', $email );

This hook refers to the following code:

apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) )

This means that translating strings with the hook I've wrapped around the sending function works but not for options. And yes, there is an existing translation for this option. If I send the email from the admin page in the users language, the footer is translated correctly. So at some point there is something wrong.

It would be good to have this fixed asap since the footer contains my page legal infos which I need to send in the correct language as well.

February 21, 2024 at 12:01 pm #15327694

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for contacting us.

Please note as per our support policy supporting or debugging custom-coded issues is out of our scope, for that, we suggest using the WPML contractor's service:

- https://wpml.org/contractors/

What we can help with, is suggesting a correct approach, from what I can see your shared code looks good, but for retrieving string translation you should use wpml_translate_single_string
( https://wpml.org/wpml-hook/wpml_translate_single_string/) and wth and if statements show the correct string value depending on the language of the email/user.

Hope this helps.

Regards,
Drazen

February 21, 2024 at 12:07 pm #15327721

johannesG-17

Hi Drazen,

I think you're not reading correctly. This ticket is a bug report ticket, not a development request! The programming stuff is correct. The stuff that's not translated is not from us. This is the default WooCommerce standard. Our stuff we did is correctly translated.

Please don't make it too much complex here again. Let's find a solution together. By the way, this issue applies to all default WooCommerce emails as well!

Regards,
Johannes

February 21, 2024 at 12:13 pm #15327725

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello Johannes,

as I understood from your reply, the issue happens while developing a custom plugin and wrapping the WooCommerce hook, so it sounded like issue happens with custom code / plugin.

To make things clear, can you please confirm footer is also not translated in default WC emails when using the WP default theme and that only WPML plugins and WooCommerce are active, all others disabled?

Please make a backup before proceeding.

Let me know.

Thanks,
Drazen

February 21, 2024 at 12:17 pm #15327730

johannesG-17

Hi,

as I already mentioned: its not being translated on all WooCommerce emails when wrapping the sending function into the desired hooks to send the user the correct translated email. The content is translated but not the footer which is received with the get_option() function.

When I change the language from the admin dashboard of myself sending the email by triggering it for a user from the WordPress dashboard, the footer has the language I use to send the mail. So there is something not translating very well.

This has nothing to do with a theme or other plugins. It's just not loading the correct translation depending on the 2 hooks wrapping the sending function.

If I retry this with specific WooCommerce order emails which are translated by the wpml language meta inside an order, everything is fine, even the footer.

February 21, 2024 at 12:31 pm #15327787

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

in general, behavior is not the same for backend emails and frontend actions.

As I said in my first reply I think that probably approach might not be correct here, but I might be wrong.

Let's check it out in a simple example case, and then I will have a proper picture of the case and can escalate further if it is a bug.

I have set up a test site from our side, all is configured. Can you please reproduce a simple case and let me know the steps you took and how to check the issue?

Login link: hidden link

Let me know.

Thanks,
Drazen

February 21, 2024 at 5:26 pm #15329728

johannesG-17

Hi,

I have configured everything but I am not able to receive any mails from this page. Without receiving / sending mails from this page I'm unable to verify the successful rebuild of the issue. How can we solve this?

Regards

February 21, 2024 at 5:34 pm #15329750

johannesG-17

Hi,

I was able to install a mail logging plugin. Please visit this page:

hidden link

Please click on the eye icon of the email with the subject: Reset your password on Sandbox

If you scroll down now, you can see that the footer is still in English!

How you can reproduce it:

1) Login to the page
2) Switch to German inside the dashboard
3) Create yourself a user with the English locale setting
4) Click the link "Passwort zurücksetzen senden" inside the user list on your user

I'm sure this works the other way around as well. So as you can see, the content gets translated but not the footer which is used inside WooCommerce by calling the get_option() stuff.

And one final note: If you now switch your admin dashboard language to English as well and re-do the steps, the footer is correctly translated.

February 22, 2024 at 8:56 am #15331929

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for getting back and taking the time.

Can you please share the full steps on what you did exactly?

Since now I have switched themes and disabled the addon plugins you installed and I do not get the same email template/behavior after the steps you shared. I suspect som other steps/code is needed here to reproduce the issue.

I have tried to ask for a reset password from the front end and the footer text translated fine.

Regards,
Drazen

February 22, 2024 at 10:27 am #15332595

johannesG-17

Hi Drazen,

I don't get it. As I told you, I've installed my plugin since it just uses the WooCommerce template. If you disable it, the default WordPress plain text will be used. I gave you a way to reproduce the issue. If you don't like the way, I need to find a solution by my own.

My plugin just uses the WooCommerce email template!

This makes me crazy again. From a developer point of view, this is a very acceptable way to reproduce this issue. If I need to write another code, we're at the same point again.

Please let me know, if you are open to find a solution. If not, I will fix it myself. This costs me way less time.

Regards

February 22, 2024 at 3:08 pm #15334325

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

I am sorry, but as I said above if it includes your custom plugin, this falls under custom coding support which we can not support or debug. I tried my best to check, suggest, and proceed on this case.

If you think it is a WPML bug, we will need a simple example case without additional custom plugins or with very simple example code/changes where we can see the issue and reproduce it also on our own by following shared steps/snippets.

As stated in the support policy:
- https://wpml.org/purchase/support-policy/

Hope you will understand.

Regards,
Drazen

February 22, 2024 at 3:34 pm #15334469

johannesG-17

Hi Drazen,

I really don't understand why it's my task to do your debugging work but okay, this time I will do it since it's annoying and provides me legal issues...

I've programmed a very very very short plugin which has only a few lines. Instead of sending the password reset email, it now sends the welcome email of WooCommerce when a customer created a new account.

I've validated the sent email and it has the reproducible error. The footer is still not translated - even if it should. Please provide a fix asap.

Regards,
Johannes

February 22, 2024 at 3:36 pm #15334514

johannesG-17

And just to help you even more, I've attached an image showing that I've translated the WooCommerce footer text correctly!

Bildschirmfoto 2024-02-22 um 16.35.40.png
February 23, 2024 at 8:05 am #15336253

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

thanks for getting back. It is not your job to do the debugging, we will do so, but as said we can not check your custom-coded solution or check something if not sure how to reproduce it, for bug reports we need a clear simple example.

Thanks for reproducing this, looks good. 🙂

The only thing that I am missing is: "it now sends the welcome email of WooCommerce when a customer creates a new account."

I tried to create an account for a user in both languages, but I do not get the same email as you did, nor do I see a way to create an account from front end.

Can you please share the steps to check and I will then escalate this issue further.

Thanks,
Drazen

February 23, 2024 at 8:18 am #15336307

johannesG-17

Hi Drazen,

good. But why do you create an account? I never said that you need to create one!!! I told you that the account email is sent when you reset the password. It's a debugging thing I've implemented to simulate the error. There is no email to expect when you create an account...

Please escalate this and get this fixed soon. Otherwise, I will leave WPML since you are always making things complex. It's a simple error which can be debugged very well by a developer who has knowledge about this stuff.

Regards