I’m using woocommerce + wpml and I would like to set programmatically email order completed.
I’m trying to using $sitepress->switch_lang() but seems not work.

add_action( 'woocommerce_order_status_completed', 'mysite_woocommerce_order_status_completed' );

function mysite_woocommerce_order_status_completed($order_id)
    global $sitepress;
    $sitepress->switch_lang('en', true);
    if($sitepress->get_current_language() == 'en')
       $mailer = WC()->mailer();
       $recipient = 'customer@mail.com';
       $subject = 'Your Order has been completed';
       $content = get_processing_notification_content_completed( $order, $subject, $mailer );
       $headers = "Content-Type: text/htmlrn";

       $mailer->send( $recipient, $subject, $content, $headers );

function get_processing_notification_content_completed( $order, $heading = false, $mailer ) {
    $template = 'emails/customer-completed-order.php';

    return wc_get_template_html( $template, array(
      'order'         => $order,
      'email_heading' => $heading,
      'sent_to_admin' => true,
      'plain_text'    => false,
      'email'         => $mailer
    ) );

although I use “switch_lang()”, mails continues to show in Italian language.

Read more here: Woocommerce switch language on order completed mail


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: