Merge pull request #15450 from woocommerce/fix/15414

Better locale switching for emails
This commit is contained in:
Mike Jolley 2017-06-06 12:56:26 +01:00 committed by GitHub
commit 4138b2b982
16 changed files with 396 additions and 246 deletions

View File

@ -172,9 +172,7 @@ class WC_Admin_Permalink_Settings {
// We need to save the options ourselves; settings api does not trigger save for the permalinks page.
if ( isset( $_POST['permalink_structure'] ) ) {
if ( function_exists( 'switch_to_locale' ) ) {
switch_to_locale( get_locale() );
}
wc_switch_to_site_locale();
$permalinks = (array) get_option( 'woocommerce_permalinks', array() );
$permalinks['category_base'] = wc_sanitize_permalink( trim( $_POST['woocommerce_product_category_slug'] ) );
@ -210,10 +208,7 @@ class WC_Admin_Permalink_Settings {
}
update_option( 'woocommerce_permalinks', $permalinks );
if ( function_exists( 'restore_current_locale' ) ) {
restore_current_locale();
}
wc_restore_locale();
}
}
}

View File

@ -108,9 +108,7 @@ class WC_Meta_Box_Order_Actions {
if ( strstr( $action, 'send_email_' ) ) {
// Switch back to the site locale.
if ( function_exists( 'switch_to_locale' ) ) {
switch_to_locale( get_locale() );
}
wc_switch_to_site_locale();
do_action( 'woocommerce_before_resend_order_emails', $order );
@ -136,9 +134,7 @@ class WC_Meta_Box_Order_Actions {
do_action( 'woocommerce_after_resend_order_email', $order, $email_to_send );
// Restore user locale.
if ( function_exists( 'restore_current_locale' ) ) {
restore_current_locale();
}
wc_restore_locale();
// Change the post saved message.
add_filter( 'redirect_post_location', array( __CLASS__, 'set_email_sent_message' ) );

View File

@ -26,8 +26,6 @@ class WC_Email_Cancelled_Order extends WC_Email {
$this->id = 'cancelled_order';
$this->title = __( 'Cancelled order', 'woocommerce' );
$this->description = __( 'Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously processing or on-hold).', 'woocommerce' );
$this->heading = __( 'Cancelled order', 'woocommerce' );
$this->subject = __( '[{site_title}] Cancelled order ({order_number})', 'woocommerce' );
$this->template_html = 'emails/admin-cancelled-order.php';
$this->template_plain = 'emails/plain/admin-cancelled-order.php';
@ -42,6 +40,26 @@ class WC_Email_Cancelled_Order extends WC_Email {
$this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( '[{site_title}] Cancelled order ({order_number})', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Cancelled order', 'woocommerce' );
}
/**
* Trigger the sending of this email.
*
@ -65,7 +83,9 @@ class WC_Email_Cancelled_Order extends WC_Email {
return;
}
$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}
/**
@ -123,7 +143,7 @@ class WC_Email_Cancelled_Order extends WC_Email {
'title' => __( 'Subject', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default subject */
'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: %s.', 'woocommerce' ), '<code>' . $this->subject . '</code>' ),
'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: %s.', 'woocommerce' ), '<code>' . $this->get_default_subject() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
@ -132,7 +152,7 @@ class WC_Email_Cancelled_Order extends WC_Email {
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default heading */
'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: %s.', 'woocommerce' ), '<code>' . $this->heading . '</code>' ),
'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: %s.', 'woocommerce' ), '<code>' . $this->get_default_heading() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,

View File

