qTranslate-Team/woocommerce-qtranslate-x

Customer completed order email is sent in the wrong language

johnclause opened this issue · 54 comments

Submitted in two places by https://wordpress.org/support/profile/og-s:
https://wordpress.org/support/topic/woocommerce-emails-3
https://wordpress.org/support/topic/wrong-email-language

The description copied here:

I'm using the latest version of Github qTranslate-X, WooCommerce & qTranslate-X

The customer processing order email is sent in the correct language. But than, all e-mails sent from the woocommerce admin are sent in the wrong language. The customer completed order email is sent in the wrong language. It seems that the default language is used.

Is this e-mail sent in the response to admin action? Indeed, then admin language will be used. Interesting, nobody noticed this before. A workaround would be to switch admin panel to the language needed before pressing button to complete order.

Before we go further, could you confirm that this works?

Michel (@mweimerskirch), did you hear about such problem before?

The default language defined in qtranslate is used (not the admin language)

Anyway, I think this would not be very easy to solve (unless Michel already had this problem and has a solution), since the original language used on order is not saved anywhere with order, as far as I can imagine. We will have to figure out a way where to save it and then to re-use it on further admin emails.

Do you think it can be resolved? Can I implement the solution from Michel ?

I am sure it can be done, just will take some time. We have to see what Michel says.

My plugin didn't solve this either. Actually, I've never even thought about it. I'll see if I can find out whether it's possible or not. I think the only way to make it work would be to store the language at the time the order is made, because WooCommerce has an option to order without creating a user account. This way, the correct language would be used wheter or not the customer has a user account or not.

I have a problem with order emails as well:

automatic email for processing order is sent ok and in correct language (the one that was chosen while making order). But all emails after that look like this:

SUBJECT: [:hr]Vaša Web narudžba od 22/03/2015 je dovršena[:en]Your MK LED Auto/Moto rasvjeta order from 22/03/2015 is complete[:]

Also if I add note to order or if it is marked as completed (basically every email after automatic processing email), it will be send in language that is used in admin panel. I tried several times and it's always like that.

Interesting is that if I deactivate qtranslate & woocommerce plugin, emails are fine, subject is ok and based on language that is used in admin panel.

Can you repair those 2 things?

@MarioS3 your second problem (" it will be send in language that is used in admin panel") should be solved by #4. Please check if it works for you.

@MarioS3 I added a fix for your first problem to #4 as well. Please test it and let us know if it works for you as well.

@OGSWEB, @MarioS3: just in case you are not sure, to test it, download the latest integrating plugin from GitHub https://github.com/qTranslate-Team/woocommerce-qtranslate-x, use "Download ZIP" button, or press here for the sake of convenience.

If all goes well for you, we will publish it as next release, version 1.1.

Parse error: syntax error, unexpected T_FUNCTION in ...woocommerce-qtranslate-x/qwc-admin.php on line 558

I changed the code so it is compatible with PHP 5.3 again.
@OGSWEB You should upgrade to 5.4. PHP 5.3 is no longer supported by the PHP developers.

I did not mean to close it yet, I do not know why it did, but anyway we can write to closed issue and may re-open if it gets big again.

@OGSWEB, @MarioS3: to test it again, deactivate previously tested plugin, delete its files, then do as before: download the latest integrating plugin from GitHub https://github.com/qTranslate-Team/woocommerce-qtranslate-x, use "Download ZIP" button, or press here for the sake of convenience. You will see the same version 1.1 on newly downloaded plugin, but it is updated.

@johnclause: It closed, because I wrote "Fixes #3" in the pull request.

I deleted last posts, this is summarized one:

This is list of all problems with plugin version 1.1 activated:

  • There in no data on thank you page, no message on thank you page
  • Total sum in new order email is 0
  • In new order email, there is no billing or shipping address, no customer data
  • Customer doesn't get processing order email at all

When deactivated following problems appear:

  • products are displayed wrong in shopping cart widget, in emails and in admin orders (this is fixed when plugin is activated). Example:

[:hr]Osram Cool Blue Hyper 12V - do 50% bjelije (5000K)[:en]Osram Cool Blue Hyper 12V - up to 50% whiter light (5000K)[:]

  • emails are sent in wrong language (this is fixed when plugin is activated)

Sorry, guys, for the delay. We will take a look into it, hopefully over this weekend.

Hope you can fix it :-)

Apparently Michel is currently unavailable. I may take a look into it within next couple of days. Sorry for the delay.

I tried reproducing the issues over the weekend, but I wasn't able to. Tried again just now. Everything works fine for me. Are you using any other WooCommerce-related plugins? If yes, try deactivating them. Also, please try using one of the default WordPress themes. Other themes might override the WooCommerce templates and they might ignore some of the newer filters.

@mweimerskirch There were no problems of this kind with previous version, they started with 1.1 version. I don't have overridden templates or anything that could possibly affect to the list of problems that I stated above. Also it's happening on "stock" COD payment method, I didn't even try custom ones, so that also shouldn't be a problem. I have U-design theme, I think that can't be problem also. Maybe you can check by yourself if you are willing to?

one of the default WordPress themes

Which one, for example, would you recommend for testing?

I am trying Storefront now and cannot get it working in a meaningful way. Emails are not sent to customer, 'thank you' page is apparently messed up, it is basically empty and error message is shown

Notice: Undefined variable: order in /wp-content/plugins/woocommerce/includes/shortcodes/class-wc-shortcode-checkout.php on line 196

Order is shown in multiple languages in /wp-admin/post.php?post=XX&action=edit, and some fields are raw multilingual fields. If I press 'Save Order', email then goes in admin language. However, I verified that, your filter 'save_post' worked and there is meta value for order language in the database.

That is the story so far.

Same problems like johnclause, looks like I'm not the only one :)

Hmm, strange. I'll check again today. Maybe I mistakenly tested one of my branches instead of the "master" branch. I'll let you know.

As to the theme: Any theme that does not include WooCommerce files is fine for testing. If there are WooCommerce files in the theme, they might override the original ones.

I was finally able to reproduce the issues on another test installation. I'm not sure what went wrong, but the issue was with the action I used to store the user language. I used the generic "save_post" action from WordPress and I've now replaced it with a woocommerce-specific filter (which also makes the implementation lighter). That worked for me on both the installations that I tried it on.
@OGSWEB and @MarioS3: I'd appreciate if you could test if this works for you as well.

Hmm... there is still something wrong

The wrong part for me is apparently custom attributes. They still misbehave for me sometimes and maybe there is more, I have recently tried 'simple' product and it did not work for me either under Storefront theme, which does not override templates, as far as I can see.

Filter 'qwc_filter_postmeta' fixed some of too early translations, but not apparently all. Woocommerce apparently rely on untranslated strings in a few places, and if we translate it too early with 'qtranxf_filter_postmeta', it gets confused. I make this derivation based on the fact that if I turn off -X, all works fine, except that all multilingual strings shown untranslated, but all emails, etc, work just fine. When I turn on -X on the same installation, customer e-mail stops coming, only admin one comes, and thank you page shows error message. There are no other errors in log and anywhere else. Apparently it silently breaks in some place and the rest does not go right during order processing. I did not dig it deeper yet.

I'm still working on it. Please wait before pulling next time until somebody else has tested it. "Hacking" Woocommerce is quite tricky ;-)

I saw that one in the code yesterday, and if you did not do it I would make the same change later ;) Having the same thought as you did, makes me feel pretty confident about this change.

Besides, normal users may not know how to test a branch. You would need to give instructions for them how to test it in your comment then.

@mweimerskirch Is new update ready for download and test or are you still working something on it?

At the moment I'm not working on it. I only did a quick test, but it should work better than the earlier versions. I'll do some more tests later today.

I tested you new release and here is summary:

  • There in no data on thank you page, no message on thank you page - OK now
  • Total sum in new order email is 0 - OK now
  • In new order email, there is no billing or shipping address, no customer data - OK now
  • Customer doesn't get processing order email at all - OK now

But there are still some problems (So far that I noticed):

  • mail with Note is sent like this - [:hr]Vašoj Web narudžbi je dodana napomena[:en]A note has been added to your order[:]
  • automatic processing mail is in correct language but all others are still in admin language
  • new order email (repeated one, from admin bar) is send like this - [:hr]Web narudžba[:en]Web order[:]

These are now really small problems, not crucial ones :)

The "your order is complete" mail should be sent in the correct language though. (the one that is sent when you click the "complete" button:
image

Other issues:

  • I've never used the notes before. I'll work on that
  • With "all others" you mean when you resend one from here?:
    image
    I did indeed not look after these. All the mails are sent using different mechanisms, so we have to use different workarounds.

I committed another patch that fixes the translation tags displayed in the "note added to your order" mail. It does not yet use the user's language (working on that) but at least it does not show translation tags in the subject anymore.

@mweimerskirch yes all others are these from "resend order emails" :)

And another one. This one is for the "note added to your order" emails.

I'm not sure yet what to do about the "resend order emails" action. If that is the only thing missing, I'd suggest to create a new issue just for this.

I committed a few more filters to help with translations from order editor page and things like e-mail footer and 'from name' on re-sent email, which you probably did not yet tried to localize.

