[Resolved] Email aligment is inccorect in WooCommerce mail sent to admin
This thread is resolved. Here is a description of the problem and solution.
Problem: The client reported an issue where the admin receives New Order Emails in Hebrew with incorrect left alignment, despite the admin's language setting being Hebrew. This misalignment occurs when the site language is set to English, and the admin's language is set to Hebrew. Solution: We confirmed that this issue is specific to WPML handling Hebrew language emails. We have escalated the problem to our development team for a permanent fix. Meanwhile, we recommend setting the admin language to Hebrew before changing the status of an order that will send an email. Additionally, you can try adding the following code snippet to your theme's functions.php file, but please ensure you have a backup before implementing:
/**
* Fix the text direction attribute when switching language to an RTL language.
*
* @see https://onthegosystems.myjetbrains.com/youtrack/issue/wcml-3838/
*/
add_action( 'wpml_language_has_switched', function ( $newLangCode ) {
/**
* @var \WP_Locale|\WPML\ST\MO\WPLocaleProxy $wp_locale
* @var string $text_direction
* @var \SitePress $sitepress
*/
global $wp_locale, $text_direction, $sitepress;
static $secondaryWPLocales = [];
if (
$wp_locale instanceof \WPML\ST\MO\WPLocaleProxy
&& $sitepress->is_rtl( $newLangCode )
) {
if ( ! isset( $secondaryWPLocales[ $newLangCode ] ) ) {
$text_direction_bk = $text_direction;
$text_direction = 'rtl';
$secondaryWPLocales[ $newLangCode ] = new \WP_Locale();
$text_direction = $text_direction_bk;
}
$wp_locale = $secondaryWPLocales[ $newLangCode ];
}
}, 20 );
Please note that this solution might be irrelevant if it's outdated or not applicable to your case. 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 the issue persists, please open a new support ticket at 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.
Background of the issue:
I created a fresh new WooCommerce store on a website with the default language set to English. The Admin's language is Hebrew. The customer places an order on the English website and receives their email in English with correct alignment. The Admin receives the New Order Email in Hebrew.
Symptoms:
Email sent in Hebrew to Admin was aligned to the left instead of the expected right alignment.
Questions:
Why is the email alignment incorrect for the Admin's New Order Email in Hebrew?
How can I ensure the email is aligned to the right for Hebrew language emails?
Hi,
You asked that I would set the site language as Hebrew, however in the case that I reported the site's language is English, and the Admin user language is Hebrew.
So in the sandbox that you provided, I set the site language as English, and the admin's language as Hebrew.
I placed an order from the English site, and the email that is sent to the admin is sent in English and aligned left to right.
That would be the first email with "Your Sandbox order has been received!" subject.
After doing so, I set the site language to Hebrew (as you requested) and placed another order.
This time the email received has a right to left alignment (which is the correct alignment for Hebrew).
That would be the second email with "Your Sandbox order has been received!" subject.
So it seems like the admin user language has no effect, but the website's language has an effect.
In the installation that you provided for me, the email sent to the admin is in English even if the admin chose Hebrew for his language in his profile settings. Maybe it's because I did not translate the WooCommerce but when I try to do that it says that I need credits which I do not have on this site set up by your team.
I have a staging site with minimal installations (WooCommerce, WPML, WCML, String translations, WP Mail Logging and nothing else active) where I was able to reproduce this problem, where can I share the login details?
Greetings,
I found out that this issue also happens if a customer places an order in Hebrew. The "Processing order" email that is sent to the customer upon payment has the correct alignment (because the user is using the website in Hebrew). However, if an admin logs in to the website from English, and sets the status of the order to completed, the customer will receive the "Completed order" email in Hebrew but with the wrong alignment (ltr instead of rtl).
Seems like this problem only happens when the person that initiates the action that ends up with sending the email, is doing so from a language that has a direction opposite of the recipient's language direction.
Since this affects our customers and not just the admin, I was wondering if you have a snippet of code or workaround to use in the meanwhile to make sure that emails that are sent in Hebrew to Hebrew reading users are always aligned rtl even if the initiator of the email sent is doing so from an ltr language.