Merge pull request #15090 from woocommerce/fix/14763

Use site locale for customer emails.
This commit is contained in:
Mike Jolley 2017-05-16 17:27:39 +01:00 committed by GitHub
commit 7205a8e020
9 changed files with 115 additions and 22 deletions

View File

@ -26,15 +26,15 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
$this->id = 'customer_completed_order'; $this->id = 'customer_completed_order';
$this->customer_email = true; $this->customer_email = true;
$this->title = __( 'Completed order', 'woocommerce' ); $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' ); $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' );
$this->heading = __( 'Your order is complete', 'woocommerce' );
$this->subject = __( 'Your {site_title} order from {order_date} is complete', 'woocommerce' );
$this->template_html = 'emails/customer-completed-order.php'; $this->template_html = 'emails/customer-completed-order.php';
$this->template_plain = 'emails/plain/customer-completed-order.php'; $this->template_plain = 'emails/plain/customer-completed-order.php';
$this->set_email_strings();
// Triggers for this email // Triggers for this email
add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ), 10, 2 ); add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ), 10, 2 );
@ -46,6 +46,16 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
parent::__construct(); parent::__construct();
} }
/**
* Set email strings.
*/
public function set_email_strings() {
$this->setup_locale();
$this->heading = __( 'Your order is complete', 'woocommerce' );
$this->subject = __( 'Your {site_title} order from {order_date} is complete', 'woocommerce' );
$this->restore_locale();
}
/** /**
* Trigger the sending of this email. * Trigger the sending of this email.
* *

View File

@ -39,27 +39,35 @@ class WC_Email_Customer_Invoice extends WC_Email {
public function __construct() { public function __construct() {
$this->id = 'customer_invoice'; $this->id = 'customer_invoice';
$this->customer_email = true;
$this->title = __( 'Customer invoice', 'woocommerce' ); $this->title = __( 'Customer invoice', 'woocommerce' );
$this->description = __( 'Customer invoice emails can be sent to customers containing their order information and payment links.', 'woocommerce' ); $this->description = __( 'Customer invoice emails can be sent to customers containing their order information and payment links.', 'woocommerce' );
$this->template_html = 'emails/customer-invoice.php'; $this->template_html = 'emails/customer-invoice.php';
$this->template_plain = 'emails/plain/customer-invoice.php'; $this->template_plain = 'emails/plain/customer-invoice.php';
$this->subject = __( 'Invoice for order {order_number} from {order_date}', 'woocommerce' ); $this->set_email_strings();
$this->heading = __( 'Invoice for order {order_number}', 'woocommerce' );
$this->subject_paid = __( 'Your {site_title} order from {order_date}', 'woocommerce' );
$this->heading_paid = __( 'Order {order_number} details', 'woocommerce' );
// Call parent constructor // Call parent constructor
parent::__construct(); parent::__construct();
$this->customer_email = true;
$this->manual = true; $this->manual = true;
$this->heading_paid = $this->get_option( 'heading_paid', $this->heading_paid ); $this->heading_paid = $this->get_option( 'heading_paid', $this->heading_paid );
$this->subject_paid = $this->get_option( 'subject_paid', $this->subject_paid ); $this->subject_paid = $this->get_option( 'subject_paid', $this->subject_paid );
} }
/**
* Set email strings.
*/
public function set_email_strings() {
$this->setup_locale();
$this->subject = __( 'Invoice for order {order_number} from {order_date}', 'woocommerce' );
$this->heading = __( 'Invoice for order {order_number}', 'woocommerce' );
$this->subject_paid = __( 'Your {site_title} order from {order_date}', 'woocommerce' );
$this->heading_paid = __( 'Order {order_number} details', 'woocommerce' );
$this->restore_locale();
}
/** /**
* Trigger the sending of this email. * Trigger the sending of this email.
* *

View File

@ -54,19 +54,29 @@ class WC_Email_Customer_New_Account extends WC_Email {
$this->id = 'customer_new_account'; $this->id = 'customer_new_account';
$this->customer_email = true; $this->customer_email = true;
$this->title = __( 'New account', 'woocommerce' ); $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' ); $this->description = __( 'Customer "new account" emails are sent to the customer when a customer signs up via checkout or account pages.', 'woocommerce' );
$this->template_html = 'emails/customer-new-account.php'; $this->template_html = 'emails/customer-new-account.php';
$this->template_plain = 'emails/plain/customer-new-account.php'; $this->template_plain = 'emails/plain/customer-new-account.php';
$this->subject = __( 'Your account on {site_title}', 'woocommerce' ); $this->set_email_strings();
$this->heading = __( 'Welcome to {site_title}', 'woocommerce' );
// Call parent constructor // Call parent constructor
parent::__construct(); parent::__construct();
} }
/**
* Set email strings.
*/
public function set_email_strings() {
$this->setup_locale();
$this->subject = __( 'Your account on {site_title}', 'woocommerce' );
$this->heading = __( 'Welcome to {site_title}', 'woocommerce' );
$this->restore_locale();
}
/** /**
* Trigger. * Trigger.
* *

View File

@ -33,14 +33,14 @@ class WC_Email_Customer_Note extends WC_Email {
$this->id = 'customer_note'; $this->id = 'customer_note';
$this->customer_email = true; $this->customer_email = true;
$this->title = __( 'Customer note', 'woocommerce' ); $this->title = __( 'Customer note', 'woocommerce' );
$this->description = __( 'Customer note emails are sent when you add a note to an order.', 'woocommerce' ); $this->description = __( 'Customer note emails are sent when you add a note to an order.', 'woocommerce' );
$this->template_html = 'emails/customer-note.php'; $this->template_html = 'emails/customer-note.php';
$this->template_plain = 'emails/plain/customer-note.php'; $this->template_plain = 'emails/plain/customer-note.php';
$this->subject = __( 'Note added to your {site_title} order from {order_date}', 'woocommerce' ); $this->set_email_strings();
$this->heading = __( 'A note has been added to your order', 'woocommerce' );
// Triggers // Triggers
add_action( 'woocommerce_new_customer_note_notification', array( $this, 'trigger' ) ); add_action( 'woocommerce_new_customer_note_notification', array( $this, 'trigger' ) );
@ -49,6 +49,16 @@ class WC_Email_Customer_Note extends WC_Email {
parent::__construct(); parent::__construct();
} }
/**
* Set email strings.
*/
public function set_email_strings() {
$this->setup_locale();
$this->subject = __( 'Note added to your {site_title} order from {order_date}', 'woocommerce' );
$this->heading = __( 'A note has been added to your order', 'woocommerce' );
$this->restore_locale();
}
/** /**
* Trigger. * Trigger.
* *

View File

@ -25,13 +25,14 @@ class WC_Email_Customer_On_Hold_Order extends WC_Email {
public function __construct() { public function __construct() {
$this->id = 'customer_on_hold_order'; $this->id = 'customer_on_hold_order';
$this->customer_email = true; $this->customer_email = true;
$this->title = __( 'Order on-hold', 'woocommerce' ); $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->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' );
$this->subject = __( 'Your {site_title} order receipt from {order_date}', 'woocommerce' );
$this->template_html = 'emails/customer-on-hold-order.php'; $this->template_html = 'emails/customer-on-hold-order.php';
$this->template_plain = 'emails/plain/customer-on-hold-order.php'; $this->template_plain = 'emails/plain/customer-on-hold-order.php';
$this->set_email_strings();
// Triggers for this email // Triggers for this email
add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 ); add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 ); add_action( 'woocommerce_order_status_failed_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
@ -40,6 +41,16 @@ class WC_Email_Customer_On_Hold_Order extends WC_Email {
parent::__construct(); parent::__construct();
} }
/**
* Set email strings.
*/
public function set_email_strings() {
$this->setup_locale();
$this->heading = __( 'Thank you for your order', 'woocommerce' );
$this->subject = __( 'Your {site_title} order receipt from {order_date}', 'woocommerce' );
$this->restore_locale();
}
/** /**
* Trigger the sending of this email. * Trigger the sending of this email.
* *

View File

@ -25,13 +25,14 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
public function __construct() { public function __construct() {
$this->id = 'customer_processing_order'; $this->id = 'customer_processing_order';
$this->customer_email = true; $this->customer_email = true;
$this->title = __( 'Processing order', 'woocommerce' ); $this->title = __( 'Processing order', 'woocommerce' );
$this->description = __( 'This is an order notification sent to customers containing order details after payment.', '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' );
$this->subject = __( 'Your {site_title} order receipt from {order_date}', 'woocommerce' );
$this->template_html = 'emails/customer-processing-order.php'; $this->template_html = 'emails/customer-processing-order.php';
$this->template_plain = 'emails/plain/customer-processing-order.php'; $this->template_plain = 'emails/plain/customer-processing-order.php';
$this->set_email_strings();
// Triggers for this email // Triggers for this email
add_action( 'woocommerce_order_status_on-hold_to_processing_notification', array( $this, 'trigger' ), 10, 2 ); add_action( 'woocommerce_order_status_on-hold_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ), 10, 2 ); add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
@ -40,6 +41,16 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
parent::__construct(); parent::__construct();
} }
/**
* Set email strings.
*/
public function set_email_strings() {
$this->setup_locale();
$this->heading = __( 'Thank you for your order', 'woocommerce' );
$this->subject = __( 'Your {site_title} order receipt from {order_date}', 'woocommerce' );
$this->restore_locale();
}
/** /**
* Trigger the sending of this email. * Trigger the sending of this email.
* *

View File

@ -37,9 +37,10 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
* Constructor. * Constructor.
*/ */
public function __construct() { public function __construct() {
$this->set_email_strings();
$this->customer_email = true; $this->customer_email = true;
$this->set_email_strings();
// Triggers for this email // Triggers for this email
add_action( 'woocommerce_order_fully_refunded_notification', array( $this, 'trigger_full' ), 10, 2 ); add_action( 'woocommerce_order_fully_refunded_notification', array( $this, 'trigger_full' ), 10, 2 );
add_action( 'woocommerce_order_partially_refunded_notification', array( $this, 'trigger_partial' ), 10, 2 ); add_action( 'woocommerce_order_partially_refunded_notification', array( $this, 'trigger_partial' ), 10, 2 );
@ -54,11 +55,13 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
* @param bool $partial_refund * @param bool $partial_refund
*/ */
public function set_email_strings( $partial_refund = false ) { public function set_email_strings( $partial_refund = false ) {
$this->setup_locale();
$this->subject_partial = $this->get_option( 'subject_partial', __( 'Your {site_title} order from {order_date} has been partially refunded', 'woocommerce' ) ); $this->subject_partial = $this->get_option( 'subject_partial', __( 'Your {site_title} order from {order_date} has been partially refunded', 'woocommerce' ) );
$this->subject_full = $this->get_option( 'subject_full', __( 'Your {site_title} order from {order_date} has been refunded', 'woocommerce' ) ); $this->subject_full = $this->get_option( 'subject_full', __( 'Your {site_title} order from {order_date} has been refunded', 'woocommerce' ) );
$this->heading_full = $this->get_option( 'heading_full', __( 'Your order has been fully refunded', 'woocommerce' ) ); $this->heading_full = $this->get_option( 'heading_full', __( 'Your order has been fully refunded', 'woocommerce' ) );
$this->heading_partial = $this->get_option( 'heading_partial', __( 'Your order has been partially refunded', 'woocommerce' ) ); $this->heading_partial = $this->get_option( 'heading_partial', __( 'Your order has been partially refunded', 'woocommerce' ) );
$this->restore_locale();
$this->template_html = 'emails/customer-refunded-order.php'; $this->template_html = 'emails/customer-refunded-order.php';
$this->template_plain = 'emails/plain/customer-refunded-order.php'; $this->template_plain = 'emails/plain/customer-refunded-order.php';

View File

@ -46,15 +46,15 @@ class WC_Email_Customer_Reset_Password extends WC_Email {
public function __construct() { public function __construct() {
$this->id = 'customer_reset_password'; $this->id = 'customer_reset_password';
$this->customer_email = true;
$this->title = __( 'Reset password', 'woocommerce' ); $this->title = __( 'Reset password', 'woocommerce' );
$this->description = __( 'Customer "reset password" emails are sent when customers reset their passwords.', '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_html = 'emails/customer-reset-password.php';
$this->template_plain = 'emails/plain/customer-reset-password.php'; $this->template_plain = 'emails/plain/customer-reset-password.php';
$this->subject = __( 'Password reset for {site_title}', 'woocommerce' ); $this->set_email_strings();
$this->heading = __( 'Password reset instructions', 'woocommerce' );
// Trigger // Trigger
add_action( 'woocommerce_reset_password_notification', array( $this, 'trigger' ), 10, 2 ); add_action( 'woocommerce_reset_password_notification', array( $this, 'trigger' ), 10, 2 );
@ -63,6 +63,16 @@ class WC_Email_Customer_Reset_Password extends WC_Email {
parent::__construct(); parent::__construct();
} }
/**
* Set email strings.
*/
public function set_email_strings() {
$this->setup_locale();
$this->subject = __( 'Password reset for {site_title}', 'woocommerce' );
$this->heading = __( 'Password reset instructions', 'woocommerce' );
$this->restore_locale();
}
/** /**
* Trigger. * Trigger.
* *

View File

@ -243,6 +243,24 @@ 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 ); return str_replace( apply_filters( 'woocommerce_email_format_string_find', $this->find, $this ), apply_filters( 'woocommerce_email_format_string_replace', $this->replace, $this ), $string );
} }
/**
* Set the locale to the store locale for customer emails to make sure emails are in the store language.
*/
public function setup_locale() {
if ( function_exists( 'switch_to_locale' ) && $this->is_customer_email() ) {
switch_to_locale( get_locale() );
}
}
/**
* Restore the locale to the default locale. Use after finished with setup_locale.
*/
public function restore_locale() {
if ( function_exists( 'restore_previous_locale' ) && $this->is_customer_email() ) {
restore_previous_locale();
}
}
/** /**
* Get email subject. * Get email subject.
* *
@ -388,6 +406,7 @@ class WC_Email extends WC_Settings_API {
* @return string * @return string
*/ */
public function get_content() { public function get_content() {
$this->setup_locale();
$this->sending = true; $this->sending = true;
if ( 'plain' === $this->get_email_type() ) { if ( 'plain' === $this->get_email_type() ) {
@ -395,6 +414,7 @@ class WC_Email extends WC_Settings_API {
} else { } else {
$email_content = $this->get_content_html(); $email_content = $this->get_content_html();
} }
$this->restore_locale();
return wordwrap( $email_content, 70 ); return wordwrap( $email_content, 70 );
} }