From 838b175f671fe4524c4b1554389c4c09470e88c9 Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Mon, 15 May 2017 14:34:37 -0700 Subject: [PATCH] Use store language in customer emails --- .../class-wc-email-customer-completed-order.php | 3 +++ .../emails/class-wc-email-customer-invoice.php | 5 ++++- .../emails/class-wc-email-customer-new-account.php | 3 +++ includes/emails/class-wc-email-customer-note.php | 3 +++ .../class-wc-email-customer-on-hold-order.php | 3 +++ .../class-wc-email-customer-processing-order.php | 3 +++ .../class-wc-email-customer-refunded-order.php | 4 +++- .../class-wc-email-customer-reset-password.php | 5 ++++- includes/emails/class-wc-email.php | 14 ++++++++++++++ 9 files changed, 40 insertions(+), 3 deletions(-) diff --git a/includes/emails/class-wc-email-customer-completed-order.php b/includes/emails/class-wc-email-customer-completed-order.php index 0bc97d73bf1..d93e43da5b7 100644 --- a/includes/emails/class-wc-email-customer-completed-order.php +++ b/includes/emails/class-wc-email-customer-completed-order.php @@ -26,6 +26,8 @@ class WC_Email_Customer_Completed_Order extends WC_Email { $this->id = 'customer_completed_order'; $this->customer_email = true; + + $this->setup_locale(); $this->title = __( 'Completed order', 'woocommerce' ); $this->description = __( 'Order complete emails are sent to customers when their orders are marked completed and usually indicate that their orders have been shipped.', 'woocommerce' ); @@ -44,6 +46,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email { // Call parent constuctor parent::__construct(); + $this->restore_locale(); } /** diff --git a/includes/emails/class-wc-email-customer-invoice.php b/includes/emails/class-wc-email-customer-invoice.php index 9e4eb8ca423..d3ad1576fc5 100644 --- a/includes/emails/class-wc-email-customer-invoice.php +++ b/includes/emails/class-wc-email-customer-invoice.php @@ -39,6 +39,9 @@ class WC_Email_Customer_Invoice extends WC_Email { public function __construct() { $this->id = 'customer_invoice'; + $this->customer_email = true; + + $this->setup_locale(); $this->title = __( 'Customer invoice', 'woocommerce' ); $this->description = __( 'Customer invoice emails can be sent to customers containing their order information and payment links.', 'woocommerce' ); @@ -54,10 +57,10 @@ class WC_Email_Customer_Invoice extends WC_Email { // Call parent constructor parent::__construct(); - $this->customer_email = true; $this->manual = true; $this->heading_paid = $this->get_option( 'heading_paid', $this->heading_paid ); $this->subject_paid = $this->get_option( 'subject_paid', $this->subject_paid ); + $this->restore_locale(); } /** diff --git a/includes/emails/class-wc-email-customer-new-account.php b/includes/emails/class-wc-email-customer-new-account.php index 4803d1679fd..b7239460341 100644 --- a/includes/emails/class-wc-email-customer-new-account.php +++ b/includes/emails/class-wc-email-customer-new-account.php @@ -54,6 +54,8 @@ class WC_Email_Customer_New_Account extends WC_Email { $this->id = 'customer_new_account'; $this->customer_email = true; + + $this->setup_locale(); $this->title = __( 'New account', 'woocommerce' ); $this->description = __( 'Customer "new account" emails are sent to the customer when a customer signs up via checkout or account pages.', 'woocommerce' ); @@ -65,6 +67,7 @@ class WC_Email_Customer_New_Account extends WC_Email { // Call parent constructor parent::__construct(); + $this->restore_locale(); } /** diff --git a/includes/emails/class-wc-email-customer-note.php b/includes/emails/class-wc-email-customer-note.php index 52afd393990..33339b05284 100644 --- a/includes/emails/class-wc-email-customer-note.php +++ b/includes/emails/class-wc-email-customer-note.php @@ -33,6 +33,8 @@ class WC_Email_Customer_Note extends WC_Email { $this->id = 'customer_note'; $this->customer_email = true; + + $this->setup_locale(); $this->title = __( 'Customer note', 'woocommerce' ); $this->description = __( 'Customer note emails are sent when you add a note to an order.', 'woocommerce' ); @@ -47,6 +49,7 @@ class WC_Email_Customer_Note extends WC_Email { // Call parent constructor parent::__construct(); + $this->restore_locale(); } /** diff --git a/includes/emails/class-wc-email-customer-on-hold-order.php b/includes/emails/class-wc-email-customer-on-hold-order.php index 73cc4f2b0c2..8b18602c2b5 100644 --- a/includes/emails/class-wc-email-customer-on-hold-order.php +++ b/includes/emails/class-wc-email-customer-on-hold-order.php @@ -25,6 +25,8 @@ class WC_Email_Customer_On_Hold_Order extends WC_Email { public function __construct() { $this->id = 'customer_on_hold_order'; $this->customer_email = true; + + $this->setup_locale(); $this->title = __( 'Order on-hold', 'woocommerce' ); $this->description = __( 'This is an order notification sent to customers containing order details after an order is placed on-hold.', 'woocommerce' ); $this->heading = __( 'Thank you for your order', 'woocommerce' ); @@ -38,6 +40,7 @@ class WC_Email_Customer_On_Hold_Order extends WC_Email { // Call parent constructor parent::__construct(); + $this->restore_locale(); } /** diff --git a/includes/emails/class-wc-email-customer-processing-order.php b/includes/emails/class-wc-email-customer-processing-order.php index 02346438897..f5577878be6 100644 --- a/includes/emails/class-wc-email-customer-processing-order.php +++ b/includes/emails/class-wc-email-customer-processing-order.php @@ -25,6 +25,8 @@ class WC_Email_Customer_Processing_Order extends WC_Email { public function __construct() { $this->id = 'customer_processing_order'; $this->customer_email = true; + + $this->setup_locale(); $this->title = __( 'Processing order', 'woocommerce' ); $this->description = __( 'This is an order notification sent to customers containing order details after payment.', 'woocommerce' ); $this->heading = __( 'Thank you for your order', 'woocommerce' ); @@ -38,6 +40,7 @@ class WC_Email_Customer_Processing_Order extends WC_Email { // Call parent constructor parent::__construct(); + $this->restore_locale(); } /** diff --git a/includes/emails/class-wc-email-customer-refunded-order.php b/includes/emails/class-wc-email-customer-refunded-order.php index 23cbcfd3f8e..fffc03fb823 100644 --- a/includes/emails/class-wc-email-customer-refunded-order.php +++ b/includes/emails/class-wc-email-customer-refunded-order.php @@ -37,8 +37,9 @@ class WC_Email_Customer_Refunded_Order extends WC_Email { * Constructor. */ public function __construct() { - $this->set_email_strings(); $this->customer_email = true; + $this->setup_locale(); + $this->set_email_strings(); // Triggers for this email add_action( 'woocommerce_order_fully_refunded_notification', array( $this, 'trigger_full' ), 10, 2 ); @@ -46,6 +47,7 @@ class WC_Email_Customer_Refunded_Order extends WC_Email { // Call parent constuctor parent::__construct(); + $this->restore_locale(); } /** diff --git a/includes/emails/class-wc-email-customer-reset-password.php b/includes/emails/class-wc-email-customer-reset-password.php index 86c4a591f5f..e12a494050a 100644 --- a/includes/emails/class-wc-email-customer-reset-password.php +++ b/includes/emails/class-wc-email-customer-reset-password.php @@ -46,9 +46,11 @@ class WC_Email_Customer_Reset_Password extends WC_Email { public function __construct() { $this->id = 'customer_reset_password'; + $this->customer_email = true; + + $this->setup_locale(); $this->title = __( 'Reset password', 'woocommerce' ); $this->description = __( 'Customer "reset password" emails are sent when customers reset their passwords.', 'woocommerce' ); - $this->customer_email = true; $this->template_html = 'emails/customer-reset-password.php'; $this->template_plain = 'emails/plain/customer-reset-password.php'; @@ -61,6 +63,7 @@ class WC_Email_Customer_Reset_Password extends WC_Email { // Call parent constructor parent::__construct(); + $this->restore_locale(); } /** diff --git a/includes/emails/class-wc-email.php b/includes/emails/class-wc-email.php index be6b463393f..9720e32a9d8 100644 --- a/includes/emails/class-wc-email.php +++ b/includes/emails/class-wc-email.php @@ -243,6 +243,18 @@ class WC_Email extends WC_Settings_API { return str_replace( apply_filters( 'woocommerce_email_format_string_find', $this->find, $this ), apply_filters( 'woocommerce_email_format_string_replace', $this->replace, $this ), $string ); } + public function setup_locale() { + if ( function_exists( 'switch_to_locale' ) && $this->is_customer_email() ) { + switch_to_locale( get_locale() ); + } + } + + public function restore_locale( $email ) { + if ( function_exists( 'restore_previous_locale' ) && $this->is_customer_email() ) { + restore_previous_locale(); + } + } + /** * Get email subject. * @@ -388,6 +400,7 @@ class WC_Email extends WC_Settings_API { * @return string */ public function get_content() { + $this->setup_locale(); $this->sending = true; if ( 'plain' === $this->get_email_type() ) { @@ -395,6 +408,7 @@ class WC_Email extends WC_Settings_API { } else { $email_content = $this->get_content_html(); } + $this->restore_locale(); return wordwrap( $email_content, 70 ); }