At this point, in my testing, everything is fine except e-mails re-sent from order editor page with a press of button "Save Order". E-mail now goes partly in the language of order, and partly in admin language. This problem may be very difficult to solve, because the order editor page and action of sending email are both processed within the same request. By the time of email sending, some strings are already translated into admin language and use of filters 'woocommerce_before_resend_order_emails' and 'woocommerce_after_resend_order_emails' only helps on a part of email. I do not know how to solve this. I am curious, how WPML does it? Does anyone have an experience with it?

With the exception mentioned, are we done here? There is a workaround in the worst case, switch admin to the language of order before sending e-mail. It works, it is inconvenient, but better than nothing.

Michel, it just occured to me that we may ask Woocommerce to change the way they send e-mails from editor pages. It would not be difficult for them to use ajax calls instead in which we could sent language to be different. I have already asked them for a couple of changes, and they did cooperate. But we would need to prepare a complete solution with a single clean PR to simplify their work. They will be naturally concerned not to break anyone, so we really need to test it all in all the ways before coming to them. Do you think it may work?

There is just one more problem with completed email (after clicking button for completed order):

This are Instructions for COD payment gateway, they were shown in both languages like this:

[:hr]Molimo Vas da proizvode platite gotovinom prilikom preuzimanja paketa. Detalje o narudžbi možete pratiti preko Korisničkih stranica.[:en]Please pay your Order with cash when it is delivered to your address. Details about order can be seen on My Account page.[:]

It did not reproduce for me, but I noticed that email footer is wrong. Is footer correct for you?
@MarioS3: Try new order from scratch again. If instructions are still wrong, that must be on your theme template overrides. To test the theory, remove template overrides and see if it helps. If it does, then you can fix it under a child theme. Woocommerce has instruction on how to override templates. I also assume you use the latest version of everything?

@mweimerskirch I don't have template overrides. I tried again, from new order - automatic email instructions are fine and they look like this:

  • Molimo Vas da proizvode platite gotovinom prilikom preuzimanja paketa. Detalje o narudžbi možete pratiti preko Korisničkih stranica.

but when these instructions are displayed in completed order email (or repeated emails from "Order actions", than they are like this:

  • [:hr]Molimo Vas da proizvode platite gotovinom prilikom preuzimanja paketa. Detalje o narudžbi možete pratiti preko Korisničkih stranica.[:en]Please pay your Order with cash when it is delivered to your address. Details about order can be seen on My Account page.[:]

It's not that big problem - take your time :)

Was there maybe new update after this one? #3 (comment)

I am sorry, footer is correct, I had it typed in wrong way. So all good for me. @OGSWEB, are you testing it too? Can we release 1.1?

@MarioS3, yes, I followed your instructions and tested both ways for completed email. It works fine for me, and for COD as well.

I don't have template overrides

I meant, your theme may have it overridden, almost surely. But you can change the overrides through child theme. Please, read Woocommerce instructions. Are you using the latest Woocommerce and WP?

There is one more little thing to look out - this is button when you enter to product attributes :)

image

@johnclause maybe it's because of U-Design, I wouldn't know. Yes, latest Woocommerce and WP.

@mweimerskirch, do you think we are ready to release 1.1? Do you think we should describe the little issue left with sending admin email from order editor page in an "Known Issue" section? Do you wish to do it, or do you wish me to do it?

Yes, I think we can release. I'll prepare something for the known issues.

@MarioS3:

maybe it's because of U-Design, I wouldn't know

I am saying that you can know. Remove overrides temporary to test. Woocommerce instructions on child theme creation explain how it works.

@mweimerskirch: thanks for the readme, I expanded it a little bit, https://github.com/qTranslate-Team/woocommerce-qtranslate-x#known-issues, and also included the issue with buttons display as @MarioS3 reported. For the latter, I will need to adjust qTranslate-X, may be on 3.3 release, which is coming soon. Anything else I missed?

I would wait for a final feedback from @OGSWEB and @MarioS3, since they are probably the only ones at trouble now with the older version.

@MarioS3: did you figure it out? What is the status?

@OGSWEB: Are you still interested?

Yes of course :-) ! Thank you very much !! I was very busy but I will make tests next week

@johnclause I didn't, it's probably because of U-Design since I'm the only one having this "Instructions" issue. You may proceed with official update.

probably because of U-Design

If so, then this would be totally fixable with a child theme creation and a little modification, as Woocommerce recommend on their 'System Status' page: "If you're modifying WooCommerce or a parent theme you didn't build personally we recommend using a child theme. See: How to create a child theme."

Version 1.1 is released. Seems like this issue can be closed, we can still continue discussion under closed issue, if needed.

What is the status on this? I'm experiencing language problems with basicly all email templates. They are send in wrong language.