Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Emails without order not translated correctly #556

Open
cebbinger opened this issue Jun 7, 2021 · 1 comment
Open

Emails without order not translated correctly #556

cebbinger opened this issue Jun 7, 2021 · 1 comment

Comments

@cebbinger
Copy link

I tried to add and translate additional content to some emails that are sent to the user. Unfortunately, the text is not translated.

Can you reproduce this issue on default Wordpress theme (eg Storefront)?

Yes.

Can you reproduce this issue when all other plugins are disabled except WooCommerce, Polylang and Hyyan WooCommerce Polylang Integration?

Yes.

What product versions and settings are you using when this issue occurs?

  • PHP: 7.2.20
  • WordPress: 5.7.1
  • WooCommerce: 5.2.2
  • Polylang: Free, 3.0.3
  • Hyyan WooCommerce Polylang Integration: 1.5.0
  • Browser: Firefox 89

Steps to Reproduce

  1. Add additional content to an email not related to an order. (for example: lost password)
  2. Translate the text using Polylang.
  3. Trigger the email with additional content. (for example: click "Lost your password?" on account page)

What I Expected

I expected to see the translated additional content in the email.

What Happened Instead

I saw the original, untranslated text in the email.

@cebbinger
Copy link
Author

Apparently, the plugin skips applying the translation ($string_template) if the $target_object is not a WC_Order.

//perform standard replacements on template
if (is_a($target_object, 'WC_Order')) {
//for legacy compatibility
$find = array();
$replace = array();
$find['order-date'] = '{order_date}';
$replace['order-date'] = date_i18n(wc_date_format(), strtotime($target_object->get_date_created()));
$formatted_string = str_replace(apply_filters(HooksInterface::EMAILS_ORDER_FIND_REPLACE_FIND_FILTER, $find, $target_object),
apply_filters(HooksInterface::EMAILS_ORDER_FIND_REPLACE_REPLACE_FILTER, $replace, $target_object), $string_template);
//better solution, native WooCommerce call
$formatted_string = $email_obj->format_string($formatted_string);
}
return $formatted_string;

For my individual case, the problem seems to be solved by adding the following code before returning $formatted_string in line 497:

else {
    return $email_obj->format_string($string_template);
}

I'm not sure if that works in other configurations, too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant