• Resolved antoska

    (@antoska)


    We have a woocommerce store with 2 languages ??(English and Belarusian). If a person is logged in, emails are sent in the person’s chosen language correctly. But if a person is not logged in, emails are sent only in English, despite the fact that the Belarusian language is selected on the site and everything is displayed correctly in Belarusian. How can I fix this problem?

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Alex

    (@alexcozmoslabs)

    Hi,

    Are those emails generated directlyby WooCommerce? We have full integration with WooCommerce in terms of email translation, meaning the login-in users receives them in the last language they visited the website in. If you don’t require users to log in before placing an order, then the language in which they placed the order on the checkout page will be used for all further email notifications sent to this user.

    If the emails are generated by 3’rd parties plugins, while emails that get sent after a user action are translated correctly, out of order emails like reminders (if you use subscriptions) will always be sent in the default language as we don’t store the user language in order to know in what language we should send the email.

    Best Regards,

    Paul

    (@paulschiretz)

    Hi @alexcozmoslabs,

    Just chiming in, @antoska sorry for hijacking this thread… but this is exactly the same issue as reported !3 months ago! and the thread was simply closed.

    Maybe if i can clarify things a bit @alexcozmoslabs can fix this for us! ??

    The issue
    There is a bug/misconception in the plugin that needs to be fixed for emails to be sent in the customers language if not a registered user.

    In your public function trp_woo_setup_locale( $bool, $wc_email ) function you rely on the recipient of the email to determine the language
    $recipients = explode( ',', $wc_email->get_recipient() ); Line 145 in class-woocommerce-emails.php of Translatepress.

    BUT at the time trp_woo_setup_locale is called via the woocommerce_allow_switching_email_locale hook the recipient in the email object is still NULL, which by the way causes a deprecation warning as i noted here https://www.ads-software.com/support/topic/php-error-when-using-woocommerce-and-the-order-email-is-send-php-8-2/

    the woocommerce_allow_switching_email_locale hook gets called via the setup_locale() function in the individual woocommerce emails. Here the trigger function from class-wc-email-customer-processing-order.php as an example:

    		/**
    * Trigger the sending of this email.
    *
    * @param int $order_id The order ID.
    * @param WC_Order|false $order Order object.
    */
    public function trigger( $order_id, $order = false ) {
    $this->setup_locale();

    if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
    $order = wc_get_order( $order_id );
    }

    if ( is_a( $order, 'WC_Order' ) ) {
    $this->object = $order;
    $this->recipient = $this->object->get_billing_email();
    $this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
    $this->placeholders['{order_number}'] = $this->object->get_order_number();
    }

    if ( $this->is_enabled() && $this->get_recipient() ) {
    $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
    }

    $this->restore_locale();
    }

    As you can clearly see the $this->recipient field of wc_email is initialized way past the setup_locale function which calls woocommerce_allow_switching_email_locale to which your trp_woo_setup_locale function is hooked. So there is now way you can customize the emails for a guest customer when you rely on the $recipients field of the wc_email object. Which you do! The only way you can make it work like the structure is now is by getting the billing_email manually from the order object instead of relying on the wc_email object.

    In short
    This is translation flow is not working:
    trigger -> setup_locale -> woocommerce_allow_switching_email_locale -> trp_woo_setup_locale -> the recipient is set up. cause trp_woo_setup_locale relies on the recipient.
    Even worse it will cause an error in php > 8.3….. explode(): Passing null to parameter #2 ($string) of type string

    You need to come up with something clever to fix this or simply use the get_billing_email(); function of the order directly to deterime the language in trp_woo_setup_locale.

    I really hope this gets fixed soon so @antoska, all the others not even aware of the issue and me can finally send translated mails!

    LET’S fix this, please!!!

    Cheers,
    Paul

    PS: I haven’t found a git repo of yours but i would be happy to submit a pull-request directly if needed.

    Plugin Support Alex

    (@alexcozmoslabs)

    Hi,

    Presented the issue to our dev team.
    Thank you for your insights as well as for the proposed fix. Could I ask you to upload your file with the fix on https://gist.github.com/starred? Right now we don’t have a plugin GIT public instance.

    Our dev team will try to fix this issue in the future and include in the core plugin.

    Thank you again.

    Kind Regards,

    Paul

    (@paulschiretz)

    Hi @alexcozmoslabs,

    I’m sorry to say this, but as of now i don’t have a fix ready for this just the explanation above for your dev team. When i wrote the description above i was debugging the plugin and reading a bit into your code, right now i’m stuck in another project… but i’m sure if your dev team just buts a breakpoint in the trp_woo_setup_locale function and read the description above they see the issue and can restructure the calls in your plugin so all vars are set before you try to read the recipients.

    Sorry to be not more helpful this time, still hoping this gets fixed soon so i can finally upgrade to php 8.2 and have translated mails.

    Cheers, Paul

    Plugin Support Alex

    (@alexcozmoslabs)

    Hi,

    We are in the testing phase of this. After we will include the fix into our core plugin.
    Just follow our changelog: https://www.ads-software.com/plugins/translatepress-multilingual/#developers.

    Kind Regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.