Skip Navigation

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

Problem:
I am experiencing an issue with translating the logo in WooCommerce emails for a multilingual website (Slovak and Czech). The initial email after a customer places an order is correctly translated, including the logo. However, when an administrator changes the order status, parts of the email, including the logo and additional content, revert to Slovak instead of Czech. This problem does not occur when using the action button on the WooCommerce > Products page.

Solution:
Add the following code to the theme's functions.php:

$option_key = 'woocommerce_email_header_image';
add_filter( 'option_' . $option_key, [ wpml_st_load_admin_texts(), 'icl_st_translate_admin_string' ] );

This should ensure that new emails sent have the correct logo based on the order language.

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

Last updated by Bruno Kos 1 year, 8 months ago.

Assisted by: Bruno Kos.

Author Posts
October 13, 2023 at 9:41 am #14571693

andrejO

I am trying to:
Translate logo in my woocommerce emails.

The problem is very similar to this thread: https://wpml.org/forums/topic/woocommerce-mail-notifications/ However, the resulting mistake found in other plugin is not the case in my case as I am not using that plugin.

The behavior is following:
1. I have web in Slovak and Czech language. When a customer makes an order on the Czech page.

2. The initial email is all correctly translated (even the logo URL from the string translation is correct).

3. However when the administrator (Slovak language is the main language) works with orders and changes the status of the order from waiting for payment to processing. The email gets some parts of the email are untranslated (the logo is in Slovak and the editional_content message is also in Slovak).

4. An interesting fact as was in the aforementioned thread, is that when using the action button on woocommerce > Products page (Mark the order as resolved), the email is all correct in the Czech language, and the logo also.

October 16, 2023 at 11:40 am #14584151

Bruno Kos
WPML Supporter since 12/2018

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

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

Hi,

Thank you for contacting WPML support!

How did you add the logo to your email? Is this a custom email template perhaps?

Can you reproduce this issue on hidden link?

This is a sandbox, I am asking about this as there could be various reasons for such error and this is the quickest way to confirm whether this is WPML bug or something specific to your setup.

Feel free to install whatever is needed here.

Regards,
Bruno Kos

October 17, 2023 at 8:22 am #14591165

andrejO

Hello,

we uploded our theme on demo site. And created sample demo product with translations in slovak and czech. We also created demo order with one product. As you can see in email log pluggin first email is with correct logo translated into czech.

The emails with customer invoice or order completed is with wrong logo - in slovak. The problem apears also when you change status of order in order detail or send email manually from order viac order actions.

We dont use any other plugin only theme and build in wc emails. Theme does not modify emails at all.

Thanks for check and reply

October 17, 2023 at 8:51 am #14591531

Bruno Kos
WPML Supporter since 12/2018

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

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

I see, may I ask you to record a short video using tool such as hidden link to illustrate the steps I need to take and where I can see the issue?

This will ensure that we are on the same page and I will then check this with our 2nd tier support.

October 17, 2023 at 9:19 am #14591835

andrejO

Hello,

it is simple to reproduce. Change status on order detail page to trigger any wordpress default email or manually trigger order action. You can see in attacments.

Then go to email log plugin to see captured email message. Or you can create new order with existing email to see in your inbox.

Note, thah first email order created is with correct logo. Problem apears when you change order status or trigger manual action in admin area.

Thanks

order-change-status.png
order-action.png
October 17, 2023 at 1:14 pm #14594745

Bruno Kos
WPML Supporter since 12/2018

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

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

All clear, I am checking this with our 2nd tier and will keep you posted.

October 18, 2023 at 10:10 am #14601487

Bruno Kos
WPML Supporter since 12/2018

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

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

This is escalated to our 2nd tier team and may take some debugging time, I'll get back to you as soon as I have any news or questions for you.

October 23, 2023 at 9:47 am #14635443

Bruno Kos
WPML Supporter since 12/2018

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

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

This seems to be a matter of your theme in fact, and not WPML issue.

However can you modify your theme code to be like this?

if ( !function_exists('delistrap_wc_option_email_header_image') ):
    /**
     * Temp fix wc email wrong logo
     */
    function delistrap_wc_option_email_header_image( $value ) {
		global $locale, $sitepress, $wpdb;
        $locale = get_locale();
	    $debug = debug_backtrace();
	    $found = false;
	    foreach ($debug as $call) {
		    if (isset($call['function']) && $call['function'] === 'wc_get_template' &&
		        isset($call['args'][0]) && $call['args'][0] === 'emails/admin-new-order.php') {
			    $found = true;
			    break;
		    }
	    }
		if (isset($_GET["id"]) && isset($_GET["action"]) && isset ($_GET["page"]) && $_GET["page"] == "wc-orders" && $found == false){
			$orderlang = get_post_meta($_GET["id"], 'wpml_language', true);
			$checklocale = new WPML_Locale($wpdb, $sitepress, $locale);
			$locale = $checklocale->get_locale($orderlang);
		}
        if ( $locale == 'cs_CZ' ) {
            $value = '<em><u>hidden link</u></em>';
        }
        return $value;
    }
    add_filter( 'option_woocommerce_email_header_image', 'delistrap_wc_option_email_header_image', 20 );
endif;

Does it work now?

October 23, 2023 at 10:12 am #14636379

andrejO

Hello, thanks for reply.

Yes modifying via option_ filter is working, but this is only temp fix.

Our theme does not modify wc emails at all. I switch theme on your demo site to default wp theme 2021 and it is still sending wrong logo.

So, why do you think it is issue of our theme, when it is not working on default wp theme also?

Please can you check it on demo site with default wp theme if you see the logo is wrong. You can create new CZ order or change status of existing orders. Steps are identical as written above.

Thanks for reply.

October 23, 2023 at 11:46 am #14637709

Bruno Kos
WPML Supporter since 12/2018

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

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

Can you check now?

hidden link

I did this:
https://wpml.org/forums/topic/logo-in-woocommerce-mail-and-address-sender-depending-on-language/#post-12173901

So added the following:

$option_key = 'woocommerce_email_header_image';
add_filter( 'option_' . $option_key, [ wpml_st_load_admin_texts(), 'icl_st_translate_admin_string' ] );

to a theme functions.php, it seems like that now new emails sent to demo@wpml.org had the same logo.

October 23, 2023 at 12:11 pm #14637929

andrejO

Hello,

yes with filter to option_{$option_key} it is working now. So can you confirm it is issue of WPML? Why it is not woking by default?

I also found, that language_attributes() function in default wc email header template is also printing worng language, but this you can not see in email log only when you send mail to real adress or via mailtrap. Can you please find solution for this also?

It seem that whole template email header it not translated. Can you check it with you team?

Thanks for reply.

October 24, 2023 at 7:57 am #14643377

Bruno Kos
WPML Supporter since 12/2018

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

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

The first issue is simply a bug that is escalated to our developers team but is not yet resolved.

As for that other issue, can you send me a screenshot from email as you receive it into inbox or through mailtrap?

October 24, 2023 at 9:53 am #14645525
andrejO

Hello,

as you can see in image the lang attribute is in wrong locale.

Thanks

New threads created by Bruno Kos and linked to this one are listed below:

https://wpml.org/forums/topic/split-woocommerce-email-the-lang-attribute-is-in-wrong-locale/

email_example.png
October 24, 2023 at 10:42 am #14646391

Bruno Kos
WPML Supporter since 12/2018

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

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

Let me close here and continue on https://wpml.org/forums/topic/split-woocommerce-email-the-lang-attribute-is-in-wrong-locale/, this being a different issue.