@ -33,29 +33,13 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
$this->template_html = 'emails/customer-completed-order.php';
$this->template_plain = 'emails/plain/customer-completed-order.php';
$this->set_email_strings();
// Triggers for this email
add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ), 10, 2 );
// Other settings
$this->heading_downloadable = $this->get_option( 'heading_downloadable', __( 'Your order is complete - download your files', 'woocommerce' ) );
$this->subject_downloadable = $this->get_option( 'subject_downloadable', __( 'Your {site_title} order from {order_date} is complete - download your files', 'woocommerce' ) );
// Call parent constuctor
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.
*
@ -82,35 +66,29 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
return;
}
$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}
/**
* Get email subject.
*
* @access public
* @since 3.1.0
* @return string
*/
public function get_subject() {
if ( ! empty( $this->object ) && $this->object->has_downloadable_item() ) {
return apply_filters( 'woocommerce_email_subject_customer_completed_order', $this->format_string( $this->subject_downloadable ), $this->object );
} else {
return apply_filters( 'woocommerce_email_subject_customer_completed_order', $this->format_string( $this->subject ), $this->object );
}
public function get_default_subject() {
return __( 'Your {site_title} order from {order_date} is complete', 'woocommerce' );
}
/**
* Get email heading.
*
* @access public
* @since 3.1.0
* @return string
*/
public function get_heading() {
if ( ! empty( $this->object ) && $this->object->has_downloadable_item() ) {
return apply_filters( 'woocommerce_email_heading_customer_completed_order', $this->format_string( $this->heading_downloadable ), $this->object );
} else {
return apply_filters( 'woocommerce_email_heading_customer_completed_order', $this->format_string( $this->heading ), $this->object );
}
public function get_default_heading() {
return __( 'Your order is complete', 'woocommerce' );
}
/**
@ -159,7 +137,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
'title' => __( 'Subject', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default subject */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->subject . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_subject() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
@ -168,25 +146,7 @@ class WC_Email_Customer_Completed_Order extends WC_Email {
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default heading */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->heading . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
),
'subject_downloadable' => array(
'title' => __( 'Subject (downloadable)', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default subject */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->subject_downloadable . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
),
'heading_downloadable' => array(
'title' => __( 'Email heading (downloadable)', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default heading */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->heading_downloadable . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_heading() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,

View File

@ -46,26 +46,72 @@ class WC_Email_Customer_Invoice extends WC_Email {
$this->template_html = 'emails/customer-invoice.php';
$this->template_plain = 'emails/plain/customer-invoice.php';
$this->set_email_strings();
// Call parent constructor
parent::__construct();
$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 );
}
/**
* Set email strings.
* Get email subject.
*
* @since 3.1.0
* @return string
*/
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();
public function get_default_subject( $paid = false ) {
if ( $paid ) {
return __( 'Your {site_title} order from {order_date}', 'woocommerce' );
} else {
return __( 'Invoice for order {order_number} from {order_date}', 'woocommerce' );
}
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading( $paid = false ) {
if ( $paid ) {
return __( 'Order {order_number} details', 'woocommerce' );
} else {
return __( 'Invoice for order {order_number}', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @access public
* @return string
*/
public function get_subject() {
if ( $this->object->has_status( array( 'completed', 'processing' ) ) ) {
$subject = $this->get_option( 'subject_paid', $this->get_default_subject( true ) );
$action = 'woocommerce_email_subject_customer_invoice_paid';
} else {
$subject = $this->get_option( 'subject', $this->get_default_subject() );
$action = 'woocommerce_email_subject_customer_invoice';
}
return apply_filters( $action, $this->format_string( $subject ), $this->object );
}
/**
* Get email heading.
*
* @access public
* @return string
*/
public function get_heading() {
if ( $this->object->has_status( wc_get_is_paid_statuses() ) ) {
$heading = $this->get_option( 'heading_paid', $this->get_default_heading( true ) );
$action = 'woocommerce_email_heading_customer_invoice_paid';
} else {
$heading = $this->get_option( 'heading', $this->get_default_heading() );
$action = 'woocommerce_email_heading_customer_invoice';
}
return apply_filters( $action, $this->format_string( $heading ), $this->object );
}
/**
@ -94,35 +140,9 @@ class WC_Email_Customer_Invoice extends WC_Email {
return;
}
$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
/**
* Get email subject.
*
* @access public
* @return string
*/
public function get_subject() {
if ( $this->object->has_status( wc_get_is_paid_statuses() ) ) {
return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $this->format_string( $this->subject_paid ), $this->object );
} else {
return apply_filters( 'woocommerce_email_subject_customer_invoice', $this->format_string( $this->subject ), $this->object );
}
}
/**
* Get email heading.
*
* @access public
* @return string
*/
public function get_heading() {
if ( $this->object->has_status( array( 'completed', 'processing' ) ) ) {
return apply_filters( 'woocommerce_email_heading_customer_invoice_paid', $this->format_string( $this->heading_paid ), $this->object );
} else {
return apply_filters( 'woocommerce_email_heading_customer_invoice', $this->format_string( $this->heading ), $this->object );
}
$this->restore_locale();
}
/**
@ -166,7 +186,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
'title' => __( 'Email subject', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default subject */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->subject . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_subject() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
@ -175,7 +195,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default heading */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->heading . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_heading() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
@ -184,7 +204,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
'title' => __( 'Email subject (paid)', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default subject */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->subject_paid . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_subject( true ) . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
@ -193,7 +213,7 @@ class WC_Email_Customer_Invoice extends WC_Email {
'title' => __( 'Email heading (paid)', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default heading */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->heading_paid . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_heading( true ) . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,

View File

@ -61,20 +61,28 @@ class WC_Email_Customer_New_Account extends WC_Email {
$this->template_html = 'emails/customer-new-account.php';
$this->template_plain = 'emails/plain/customer-new-account.php';
$this->set_email_strings();
// Call parent constructor
parent::__construct();
}
/**
* Set email strings.
* Get email subject.
*
* @since 3.1.0
* @return string
*/
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();
public function get_default_subject() {
return __( 'Your account on {site_title}', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Welcome to {site_title}', 'woocommerce' );
}
/**
@ -100,7 +108,9 @@ class WC_Email_Customer_New_Account extends WC_Email {
return;
}
$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}
/**

View File

@ -40,8 +40,6 @@ class WC_Email_Customer_Note extends WC_Email {
$this->template_html = 'emails/customer-note.php';
$this->template_plain = 'emails/plain/customer-note.php';
$this->set_email_strings();
// Triggers
add_action( 'woocommerce_new_customer_note_notification', array( $this, 'trigger' ) );
@ -50,13 +48,23 @@ class WC_Email_Customer_Note extends WC_Email {
}
/**
* Set email strings.
* Get email subject.
*
* @since 3.1.0
* @return string
*/
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();
public function get_default_subject() {
return __( 'Note added to your {site_title} order from {order_date}', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'A note has been added to your order', 'woocommerce' );
}
/**
@ -65,9 +73,7 @@ class WC_Email_Customer_Note extends WC_Email {
* @param array $args
*/
public function trigger( $args ) {
if ( ! empty( $args ) ) {
$defaults = array(
'order_id' => '',
'customer_note' => '',
@ -95,7 +101,9 @@ class WC_Email_Customer_Note extends WC_Email {
return;
}
$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}
/**

View File

@ -31,8 +31,6 @@ class WC_Email_Customer_On_Hold_Order extends WC_Email {
$this->template_html = 'emails/customer-on-hold-order.php';
$this->template_plain = 'emails/plain/customer-on-hold-order.php';
$this->set_email_strings();
// Triggers for this email
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 );
@ -42,13 +40,23 @@ class WC_Email_Customer_On_Hold_Order extends WC_Email {
}
/**
* Set email strings.
* Get email subject.
*
* @since 3.1.0
* @return string
*/
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();
public function get_default_subject() {
return __( 'Your {site_title} order receipt from {order_date}', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Thank you for your order', 'woocommerce' );
}
/**
@ -77,7 +85,9 @@ class WC_Email_Customer_On_Hold_Order extends WC_Email {
return;
}
$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}
/**

View File

@ -31,8 +31,6 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
$this->template_html = 'emails/customer-processing-order.php';
$this->template_plain = 'emails/plain/customer-processing-order.php';
$this->set_email_strings();
// Triggers for this email
add_action( 'woocommerce_order_status_failed_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_on-hold_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
@ -43,13 +41,23 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
}
/**
* Set email strings.
* Get email subject.
*
* @since 3.1.0
* @return string
*/
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();
public function get_default_subject() {
return __( 'Your {site_title} order receipt from {order_date}', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Thank you for your order', 'woocommerce' );
}
/**
@ -78,7 +86,9 @@ class WC_Email_Customer_Processing_Order extends WC_Email {
return;
}
$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}
/**

View File

@ -38,8 +38,11 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
*/
public function __construct() {
$this->customer_email = true;
$this->set_email_strings();
$this->id = 'customer_refunded_order';
$this->title = __( 'Refunded order', 'woocommerce' );
$this->description = __( 'Order refunded emails are sent to customers when their orders are refunded.', 'woocommerce' );
$this->template_html = 'emails/customer-refunded-order.php';
$this->template_plain = 'emails/plain/customer-refunded-order.php';
// Triggers for this email
add_action( 'woocommerce_order_fully_refunded_notification', array( $this, 'trigger_full' ), 10, 2 );
@ -50,37 +53,69 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
}
/**
* Set email strings.
* Get email subject.
*
* @param bool $partial_refund
* @since 3.1.0
* @return string
*/
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_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_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_plain = 'emails/plain/customer-refunded-order.php';
if ( $partial_refund ) {
$this->id = 'customer_partially_refunded_order';
$this->title = __( 'Partially refunded order', 'woocommerce' );
$this->description = __( 'Order partially refunded emails are sent to customers when their orders are partially refunded.', 'woocommerce' );
$this->heading = $this->heading_partial;
$this->subject = $this->subject_partial;
public function get_default_subject( $partial = false ) {
if ( $partial ) {
return __( 'Your {site_title} order from {order_date} has been partially refunded', 'woocommerce' );
} else {
$this->id = 'customer_refunded_order';
$this->title = __( 'Refunded order', 'woocommerce' );
$this->description = __( 'Order refunded emails are sent to customers when their orders are marked refunded.', 'woocommerce' );
$this->heading = $this->heading_full;
$this->subject = $this->subject_full;
return __( 'Your {site_title} order from {order_date} has been refunded', 'woocommerce' );
}
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading( $partial = false ) {
if ( $partial ) {
return __( 'Order {order_number} details', 'woocommerce' );
} else {
return __( 'Your order has been partially refunded', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @access public
* @return string
*/
public function get_subject() {
if ( $this->partial_refund ) {
$subject = $this->get_option( 'subject_partial', $this->get_default_subject( true ) );
} else {
$subject = $this->get_option( 'subject_full', $this->get_default_heading() );
}
return apply_filters( 'woocommerce_email_subject_customer_refunded_order', $this->format_string( $subject ), $this->object );
}
/**
* Get email heading.
*
* @access public
* @return string
*/
public function get_heading() {
if ( $this->partial_refund ) {
$heading = $this->get_option( 'heading_partial', $this->get_default_heading( true ) );
} else {
$heading = $this->get_option( 'heading_full', $this->get_default_heading() );
}
return apply_filters( 'woocommerce_email_heading_customer_refunded_order', $this->format_string( $heading ), $this->object );
}
/**
* Set email strings.
* @deprecated 3.1.0 Unused.
*/
public function set_email_strings( $partial_refund = false ) {}
/**
* Full refund notification.
*
@ -110,7 +145,7 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
*/
public function trigger( $order_id, $partial_refund = false, $refund_id = null ) {
$this->partial_refund = $partial_refund;
$this->set_email_strings( $partial_refund );
$this->id = $this->partial_refund ? 'customer_partially_refunded_order' : 'customer_refunded_order';
if ( $order_id ) {
$this->object = wc_get_order( $order_id );
@ -133,27 +168,9 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
return;
}
$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
/**
* Get email subject.
*
* @access public
* @return string
*/
public function get_subject() {
return apply_filters( 'woocommerce_email_subject_customer_refunded_order', $this->format_string( $this->subject ), $this->object );
}
/**
* Get email heading.
*
* @access public
* @return string
*/
public function get_heading() {
return apply_filters( 'woocommerce_email_heading_customer_refunded_order', $this->format_string( $this->heading ), $this->object );
$this->restore_locale();
}
/**
@ -206,36 +223,32 @@ class WC_Email_Customer_Refunded_Order extends WC_Email {
'title' => __( 'Full refund subject', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default subject */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->subject_full . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_subject() . '</code>' ),
'placeholder' => '',
'default' => $this->subject_full,
'desc_tip' => true,
),
'subject_partial' => array(
'title' => __( 'Partial refund subject', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default subject */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->subject_partial . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_subject( true ) . '</code>' ),
'placeholder' => '',
'default' => $this->subject_partial,
'desc_tip' => true,
),
'heading_full' => array(
'title' => __( 'Full refund email heading', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default heading */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->heading_full . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_heading() . '</code>' ),
'placeholder' => '',
'default' => $this->heading_full,
'desc_tip' => true,
),
'heading_partial' => array(
'title' => __( 'Partial refund email heading', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default heading */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->heading_partial . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_heading( true ) . '</code>' ),
'placeholder' => '',
'default' => $this->heading_partial,
'desc_tip' => true,
),
'email_type' => array(

View File

@ -54,8 +54,6 @@ class WC_Email_Customer_Reset_Password extends WC_Email {
$this->template_html = 'emails/customer-reset-password.php';
$this->template_plain = 'emails/plain/customer-reset-password.php';
$this->set_email_strings();
// Trigger
add_action( 'woocommerce_reset_password_notification', array( $this, 'trigger' ), 10, 2 );
@ -64,13 +62,23 @@ class WC_Email_Customer_Reset_Password extends WC_Email {
}
/**
* Set email strings.
* Get email subject.
*
* @since 3.1.0
* @return string
*/
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();
public function get_default_subject() {
return __( 'Password reset for {site_title}', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Password reset instructions', 'woocommerce' );
}
/**
@ -93,8 +101,9 @@ class WC_Email_Customer_Reset_Password extends WC_Email {
return;
}
$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}
/**

View File

@ -26,8 +26,6 @@ class WC_Email_Failed_Order extends WC_Email {
$this->id = 'failed_order';
$this->title = __( 'Failed order', 'woocommerce' );
$this->description = __( 'Failed order emails are sent to chosen recipient(s) when orders have been marked failed (if they were previously processing or on-hold).', 'woocommerce' );
$this->heading = __( 'Failed order', 'woocommerce' );
$this->subject = __( '[{site_title}] Failed order ({order_number})', 'woocommerce' );
$this->template_html = 'emails/admin-failed-order.php';
$this->template_plain = 'emails/plain/admin-failed-order.php';
@ -42,6 +40,26 @@ class WC_Email_Failed_Order extends WC_Email {
$this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( '[{site_title}] Failed order ({order_number})', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Failed order', 'woocommerce' );
}
/**
* Trigger the sending of this email.
*
@ -65,7 +83,9 @@ class WC_Email_Failed_Order extends WC_Email {
return;
}
$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}
/**
@ -121,7 +141,7 @@ class WC_Email_Failed_Order extends WC_Email {
'subject' => array(
'title' => __( 'Subject', 'woocommerce' ),
'type' => 'text',
'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: %s.', 'woocommerce' ), '<code>' . $this->subject . '</code>' ),
'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: %s.', 'woocommerce' ), '<code>' . $this->get_default_subject() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
@ -129,7 +149,7 @@ class WC_Email_Failed_Order extends WC_Email {
'heading' => array(
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: %s.', 'woocommerce' ), '<code>' . $this->heading . '</code>' ),
'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: %s.', 'woocommerce' ), '<code>' . $this->get_default_heading() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,

View File

@ -26,8 +26,6 @@ class WC_Email_New_Order extends WC_Email {
$this->id = 'new_order';
$this->title = __( 'New order', 'woocommerce' );
$this->description = __( 'New order emails are sent to chosen recipient(s) when a new order is received.', 'woocommerce' );
$this->heading = __( 'New customer order', 'woocommerce' );
$this->subject = __( '[{site_title}] New customer order ({order_number}) - {order_date}', 'woocommerce' );
$this->template_html = 'emails/admin-new-order.php';
$this->template_plain = 'emails/plain/admin-new-order.php';
@ -46,6 +44,26 @@ class WC_Email_New_Order extends WC_Email {
$this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( '[{site_title}] New customer order ({order_number}) - {order_date}', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'New customer order', 'woocommerce' );
}
/**
* Trigger the sending of this email.
*
@ -69,7 +87,9 @@ class WC_Email_New_Order extends WC_Email {
return;
}
$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}
/**
@ -126,7 +146,7 @@ class WC_Email_New_Order extends WC_Email {
'subject' => array(
'title' => __( 'Subject', 'woocommerce' ),
'type' => 'text',
'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: %s.', 'woocommerce' ), '<code>' . $this->subject . '</code>' ),
'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: %s.', 'woocommerce' ), '<code>' . $this->get_default_subject() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
@ -134,7 +154,7 @@ class WC_Email_New_Order extends WC_Email {
'heading' => array(
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: %s.', 'woocommerce' ), '<code>' . $this->heading . '</code>' ),
'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: %s.', 'woocommerce' ), '<code>' . $this->get_default_heading() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,

View File

@ -45,6 +45,26 @@ class WC_Email extends WC_Settings_API {
*/
public $description;
/**
* Default heading.
*
* Supported for backwards compatibility but we recommend overloading the
* get_default_x methods instead so localication can be done when needed.
*
* @var string
*/
public $heading = '';
/**
* Default subject.
*
* Supported for backwards compatibility but we recommend overloading the
* get_default_x methods instead so localication can be done when needed.
*
* @var string
*/
public $subject = '';
/**
* Plain text template path.
* @var string
@ -69,18 +89,6 @@ class WC_Email extends WC_Settings_API {
*/
public $recipient;
/**
* Heading for the email content.
* @var string
*/
public $heading;
/**
* Subject for the email.
* @var string
*/
public $subject;
/**
* Object this email is for, for example a customer, product, or email.
* @var object|bool
@ -204,8 +212,6 @@ class WC_Email extends WC_Settings_API {
}
// Settings
$this->heading = $this->get_option( 'heading', $this->heading );
$this->subject = $this->get_option( 'subject', $this->subject );
$this->email_type = $this->get_option( 'email_type' );
$this->enabled = $this->get_option( 'enabled' );
@ -247,8 +253,8 @@ class WC_Email extends WC_Settings_API {
* 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() );
if ( $this->is_customer_email() ) {
wc_switch_to_site_locale();
}
}
@ -256,18 +262,38 @@ class WC_Email extends WC_Settings_API {
* 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();
if ( $this->is_customer_email() ) {
wc_restore_locale();
}
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return $this->subject;
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return $this->heading;
}
/**
* Get email subject.
*
* @return string
*/
public function get_subject() {
return apply_filters( 'woocommerce_email_subject_' . $this->id, $this->format_string( $this->subject ), $this->object );
return apply_filters( 'woocommerce_email_subject_' . $this->id, $this->format_string( $this->get_option( 'subject', $this->get_default_subject() ) ), $this->object );
}
/**
@ -276,7 +302,7 @@ class WC_Email extends WC_Settings_API {
* @return string
*/
public function get_heading() {
return apply_filters( 'woocommerce_email_heading_' . $this->id, $this->format_string( $this->heading ), $this->object );
return apply_filters( 'woocommerce_email_heading_' . $this->id, $this->format_string( $this->get_option( 'heading', $this->get_default_heading() ) ), $this->object );
}
/**
@ -406,7 +432,6 @@ 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() ) {
@ -414,7 +439,6 @@ class WC_Email extends WC_Settings_API {
} else {
$email_content = $this->get_content_html();
}
$this->restore_locale();
return wordwrap( $email_content, 70 );
}
@ -513,7 +537,7 @@ class WC_Email extends WC_Settings_API {
'title' => __( 'Email subject', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default subject */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->subject . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_subject() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
@ -522,7 +546,7 @@ class WC_Email extends WC_Settings_API {
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
/* translators: %s: default heading */
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->heading . '</code>' ),
'description' => sprintf( __( 'Defaults to %s', 'woocommerce' ), '<code>' . $this->get_default_heading() . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,

View File

@ -1606,8 +1606,8 @@ function wc_list_pluck( $list, $callback_or_field, $index_key = null ) {
* @return array
*/
function wc_get_permalink_structure() {
if ( function_exists( 'switch_to_locale' ) && did_action( 'admin_init' ) ) {
switch_to_locale( get_locale() );
if ( did_action( 'admin_init' ) ) {
wc_switch_to_site_locale();
}
$permalinks = wp_parse_args( (array) get_option( 'woocommerce_permalinks', array() ), array(
@ -1624,12 +1624,46 @@ function wc_get_permalink_structure() {
$permalinks['tag_rewrite_slug'] = untrailingslashit( empty( $permalinks['tag_base'] ) ? _x( 'product-tag', 'slug', 'woocommerce' ) : $permalinks['tag_base'] );
$permalinks['attribute_rewrite_slug'] = untrailingslashit( empty( $permalinks['attribute_base'] ) ? '' : $permalinks['attribute_base'] );
if ( function_exists( 'restore_current_locale' ) && did_action( 'admin_init' ) ) {
restore_current_locale();
if ( did_action( 'admin_init' ) ) {
wc_restore_locale();
}
return $permalinks;
}
/**
* Switch WooCommerce to site language.
*
* @since 3.1.0
*/
function wc_switch_to_site_locale() {
if ( function_exists( 'switch_to_locale' ) ) {
switch_to_locale( $switch_to_locale );
// Filter on plugin_locale so load_plugin_textdomain loads the correct locale.
add_filter( 'plugin_locale', 'get_locale' );
// Init WC locale.
WC()->load_plugin_textdomain();
}
}
/**
* Switch WooCommerce language to original.
*
* @since 3.1.0
*/
function wc_restore_locale() {
if ( function_exists( 'restore_previous_locale' ) ) {
restore_previous_locale();
// Remove filter.
remove_filter( 'plugin_locale', 'get_locale' );
// Init WC locale.
WC()->load_plugin_textdomain();
}
}
/**
* Convert plaintext phone number to clickable phone number.
*

View File

@ -461,6 +461,7 @@ final class WooCommerce {
$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
$locale = apply_filters( 'plugin_locale', $locale, 'woocommerce' );
unload_textdomain( 'woocommerce' );
load_textdomain( 'woocommerce', WP_LANG_DIR . '/woocommerce/woocommerce-' . $locale . '.mo' );
load_plugin_textdomain( 'woocommerce', false, plugin_basename( dirname( __FILE__ ) ) . '/i18n/languages' );
}