first commit

This commit is contained in:
User A0264400
2026-04-01 23:20:16 +03:00
commit a766acdc90
23071 changed files with 4933189 additions and 0 deletions

View File

@@ -0,0 +1,247 @@
<?php
/**
* Class WC_Email_Cancelled_Order file.
*
* @package WooCommerce\Emails
*/
use Automattic\WooCommerce\Utilities\FeaturesUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WC_Email_Cancelled_Order', false ) ) :
/**
* Cancelled Order Email.
*
* An email sent to the admin when an order is cancelled.
*
* @class WC_Email_Cancelled_Order
* @version 2.2.7
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Cancelled_Order extends WC_Email {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'cancelled_order';
$this->title = __( 'Cancelled order', 'woocommerce' );
$this->email_group = 'orders';
$this->template_html = 'emails/admin-cancelled-order.php';
$this->template_plain = 'emails/plain/admin-cancelled-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
'{order_billing_full_name}' => '',
);
// Triggers for this email.
add_action( 'woocommerce_order_status_processing_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_on-hold_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 );
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Receive an email notification when an order that was processing or on hold gets cancelled', 'woocommerce' )
: __( 'Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously processing or on-hold).', 'woocommerce' );
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'Canceled order', 'woocommerce' );
$this->description = __( 'Notifies admins when an order that was processing or on hold has been canceled.', 'woocommerce' );
}
// Other settings.
$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}]: Order #{order_number} has been cancelled', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return $this->email_improvements_enabled
? __( 'Order cancelled: #{order_number}', 'woocommerce' )
: __( 'Order Cancelled: #{order_number}', 'woocommerce' );
}
/**
* 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->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->placeholders['{order_billing_full_name}'] = $this->object->get_formatted_billing_full_name();
}
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();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => true,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => true,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
return wc_get_template_html(
$this->template_block_content,
array(
'order' => $this->object,
'sent_to_admin' => true,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return __( 'Thanks for reading.', 'woocommerce' );
}
/**
* Initialise settings form fields.
*/
public function init_form_fields() {
/* translators: %s: list of placeholders */
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable this email notification', 'woocommerce' ),
'default' => 'yes',
),
'recipient' => array(
'title' => __( 'Recipient(s)', 'woocommerce' ),
'type' => 'text',
/* translators: %s: admin email */
'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to %s.', 'woocommerce' ), '<code>' . esc_attr( get_option( 'admin_email' ) ) . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
),
'subject' => array(
'title' => __( 'Subject', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject(),
'default' => '',
),
'heading' => array(
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading(),
'default' => '',
),
'additional_content' => array(
'title' => __( 'Additional content', 'woocommerce' ),
'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text,
'css' => 'width:400px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => $this->get_default_additional_content(),
'desc_tip' => true,
),
'email_type' => array(
'title' => __( 'Email type', 'woocommerce' ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
'default' => 'html',
'class' => 'email_type wc-enhanced-select',
'options' => $this->get_email_type_options(),
'desc_tip' => true,
),
);
if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
$this->form_fields['cc'] = $this->get_cc_field();
$this->form_fields['bcc'] = $this->get_bcc_field();
}
if ( $this->block_email_editor_enabled ) {
$this->form_fields['preheader'] = $this->get_preheader_field();
}
}
}
endif;
return new WC_Email_Cancelled_Order();

View File

@@ -0,0 +1,237 @@
<?php
/**
* Class WC_Email_Customer_Cancelled_Order file.
*
* @package WooCommerce\Emails
*/
use Automattic\WooCommerce\Utilities\FeaturesUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WC_Email_Customer_Cancelled_Order', false ) ) :
/**
* Cancelled Order Email for Customers.
*
* An email sent to the customer when an order is cancelled.
*
* @class WC_Email_Customer_Cancelled_Order
* @version 1.0.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_Cancelled_Order extends WC_Email {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_cancelled_order';
$this->customer_email = true;
$this->title = __( 'Cancelled order', 'woocommerce' );
$this->email_group = 'order-changes';
$this->template_html = 'emails/customer-cancelled-order.php';
$this->template_plain = 'emails/plain/customer-cancelled-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
'{order_billing_full_name}' => '',
);
// Triggers for this email.
add_action( 'woocommerce_order_status_processing_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_on-hold_to_cancelled_notification', array( $this, 'trigger' ), 10, 2 );
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Send an email to customers notifying them when their order has been cancelled', 'woocommerce' )
: __( 'Cancelled order emails are sent to customers when their orders have been marked cancelled (if they were previously processing or on-hold).', 'woocommerce' );
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'Order cancelled', 'woocommerce' );
$this->description = __( 'Notifies customers when their order has been cancelled.', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @since 1.0.0
* @return string
*/
public function get_default_subject() {
return __( '[{site_title}]: Your order #{order_number} has been cancelled', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 1.0.0
* @return string
*/
public function get_default_heading() {
return $this->email_improvements_enabled
? __( 'Order cancelled: #{order_number}', 'woocommerce' )
: __( 'Order Cancelled: #{order_number}', 'woocommerce' );
}
/**
* 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();
$this->placeholders['{order_billing_full_name}'] = $this->object->get_formatted_billing_full_name();
}
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();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
return wc_get_template_html(
$this->template_block_content,
array(
'order' => $this->object,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 1.0.0
* @return string
*/
public function get_default_additional_content() {
return __( 'We hope to see you again soon.', 'woocommerce' );
}
/**
* Initialise settings form fields.
*/
public function init_form_fields() {
/* translators: %s: list of placeholders */
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable this email notification', 'woocommerce' ),
'default' => 'no',
),
'subject' => array(
'title' => __( 'Subject', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject(),
'default' => '',
),
'heading' => array(
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading(),
'default' => '',
),
'additional_content' => array(
'title' => __( 'Additional content', 'woocommerce' ),
'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text,
'css' => 'width:400px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => $this->get_default_additional_content(),
'desc_tip' => true,
),
'email_type' => array(
'title' => __( 'Email type', 'woocommerce' ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
'default' => 'html',
'class' => 'email_type wc-enhanced-select',
'options' => $this->get_email_type_options(),
'desc_tip' => true,
),
);
if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
$this->form_fields['cc'] = $this->get_cc_field();
$this->form_fields['bcc'] = $this->get_bcc_field();
}
if ( $this->block_email_editor_enabled ) {
$this->form_fields['preheader'] = $this->get_preheader_field();
}
}
}
endif;
return new WC_Email_Customer_Cancelled_Order();

View File

@@ -0,0 +1,162 @@
<?php
/**
* Class WC_Email_Customer_Completed_Order file.
*
* @package WooCommerce\Emails
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_Completed_Order', false ) ) :
/**
* Customer Completed Order Email.
*
* Order complete emails are sent to the customer when the order is marked complete and usual indicates that the order has been shipped.
*
* @class WC_Email_Customer_Completed_Order
* @version 2.0.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_Completed_Order extends WC_Email {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_completed_order';
$this->customer_email = true;
$this->title = __( 'Completed order', 'woocommerce' );
$this->email_group = 'order-updates';
$this->template_html = 'emails/customer-completed-order.php';
$this->template_plain = 'emails/plain/customer-completed-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Triggers for this email.
add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ), 10, 2 );
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Send an email to customers notifying them that their order is complete and has been shipped', 'woocommerce' )
: __( 'Order complete emails are sent to customers when their orders are marked completed and usually indicate that their orders have been shipped.', 'woocommerce' );
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'Order fulfilled', 'woocommerce' );
$this->description = __( 'Notifies customers when their order has been shipped.', 'woocommerce' );
}
}
/**
* 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();
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return $this->email_improvements_enabled
? __( 'Your order from {site_title} is on its way!', 'woocommerce' )
: __( 'Your {site_title} order is now complete', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return $this->email_improvements_enabled
? __( 'Good things are heading your way!', 'woocommerce' )
: __( 'Thanks for shopping with us', 'woocommerce' );
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return $this->email_improvements_enabled
? __( 'Thanks again! If you need any help with your order, please contact us at {store_email}.', 'woocommerce' )
: __( 'Thanks for shopping with us.', 'woocommerce' );
}
}
endif;
return new WC_Email_Customer_Completed_Order();

View File

@@ -0,0 +1,159 @@
<?php
/**
* Class WC_Email_Customer_Failed_Order file.
*
* @package WooCommerce\Emails
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_Failed_Order', false ) ) :
/**
* Customer failed Order Email.
*
* Order failed emails are sent to the customer when their order are marked as failed.
*
* @class WC_Email_Customer_Failed_Order
* @version 2.0.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_Failed_Order extends WC_Email {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_failed_order';
$this->customer_email = true;
$this->title = __( 'Failed order', 'woocommerce' );
$this->email_group = 'order-changes';
$this->template_html = 'emails/customer-failed-order.php';
$this->template_plain = 'emails/plain/customer-failed-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Triggers for this email.
add_action( 'woocommerce_order_status_failed_notification', array( $this, 'trigger' ), 10, 2 );
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Receive an email notification when an order that was processing or on hold fails', 'woocommerce' )
: __( 'Order failed emails are sent to customers when their orders are marked as failed.', 'woocommerce' );
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'Order failed', 'woocommerce' );
$this->description = __( 'Notifies customers when their order has failed.', 'woocommerce' );
}
}
/**
* 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();
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( 'Your order at {site_title} was unsuccessful', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Sorry, your order was unsuccessful', 'woocommerce' );
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'blogname' => $this->get_blogname(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'blogname' => $this->get_blogname(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return $this->email_improvements_enabled
? __( 'If you need any help with your order, please contact us at {store_email}.', 'woocommerce' )
: '';
}
}
endif;
return new WC_Email_Customer_Failed_Order();

View File

@@ -0,0 +1,234 @@
<?php
/**
* Class WC_Email_Customer_Fulfillment_Created file.
*
* @package WooCommerce\Emails
*/
use Automattic\WooCommerce\Internal\Fulfillments\Fulfillment;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_Fulfillment_Created', false ) ) :
/**
* Customer Fulfillment Created Email.
*
* Fulfillment created emails are sent to the customer when the merchant creates a fulfillment for the order, and marks it as fulfilled. The notification isnt sent for draft fulfillments.
*
* @class WC_Email_Customer_Fulfillment_Created
* @version 1.0.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_Fulfillment_Created extends WC_Email {
/**
* Fulfillment object.
*
* @var Fulfillment|null
*/
private $fulfillment;
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_fulfillment_created';
$this->customer_email = true;
$this->title = __( 'Fulfillment created', 'woocommerce' );
$this->email_group = 'order-updates';
$this->template_html = 'emails/customer-fulfillment-created.php';
$this->template_plain = 'emails/plain/customer-fulfillment-created.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Triggers for this email.
add_action( 'woocommerce_fulfillment_created_notification', array( $this, 'trigger' ), 10, 3 );
// Call parent constructor.
parent::__construct();
$this->description = __( 'Fulfillment created emails are sent to the customer when the merchant creates a fulfillment for the order, and marks it as fulfilled. The notification isnt sent for draft fulfillments.', 'woocommerce' );
$this->template_block_content = 'emails/block/general-block-content-for-fulfillment-emails.php';
}
/**
* Trigger the sending of this email.
*
* @param int $order_id The order ID.
* @param Fulfillment $fulfillment The fulfillment.
* @param WC_Order|false $order Order object.
*/
public function trigger( $order_id, $fulfillment, $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->fulfillment = $fulfillment;
$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();
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( 'An item from {site_title} order {order_number} has been fulfilled!', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Your item is on the way!', 'woocommerce' );
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
$this->maybe_init_fulfillment_for_preview( $this->object );
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'fulfillment' => $this->fulfillment,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
$this->maybe_init_fulfillment_for_preview( $this->object );
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'fulfillment' => $this->fulfillment,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
$this->maybe_init_fulfillment_for_preview( $this->object );
return wc_get_template_html(
$this->template_block_content,
array(
'order' => $this->object,
'fulfillment' => $this->fulfillment,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return __( 'Please note that couriers may need some time to provide the latest shipping information.', 'woocommerce' );
}
/**
* Initialize fulfillment for email preview.
*
* This method sets up a dummy fulfillment object when the email is being previewed in the admin.
*
* @param WC_Order $order The order object.
*
* @since 10.1.0
*/
private function maybe_init_fulfillment_for_preview( $order ) {
/**
* Filter to determine if this is an email preview.
*
* @since 9.8.0
*/
$is_email_preview = apply_filters( 'woocommerce_is_email_preview', false );
if ( $is_email_preview ) {
// If this is a preview, we need to set up a dummy fulfillment object.
$this->fulfillment = new Fulfillment();
$this->fulfillment->set_items(
array_map(
function ( $item ) {
return array(
'item_id' => $item->get_id(),
'qty' => 1,
);
},
$order->get_items()
)
);
// Some private meta data to simulate a real fulfillment.
$this->fulfillment->add_meta_data( '_tracking_number', '123456789' );
$this->fulfillment->add_meta_data( '_shipment_provider', 'dhl' );
$this->fulfillment->add_meta_data( '_tracking_url', 'https://www.dhl.com/tracking/123456789' );
// Some public data to simulate a real fulfillment.
$this->fulfillment->add_meta_data( 'service', 'Standard Shipping' );
$this->fulfillment->add_meta_data( 'expected_delivery', '2025-06-30' );
// Add translations for metadata keys.
add_filter(
'woocommerce_fulfillment_meta_key_translations',
function ( $keys ) {
$keys['service'] = __( 'Service', 'woocommerce' );
$keys['expected_delivery'] = __( 'Expected Delivery', 'woocommerce' );
return $keys;
}
);
}
}
}
endif;
return new WC_Email_Customer_Fulfillment_Created();

View File

@@ -0,0 +1,219 @@
<?php
/**
* Class WC_Email_Customer_Fulfillment_Deleted file.
*
* @package WooCommerce\Emails
*/
use Automattic\WooCommerce\Internal\Fulfillments\Fulfillment;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_Fulfillment_Deleted', false ) ) :
/**
* Customer Fulfillment Deleted Email.
*
* Fulfillment deleted emails are sent to the customer when the merchant cancels an already fulfilled fulfillment. The notification isnt sent for draft fulfillments.
*
* @class WC_Email_Customer_Fulfillment_Deleted
* @version 1.0.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_Fulfillment_Deleted extends WC_Email {
/**
* Fulfillment object.
*
* @var Fulfillment|null
*/
private $fulfillment;
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_fulfillment_deleted';
$this->customer_email = true;
$this->title = __( 'Fulfillment deleted', 'woocommerce' );
$this->email_group = 'order-updates';
$this->template_html = 'emails/customer-fulfillment-deleted.php';
$this->template_plain = 'emails/plain/customer-fulfillment-deleted.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Triggers for this email.
add_action( 'woocommerce_fulfillment_deleted_notification', array( $this, 'trigger' ), 10, 3 );
// Call parent constructor.
parent::__construct();
$this->description = __( 'Fulfillment deleted emails are sent to the customer when the merchant cancels an already fulfilled fulfillment. The notification isnt sent for draft fulfillments.', 'woocommerce' );
$this->template_block_content = 'emails/block/general-block-content-for-fulfillment-emails.php';
}
/**
* Trigger the sending of this email.
*
* @param int $order_id The order ID.
* @param Fulfillment $fulfillment The fulfillment.
* @param WC_Order|false $order Order object.
*/
public function trigger( $order_id, $fulfillment, $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->fulfillment = $fulfillment;
$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();
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( 'A shipment from {site_title} order {order_number} has been cancelled', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'One of your shipments has been removed', 'woocommerce' );
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
$this->maybe_init_fulfillment_for_preview( $this->object );
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'fulfillment' => $this->fulfillment,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
$this->maybe_init_fulfillment_for_preview( $this->object );
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'fulfillment' => $this->fulfillment,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
$this->maybe_init_fulfillment_for_preview( $this->object );
return wc_get_template_html(
$this->template_block_content,
array(
'order' => $this->object,
'fulfillment' => $this->fulfillment,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return __( 'If you have any questions or notice anything unexpected, feel free to reach out to our support team through your account or reply to this email.', 'woocommerce' );
}
/**
* Initialize fulfillment for email preview.
*
* This method sets up a dummy fulfillment object when the email is being previewed in the admin.
*
* @param WC_Order $order The order object.
*
* @since 10.1.0
*/
private function maybe_init_fulfillment_for_preview( $order ) {
/**
* Filter to determine if this is an email preview.
*
* @since 9.8.0
*/
$is_email_preview = apply_filters( 'woocommerce_is_email_preview', false );
if ( $is_email_preview ) {
// If this is a preview, we need to set up a dummy fulfillment object.
$this->fulfillment = new Fulfillment();
$this->fulfillment->set_items(
array_map(
function ( $item ) {
return array(
'item_id' => $item->get_id(),
'qty' => 1,
);
},
$order->get_items()
)
);
// Set the deleted status.
$this->fulfillment->set_date_deleted( gmdate( 'Y-m-d H:i:s' ) );
}
}
}
endif;
return new WC_Email_Customer_Fulfillment_Deleted();

View File

@@ -0,0 +1,234 @@
<?php
/**
* Class WC_Email_Customer_Fulfillment_Updated file.
*
* @package WooCommerce\Emails
*/
use Automattic\WooCommerce\Internal\Fulfillments\Fulfillment;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_Fulfillment_Updated', false ) ) :
/**
* Customer Fulfillment Updated Email.
*
* Fulfillment updated emails are sent to the customer when the merchant updates a fulfillment for the order. The notification isnt sent for draft fulfillments.
*
* @class WC_Email_Customer_Fulfillment_Updated
* @version 1.0.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_Fulfillment_Updated extends WC_Email {
/**
* Fulfillment object.
*
* @var Fulfillment|null
*/
private $fulfillment;
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_fulfillment_updated';
$this->customer_email = true;
$this->title = __( 'Fulfillment updated', 'woocommerce' );
$this->email_group = 'order-updates';
$this->template_html = 'emails/customer-fulfillment-updated.php';
$this->template_plain = 'emails/plain/customer-fulfillment-updated.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Triggers for this email.
add_action( 'woocommerce_fulfillment_updated_notification', array( $this, 'trigger' ), 10, 3 );
// Call parent constructor.
parent::__construct();
$this->description = __( 'Fulfillment updated emails are sent to the customer when the merchant updates a fulfillment for the order. The notification isnt sent for draft fulfillments.', 'woocommerce' );
$this->template_block_content = 'emails/block/general-block-content-for-fulfillment-emails.php';
}
/**
* Trigger the sending of this email.
*
* @param int $order_id The order ID.
* @param Fulfillment $fulfillment The fulfillment.
* @param WC_Order|false $order Order object.
*/
public function trigger( $order_id, $fulfillment, $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->fulfillment = $fulfillment;
$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();
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( 'A shipment from {site_title} order {order_number} has been updated', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Your shipment has been updated', 'woocommerce' );
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
$this->maybe_init_fulfillment_for_preview( $this->object );
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'fulfillment' => $this->fulfillment,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
$this->maybe_init_fulfillment_for_preview( $this->object );
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'fulfillment' => $this->fulfillment,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
$this->maybe_init_fulfillment_for_preview( $this->object );
return wc_get_template_html(
$this->template_block_content,
array(
'order' => $this->object,
'fulfillment' => $this->fulfillment,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return __( 'If anything looks off or you have questions, feel free to contact our support team.', 'woocommerce' );
}
/**
* Initialize fulfillment for email preview.
*
* This method sets up a dummy fulfillment object when the email is being previewed in the admin.
*
* @param WC_Order $order The order object.
*
* @since 10.1.0
*/
private function maybe_init_fulfillment_for_preview( $order ) {
/**
* Filter to determine if this is an email preview.
*
* @since 9.8.0
*/
$is_email_preview = apply_filters( 'woocommerce_is_email_preview', false );
if ( $is_email_preview ) {
// If this is a preview, we need to set up a dummy fulfillment object.
$this->fulfillment = new Fulfillment();
$this->fulfillment->set_items(
array_map(
function ( $item ) {
return array(
'item_id' => $item->get_id(),
'qty' => 1,
);
},
$order->get_items()
)
);
// Some private meta data to simulate a real fulfillment.
$this->fulfillment->add_meta_data( '_tracking_number', '123456789' );
$this->fulfillment->add_meta_data( '_shipment_provider', 'dhl' );
$this->fulfillment->add_meta_data( '_tracking_url', 'https://www.dhl.com/tracking/123456789' );
// Some public data to simulate a real fulfillment.
$this->fulfillment->add_meta_data( 'service', 'Standard Shipping' );
$this->fulfillment->add_meta_data( 'expected_delivery', '2025-06-30' );
// Add translations for metadata keys.
add_filter(
'woocommerce_fulfillment_meta_key_translations',
function ( $keys ) {
$keys['service'] = __( 'Service', 'woocommerce' );
$keys['expected_delivery'] = __( 'Expected Delivery', 'woocommerce' );
return $keys;
}
);
}
}
}
endif;
return new WC_Email_Customer_Fulfillment_Updated();

View File

@@ -0,0 +1,271 @@
<?php
/**
* Class WC_Email_Customer_Invoice file.
*
* @package WooCommerce\Emails
*/
use Automattic\WooCommerce\Enums\OrderStatus;
use Automattic\WooCommerce\Utilities\FeaturesUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_Invoice', false ) ) :
/**
* Order details email.
*
* An email sent to the customer via admin, that summarizes the details of their order. This was
* historically referred to as the 'invoice', and for backwards compatibility reasons that is still
* reflected in the class name (although on a user-level we have moved away from that nomenclature).
*
* @class WC_Email_Customer_Invoice
* @version 3.5.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_Invoice extends WC_Email {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_invoice';
$this->customer_email = true;
$this->title = __( 'Order details', 'woocommerce' );
$this->email_group = 'payments';
$this->template_html = 'emails/customer-invoice.php';
$this->template_plain = 'emails/plain/customer-invoice.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Manually send an email to your customers containing their order information and payment links', 'woocommerce' )
: __( 'Order detail emails can be sent to customers containing their order information and payment links.', 'woocommerce' );
$this->manual = true;
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'Payment request', 'woocommerce' );
$this->description = __( 'Manually send customers an email to review their order and complete payment.', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @param bool $paid Whether the order has been paid or not.
* @since 3.1.0
* @return string
*/
public function get_default_subject( $paid = false ) {
return __( 'Details for order #{order_number} on {site_title}', 'woocommerce' );
}
/**
* Get email heading.
*
* @param bool $paid Whether the order has been paid or not.
* @since 3.1.0
* @return string
*/
public function get_default_heading( $paid = false ) {
return __( 'Details for order #{order_number}', 'woocommerce' );
}
/**
* Get email subject.
*
* @return string
*/
public function get_subject() {
if ( $this->object->has_status( array( OrderStatus::COMPLETED, OrderStatus::PROCESSING ) ) ) {
$subject = $this->get_option( 'subject_paid', $this->get_default_subject( true ) );
if ( $this->block_email_editor_enabled ) {
$subject = $this->personalizer->personalize_transactional_content( $subject, $this );
}
return apply_filters( 'woocommerce_email_subject_customer_invoice_paid', $this->format_string( $subject ), $this->object, $this );
}
$subject = $this->get_option( 'subject', $this->get_default_subject() );
if ( $this->block_email_editor_enabled ) {
$subject = $this->personalizer->personalize_transactional_content( $subject, $this );
}
return apply_filters( 'woocommerce_email_subject_customer_invoice', $this->format_string( $subject ), $this->object, $this );
}
/**
* Get email heading.
*
* @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 ) );
return apply_filters( 'woocommerce_email_heading_customer_invoice_paid', $this->format_string( $heading ), $this->object, $this );
}
$heading = $this->get_option( 'heading', $this->get_default_heading() );
return apply_filters( 'woocommerce_email_heading_customer_invoice', $this->format_string( $heading ), $this->object, $this );
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return $this->email_improvements_enabled
? __( 'Thanks again! If you need any help with your order, please contact us at {store_email}.', 'woocommerce' )
: __( 'Thanks for using {site_url}!', 'woocommerce' );
}
/**
* Trigger the sending of this email.
*
* @param int $order_id The order ID.
* @param WC_Order $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->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
$this->restore_locale();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Initialise settings form fields.
*/
public function init_form_fields() {
/* translators: %s: list of placeholders */
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
$this->form_fields = array(
'subject' => array(
'title' => __( 'Subject', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject(),
'default' => '',
),
'heading' => array(
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading(),
'default' => '',
),
'subject_paid' => array(
'title' => __( 'Subject (paid)', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject( true ),
'default' => '',
),
'heading_paid' => array(
'title' => __( 'Email heading (paid)', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading( true ),
'default' => '',
),
'additional_content' => array(
'title' => __( 'Additional content', 'woocommerce' ),
'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text,
'css' => 'width:400px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => $this->get_default_additional_content(),
'desc_tip' => true,
),
'email_type' => array(
'title' => __( 'Email type', 'woocommerce' ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
'default' => 'html',
'class' => 'email_type wc-enhanced-select',
'options' => $this->get_email_type_options(),
'desc_tip' => true,
),
);
if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
$this->form_fields['cc'] = $this->get_cc_field();
$this->form_fields['bcc'] = $this->get_bcc_field();
}
if ( $this->block_email_editor_enabled ) {
$this->form_fields['preheader'] = $this->get_preheader_field();
}
}
}
endif;
return new WC_Email_Customer_Invoice();

View File

@@ -0,0 +1,224 @@
<?php
/**
* Class WC_Email_Customer_New_Account file.
*
* @package WooCommerce\Emails
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_New_Account', false ) ) {
/**
* Customer New Account.
*
* An email sent to the customer when they create an account.
*
* @class WC_Email_Customer_New_Account
* @version 3.5.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_New_Account extends WC_Email {
/**
* User login name.
*
* @var string
*/
public $user_login;
/**
* User email.
*
* @var string
*/
public $user_email;
/**
* User password.
*
* @var string
*/
public $user_pass;
/**
* Is the password generated?
*
* @var bool
*/
public $password_generated;
/**
* Magic link to set initial password.
*
* @var string
*/
public $set_password_url;
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_new_account';
$this->customer_email = true;
$this->title = __( 'New account', 'woocommerce' );
$this->email_group = 'accounts';
$this->description = __( 'Send an email to customers notifying them that they have created an account', 'woocommerce' );
$this->template_html = 'emails/customer-new-account.php';
$this->template_plain = 'emails/plain/customer-new-account.php';
parent::__construct();
// Must be after parent's constructor which sets `block_email_editor_enabled` property.
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'Account created', 'woocommerce' );
$this->description = __( 'Notifies customers when their account has been created.', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( 'Your {site_title} account has been created!', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Welcome to {site_title}', 'woocommerce' );
}
/**
* Trigger.
*
* @param int $user_id User ID.
* @param string $user_pass User password.
* @param bool $password_generated Whether the password was generated automatically or not.
*/
public function trigger( $user_id, $user_pass = '', $password_generated = false ) {
$this->setup_locale();
if ( $user_id ) {
$this->object = new WP_User( $user_id );
$this->set_password_url = $this->generate_set_password_url();
$this->user_login = stripslashes( $this->object->user_login );
$this->user_email = stripslashes( $this->object->user_email );
$this->recipient = $this->user_email;
$this->user_pass = $user_pass;
$this->password_generated = $password_generated;
}
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();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'user_login' => $this->user_login,
'blogname' => $this->get_blogname(),
'set_password_url' => $this->set_password_url,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
'password_generated' => $this->password_generated,
'user_pass' => $this->user_pass, // Password is no longer used in the template, but we're keeping it here for backwards compatibility with custom templates.
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'user_login' => $this->user_login,
'blogname' => $this->get_blogname(),
'set_password_url' => $this->set_password_url,
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
'password_generated' => $this->password_generated,
'user_pass' => $this->user_pass, // Password is no longer used in the template, but we're keeping it here for backwards compatibility with custom templates.
)
);
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
return wc_get_template_html(
$this->template_block_content,
array(
'user_login' => $this->user_login,
'set_password_url' => $this->set_password_url,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
'password_generated' => $this->password_generated,
'user_pass' => $this->user_pass, // Password is no longer used in the template, but we're keeping it here for backwards compatibility with custom templates.
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return __( 'We look forward to seeing you soon.', 'woocommerce' );
}
/**
* Generate set password URL link for a new user.
*
* @since 6.0.0
* @return string
*/
protected function generate_set_password_url() {
// Generate a magic link so user can set initial password.
$key = get_password_reset_key( $this->object );
if ( is_wp_error( $key ) ) {
// Something went wrong while getting the key for new password URL, send customer to the generic password reset.
return wc_get_account_endpoint_url( 'lost-password' );
}
return sprintf( '%s?action=newaccount&key=%s&login=%s', wc_get_account_endpoint_url( 'lost-password' ), $key, rawurlencode( $this->object->user_login ) );
}
}
}
return new WC_Email_Customer_New_Account();

View File

@@ -0,0 +1,198 @@
<?php
/**
* Class WC_Email_Customer_Note file.
*
* @package WooCommerce\Emails
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_Note', false ) ) :
/**
* Customer Note Order Email.
*
* Customer note emails are sent when you add a note to an order.
*
* @class WC_Email_Customer_Note
* @version 3.5.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_Note extends WC_Email {
/**
* Customer note.
*
* @var string
*/
public $customer_note;
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_note';
$this->customer_email = true;
$this->title = __( 'Customer note', 'woocommerce' );
$this->email_group = 'order-changes';
$this->template_html = 'emails/customer-note.php';
$this->template_plain = 'emails/plain/customer-note.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Triggers.
add_action( 'woocommerce_new_customer_note_notification', array( $this, 'trigger' ) );
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Send an email to customers notifying them when youve added a note to their order', 'woocommerce' )
: __( 'Customer note emails are sent when you add a note to an order.', 'woocommerce' );
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'Customer note added', 'woocommerce' );
$this->description = __( 'Notifies customers when youve added a note to their order.', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return $this->email_improvements_enabled
? __( 'A note has been added to your order from {site_title}', 'woocommerce' )
: __( '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' );
}
/**
* Trigger.
*
* @param array $args Email arguments.
*/
public function trigger( $args ) {
$this->setup_locale();
if ( ! empty( $args ) ) {
$defaults = array(
'order_id' => '',
'customer_note' => '',
);
$args = wp_parse_args( $args, $defaults );
$order_id = $args['order_id'];
$customer_note = $args['customer_note'];
if ( $order_id ) {
$this->object = wc_get_order( $order_id );
if ( $this->object ) {
$this->recipient = $this->object->get_billing_email();
$this->customer_note = $customer_note;
$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();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'customer_note' => $this->customer_note,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'customer_note' => $this->customer_note,
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return $this->email_improvements_enabled
? __( 'Thanks again! If you need any help with your order, please contact us at {store_email}.', 'woocommerce' )
: __( 'Thanks for reading.', 'woocommerce' );
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
return wc_get_template_html(
$this->template_block_content,
array(
'order' => $this->object,
'customer_note' => $this->customer_note,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
}
endif;
return new WC_Email_Customer_Note();

View File

@@ -0,0 +1,160 @@
<?php
/**
* Class WC_Email_Customer_On_Hold_Order file.
*
* @package WooCommerce\Emails
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_On_Hold_Order', false ) ) :
/**
* Customer On-hold Order Email.
*
* An email sent to the customer when a new order is on-hold for.
*
* @class WC_Email_Customer_On_Hold_Order
* @version 2.6.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_On_Hold_Order extends WC_Email {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_on_hold_order';
$this->customer_email = true;
$this->title = __( 'Order on-hold', 'woocommerce' );
$this->email_group = 'order-changes';
$this->template_html = 'emails/customer-on-hold-order.php';
$this->template_plain = 'emails/plain/customer-on-hold-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// 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 );
add_action( 'woocommerce_order_status_cancelled_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Send an email to customers notifying them when their order has been placed on hold', 'woocommerce' )
: __( 'This is an order notification sent to customers containing order details after an order is placed on-hold from Pending, Cancelled or Failed order status.', 'woocommerce' );
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'Order on hold', 'woocommerce' );
$this->description = __( 'Notifies customers when their order has been placed on hold.', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( 'Your {site_title} order has been received!', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Thank you for your order', 'woocommerce' );
}
/**
* 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();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return $this->email_improvements_enabled
? __( 'Thanks again! If you need any help with your order, please contact us at {store_email}.', 'woocommerce' )
: __( 'We look forward to fulfilling your order soon.', 'woocommerce' );
}
}
endif;
return new WC_Email_Customer_On_Hold_Order();

View File

@@ -0,0 +1,467 @@
<?php
/**
* Class WC_Email_Customer_POS_Completed_Order file.
*
* @package WooCommerce\Emails
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use Automattic\WooCommerce\Internal\Email\OrderPriceFormatter;
use Automattic\WooCommerce\Internal\Orders\PointOfSaleOrderUtil;
use Automattic\WooCommerce\Internal\Settings\PointOfSaleDefaultSettings;
use Automattic\WooCommerce\Utilities\FeaturesUtil;
if ( ! class_exists( 'WC_Email_Customer_POS_Completed_Order', false ) ) :
/**
* Customer Completed Order Email.
*
* Order complete emails are sent to the customer when the order is marked complete and usual indicates that the order has been shipped.
*
* @class WC_Email_Customer_POS_Completed_Order
* @version 2.0.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_POS_Completed_Order extends WC_Email {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_pos_completed_order';
$this->customer_email = true;
$this->title = __( 'POS completed order', 'woocommerce' );
$this->email_group = 'payments';
$this->template_html = 'emails/customer-pos-completed-order.php';
$this->template_plain = 'emails/plain/customer-pos-completed-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
$this->enable_order_email_actions_for_pos_orders();
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Let customers know once their POS order is complete.', 'woocommerce' )
: __( 'Order complete emails are sent to customers when their POS orders are marked completed.', 'woocommerce' );
$this->manual = true;
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'POS order complete', 'woocommerce' );
$this->description = __( 'Notifies customers when their in-person (POS) order has been completed.', 'woocommerce' );
}
}
/**
* Trigger the sending of this email.
*
* @param int $order_id The order ID.
* @param string $template_id The email template ID.
*/
public function trigger( $order_id, $template_id ) {
if ( $this->id !== $template_id ) {
return;
}
$this->setup_locale();
if ( $order_id ) {
$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->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
$this->restore_locale();
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
$store_name = $this->get_pos_store_name();
/* translators: %1$s: Order number, %2$s: Store name */
return sprintf( __( 'Your in-store purchase #%1$s at %2$s', 'woocommerce' ), '{order_number}', esc_html( $store_name ) );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Thank you for your in-store purchase', 'woocommerce' );
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
$this->add_pos_customizations();
add_action( 'woocommerce_pos_email_header', array( $this, 'email_header' ) );
add_action( 'woocommerce_pos_email_footer', array( $this, 'email_footer' ) );
$content = wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'pos_store_name' => $this->get_pos_store_name(),
'pos_store_email' => $this->get_pos_store_email(),
'pos_store_phone_number' => $this->get_pos_store_phone_number(),
'pos_store_address' => $this->get_pos_store_address(),
'pos_refund_returns_policy' => $this->get_pos_refund_returns_policy(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
$this->remove_pos_customizations();
remove_action( 'woocommerce_pos_email_header', array( $this, 'email_header' ) );
remove_action( 'woocommerce_pos_email_footer', array( $this, 'email_footer' ) );
return $content;
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
$this->add_pos_customizations();
$content = wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'pos_store_name' => $this->get_pos_store_name(),
'pos_store_email' => $this->get_pos_store_email(),
'pos_store_phone_number' => $this->get_pos_store_phone_number(),
'pos_store_address' => $this->get_pos_store_address(),
'pos_refund_returns_policy' => $this->get_pos_refund_returns_policy(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
$this->remove_pos_customizations();
return $content;
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
$this->add_pos_customizations();
return wc_get_template_html(
$this->template_block_content,
array(
'order' => $this->object,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Enable order email actions for POS orders.
*/
private function enable_order_email_actions_for_pos_orders() {
$this->enable_email_template_for_pos_orders();
// Enable send email when requested.
add_action( 'woocommerce_rest_order_actions_email_send', array( $this, 'trigger' ), 10, 2 );
}
/**
* Override settings form fields to remove the enabled/disabled field as the email is manually sent.
*/
public function init_form_fields() {
/* translators: %s: list of placeholders */
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
$this->form_fields = array(
'subject' => array(
'title' => __( 'Subject', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject(),
'default' => '',
),
'heading' => array(
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading(),
'default' => '',
),
'additional_content' => array(
'title' => __( 'Additional content', 'woocommerce' ),
'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text,
'css' => 'width:400px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => $this->get_default_additional_content(),
'desc_tip' => true,
),
'email_type' => array(
'title' => __( 'Email type', 'woocommerce' ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
'default' => 'html',
'class' => 'email_type wc-enhanced-select',
'options' => $this->get_email_type_options(),
'desc_tip' => true,
),
);
if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
$this->form_fields['cc'] = $this->get_cc_field();
$this->form_fields['bcc'] = $this->get_bcc_field();
}
}
/**
* Add actions and filters before generating email content.
*/
private function add_pos_customizations() {
// Add action to display unit price in the beginning of the order item meta.
add_action( 'woocommerce_order_item_meta_start', array( $this, 'add_unit_price' ), 10, 4 );
// Add filter to include additional details in the order item totals table.
add_filter( 'woocommerce_get_order_item_totals', array( $this, 'order_item_totals' ), 10, 3 );
// Add filter for custom footer text with highest priority to run before the default footer text filtering in `WC_Emails`.
add_filter( 'woocommerce_email_footer_text', array( $this, 'replace_footer_placeholders' ), 1, 2 );
}
/**
* Remove actions and filters after generating email content.
*/
private function remove_pos_customizations() {
// Remove actions and filters after generating content to avoid affecting other emails.
remove_action( 'woocommerce_order_item_meta_start', array( $this, 'add_unit_price' ), 10 );
remove_filter( 'woocommerce_get_order_item_totals', array( $this, 'order_item_totals' ), 10 );
remove_filter( 'woocommerce_email_footer_text', array( $this, 'replace_footer_placeholders' ), 1 );
}
/**
* Get the email header.
*
* @param mixed $email_heading Heading for the email.
*
* @internal For exclusive usage within this class, backwards compatibility not guaranteed.
*/
public function email_header( $email_heading ) {
wc_get_template(
'emails/email-header.php',
array(
'email_heading' => $email_heading,
'store_name' => $this->get_pos_store_name(),
)
);
}
/**
* Get the email footer.
*
* @param mixed $email Email object.
*
* @internal For exclusive usage within this class, backwards compatibility not guaranteed.
*/
public function email_footer( $email ) {
wc_get_template(
'emails/email-footer.php',
array(
'email' => $email,
)
);
}
/**
* Add unit price to order item meta start position.
*
* @param int $item_id Order item ID.
* @param array $item Order item data.
* @param WC_Order $order Order object.
*/
public function add_unit_price( $item_id, $item, $order ) {
$unit_price = OrderPriceFormatter::get_formatted_item_subtotal( $order, $item, get_option( 'woocommerce_tax_display_cart' ) );
echo wp_kses_post( '<br /><small>' . $unit_price . '</small>' );
}
/**
* Add additional details to the order item totals table.
*
* @param array $total_rows Array of total rows.
* @param WC_Order $order Order object.
* @param string $tax_display Tax display.
* @return array Modified array of total rows.
*/
public function order_item_totals( $total_rows, $order, $tax_display ) {
$cash_payment_change_due_amount = $order->get_meta( '_cash_change_amount', true );
if ( '' !== $cash_payment_change_due_amount ) {
$formatted_cash_payment_change_due_amount = wc_price( $cash_payment_change_due_amount, array( 'currency' => $order->get_currency() ) );
$total_rows['cash_payment_change_due_amount'] = array(
'type' => 'cash_payment_change_due_amount',
'label' => __( 'Change due:', 'woocommerce' ),
'value' => $formatted_cash_payment_change_due_amount,
);
}
$auth_code = $order->get_meta( '_charge_id', true );
if ( ! empty( $auth_code ) ) {
$total_rows['payment_auth_code'] = array(
'type' => 'payment_auth_code',
'label' => __( 'Auth code:', 'woocommerce' ),
'value' => $auth_code,
);
}
if ( $order->get_date_paid() !== null ) {
$total_rows['date_paid'] = array(
'type' => 'date_paid',
'label' => __( 'Time of payment:', 'woocommerce' ),
'value' => wc_format_datetime( $order->get_date_paid(), get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ),
);
}
return $total_rows;
}
/**
* Enable email template for REST API order valid templates for POS orders.
*/
private function enable_email_template_for_pos_orders() {
add_filter( 'woocommerce_rest_order_actions_email_valid_template_classes', array( $this, 'add_to_valid_template_classes' ), 10, 2 );
}
/**
* Add this email template to the list of valid templates for POS orders.
*
* @param array $valid_template_classes Array of valid template class names.
* @param WC_Order $order The order.
* @return array Modified array of valid template class names.
*/
public function add_to_valid_template_classes( $valid_template_classes, $order ) {
if ( ! PointOfSaleOrderUtil::is_pos_order( $order ) ) {
return $valid_template_classes;
}
$valid_template_classes[] = get_class( $this );
return $valid_template_classes;
}
/**
* Get the store name from POS settings.
*
* @return string
*/
private function get_pos_store_name() {
$store_name = get_option( 'woocommerce_pos_store_name' );
return $this->format_string(
empty( $store_name ) ? PointOfSaleDefaultSettings::get_default_store_name() : $store_name
);
}
/**
* Get the store email from POS settings.
*
* @return string
*/
private function get_pos_store_email() {
return $this->format_string(
get_option( 'woocommerce_pos_store_email', PointOfSaleDefaultSettings::get_default_store_email() )
);
}
/**
* Get the store phone number from POS settings.
*
* @return string
*/
private function get_pos_store_phone_number() {
return $this->format_string(
get_option( 'woocommerce_pos_store_phone' )
);
}
/**
* Get the store address from POS settings.
*
* @return string
*/
private function get_pos_store_address() {
return $this->format_string(
get_option( 'woocommerce_pos_store_address', PointOfSaleDefaultSettings::get_default_store_address() )
);
}
/**
* Get the refund and returns policy from POS settings.
*
* @return string
*/
private function get_pos_refund_returns_policy() {
return $this->format_string(
get_option( 'woocommerce_pos_refund_returns_policy' )
);
}
/**
* Replace footer text placeholders with POS-specific values.
*
* @param string $footer_text The footer text to be filtered.
* @param mixed $email Email object.
* @return string Modified footer text.
*
* @internal For exclusive usage within this class, backwards compatibility not guaranteed.
*/
public function replace_footer_placeholders( $footer_text, $email ) {
// Only replace placeholders if we're in the context of a POS email.
if ( $email->id !== $this->id ) {
return $footer_text;
}
return str_replace(
array(
'{site_title}',
'{store_address}',
'{store_email}',
),
array(
$this->get_pos_store_name(),
$this->get_pos_store_address(),
$this->get_pos_store_email(),
),
$footer_text
);
}
}
endif;
return new WC_Email_Customer_POS_Completed_Order();

View File

@@ -0,0 +1,610 @@
<?php
/**
* Class WC_Email_Customer_POS_Refunded_Order file.
*
* @package WooCommerce\Emails
*/
use Automattic\WooCommerce\Internal\Email\OrderPriceFormatter;
use Automattic\WooCommerce\Internal\Orders\PointOfSaleOrderUtil;
use Automattic\WooCommerce\Internal\Settings\PointOfSaleDefaultSettings;
use Automattic\WooCommerce\Utilities\FeaturesUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_POS_Refunded_Order', false ) ) :
/**
* Customer Refunded Order Email.
*
* Order refunded emails are sent to the customer when the order is marked refunded.
*
* @class WC_Email_Customer_POS_Refunded_Order
* @version 3.5.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_POS_Refunded_Order extends WC_Email {
/**
* Refund order.
*
* @var WC_Order|bool
*/
public $refund;
/**
* Is the order partial refunded?
*
* @var bool
*/
public $partial_refund;
/**
* Constructor.
*/
public function __construct() {
$this->customer_email = true;
$this->id = 'customer_pos_refunded_order';
$this->title = __( 'POS refunded order', 'woocommerce' );
$this->email_group = 'payments';
$this->template_html = 'emails/customer-pos-refunded-order.php';
$this->template_plain = 'emails/plain/customer-pos-refunded-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Let customers know when a full or partial refund is on its way to them for their POS order.', 'woocommerce' )
: __( 'Order refunded emails are sent to customers when their POS orders are refunded.', 'woocommerce' );
$this->disable_default_refund_emails_for_pos_orders();
$this->register_refund_email_triggers();
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'POS order refunded', 'woocommerce' );
$this->description = __( 'Notifies customers when a full or partial refund has been issued for their in-person (POS) order.', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @param bool $partial Whether it is a partial refund or a full refund.
* @since 3.1.0
* @return string
*/
public function get_default_subject( $partial = false ) {
$store_name = $this->get_pos_store_name();
if ( $partial ) {
/* translators: %1$s: Store name, %2$s: Order number */
return sprintf( __( 'Your %1$s order #%2$s has been partially refunded', 'woocommerce' ), esc_html( $store_name ), '{order_number}' );
} else {
/* translators: %1$s: Store name, %2$s: Order number */
return sprintf( __( 'Your %1$s order #%2$s has been refunded', 'woocommerce' ), esc_html( $store_name ), '{order_number}' );
}
}
/**
* Get email heading.
*
* @param bool $partial Whether it is a partial refund or a full refund.
* @since 3.1.0
* @return string
*/
public function get_default_heading( $partial = false ) {
if ( $partial ) {
return $this->email_improvements_enabled
? __( 'Partial refund: Order {order_number}', 'woocommerce' )
: __( 'Partial Refund: Order {order_number}', 'woocommerce' );
} else {
return $this->email_improvements_enabled
? __( 'Order refunded: {order_number}', 'woocommerce' )
: __( 'Order Refunded: {order_number}', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @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_subject() );
}
/**
* Filter the email subject for customer refunded order.
*
* @param string $subject The email subject.
* @param WC_Order $order Order object.
* @param WC_Email_Customer_POS_Refunded_Order $email Email object.
* @since 3.7.0
*/
return apply_filters( 'woocommerce_email_subject_customer_refunded_order', $this->format_string( $subject ), $this->object, $this );
}
/**
* Get email heading.
*
* @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() );
}
/**
* Filter the email heading for customer refunded order.
*
* @param string $heading The email heading.
* @param WC_Order $order Order object.
* @param WC_Email_Customer_POS_Refunded_Order $email Email object.
* @since 3.7.0
*/
return apply_filters( 'woocommerce_email_heading_customer_refunded_order', $this->format_string( $heading ), $this->object, $this );
}
/**
* Set email strings.
*
* @param bool $partial_refund Whether it is a partial refund or a full refund.
* @deprecated 3.1.0 Unused.
*/
public function set_email_strings( $partial_refund = false ) {}
/**
* Full refund notification.
*
* @param int $order_id Order ID.
* @param int $refund_id Refund ID.
*
* @internal For exclusive usage within this class, backwards compatibility not guaranteed.
*/
public function trigger_full( $order_id, $refund_id = null ) {
$this->trigger( $order_id, false, $refund_id );
}
/**
* Partial refund notification.
*
* @param int $order_id Order ID.
* @param int $refund_id Refund ID.
*
* @internal For exclusive usage within this class, backwards compatibility not guaranteed.
*/
public function trigger_partial( $order_id, $refund_id = null ) {
$this->trigger( $order_id, true, $refund_id );
}
/**
* Trigger.
*
* @param int $order_id Order ID.
* @param bool $partial_refund Whether it is a partial refund or a full refund.
* @param int $refund_id Refund ID.
*/
private function trigger( $order_id, $partial_refund = false, $refund_id = null ) {
if ( ! $order_id ) {
return;
}
// Only trigger for POS orders.
$order = wc_get_order( $order_id );
if ( ! $order || ! PointOfSaleOrderUtil::is_pos_order( $order ) ) {
return;
}
$this->setup_locale();
$this->partial_refund = $partial_refund;
$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 ( ! empty( $refund_id ) ) {
$this->refund = wc_get_order( $refund_id );
} else {
$this->refund = false;
}
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();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
$this->add_pos_customizations();
add_action( 'woocommerce_pos_email_header', array( $this, 'email_header' ) );
add_action( 'woocommerce_pos_email_footer', array( $this, 'email_footer' ) );
$content = wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'refund' => $this->refund,
'partial_refund' => $this->partial_refund,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'pos_store_name' => $this->get_pos_store_name(),
'pos_store_email' => $this->get_pos_store_email(),
'pos_store_phone_number' => $this->get_pos_store_phone_number(),
'pos_store_address' => $this->get_pos_store_address(),
'pos_refund_returns_policy' => $this->get_pos_refund_returns_policy(),
'blogname' => $this->get_blogname(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
$this->remove_pos_customizations();
remove_action( 'woocommerce_pos_email_header', array( $this, 'email_header' ) );
remove_action( 'woocommerce_pos_email_footer', array( $this, 'email_footer' ) );
return $content;
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
$this->add_pos_customizations();
$content = wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'refund' => $this->refund,
'partial_refund' => $this->partial_refund,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'pos_store_name' => $this->get_pos_store_name(),
'pos_store_email' => $this->get_pos_store_email(),
'pos_store_phone_number' => $this->get_pos_store_phone_number(),
'pos_store_address' => $this->get_pos_store_address(),
'pos_refund_returns_policy' => $this->get_pos_refund_returns_policy(),
'blogname' => $this->get_blogname(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
$this->remove_pos_customizations();
return $content;
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
$this->add_pos_customizations();
return wc_get_template_html(
$this->template_block_content,
array(
'order' => $this->object,
'refund' => $this->refund,
'partial_refund' => $this->partial_refund,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Initialise settings form fields.
*/
public function init_form_fields() {
/* translators: %s: list of placeholders */
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable this email notification', 'woocommerce' ),
'default' => 'yes',
),
'subject_full' => array(
'title' => __( 'Full refund subject', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject(),
'default' => '',
),
'subject_partial' => array(
'title' => __( 'Partial refund subject', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject( true ),
'default' => '',
),
'heading_full' => array(
'title' => __( 'Full refund email heading', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading(),
'default' => '',
),
'heading_partial' => array(
'title' => __( 'Partial refund email heading', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading( true ),
'default' => '',
),
'additional_content' => array(
'title' => __( 'Additional content', 'woocommerce' ),
'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text,
'css' => 'width:400px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => $this->get_default_additional_content(),
'desc_tip' => true,
),
'email_type' => array(
'title' => __( 'Email type', 'woocommerce' ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
'default' => 'html',
'class' => 'email_type wc-enhanced-select',
'options' => $this->get_email_type_options(),
'desc_tip' => true,
),
);
if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
$this->form_fields['cc'] = $this->get_cc_field();
$this->form_fields['bcc'] = $this->get_bcc_field();
}
if ( $this->block_email_editor_enabled ) {
$this->form_fields['preheader'] = $this->get_preheader_field();
}
}
/**
* Add actions and filters before generating email content.
*/
private function add_pos_customizations() {
// Add action to display unit price in the beginning of the order item meta.
add_action( 'woocommerce_order_item_meta_start', array( $this, 'add_unit_price' ), 10, 4 );
// Add filter to include additional details in the order item totals table.
add_filter( 'woocommerce_get_order_item_totals', array( $this, 'order_item_totals' ), 10, 3 );
// Add filter for custom footer text with highest priority to run before the default footer text filtering in `WC_Emails`.
add_filter( 'woocommerce_email_footer_text', array( $this, 'replace_footer_placeholders' ), 1, 2 );
}
/**
* Remove actions and filters after generating email content.
*/
private function remove_pos_customizations() {
// Remove actions and filters after generating content to avoid affecting other emails.
remove_action( 'woocommerce_order_item_meta_start', array( $this, 'add_unit_price' ), 10 );
remove_filter( 'woocommerce_get_order_item_totals', array( $this, 'order_item_totals' ), 10 );
remove_filter( 'woocommerce_email_footer_text', array( $this, 'replace_footer_placeholders' ), 1 );
}
/**
* Get the email header.
*
* @param mixed $email_heading Heading for the email.
*
* @internal For exclusive usage within this class, backwards compatibility not guaranteed.
*/
public function email_header( $email_heading ) {
wc_get_template(
'emails/email-header.php',
array(
'email_heading' => $email_heading,
'store_name' => $this->get_pos_store_name(),
)
);
}
/**
* Get the email footer.
*
* @param mixed $email Email object.
*
* @internal For exclusive usage within this class, backwards compatibility not guaranteed.
*/
public function email_footer( $email ) {
wc_get_template(
'emails/email-footer.php',
array(
'email' => $email,
)
);
}
/**
* Add unit price to order item meta start position.
*
* @param int $item_id Order item ID.
* @param array $item Order item data.
* @param WC_Order $order Order object.
*/
public function add_unit_price( $item_id, $item, $order ) {
$unit_price = OrderPriceFormatter::get_formatted_item_subtotal( $order, $item, get_option( 'woocommerce_tax_display_cart' ) );
echo wp_kses_post( '<br /><small>' . $unit_price . '</small>' );
}
/**
* Disable default WooCommerce refund emails for POS orders.
* The core refund email IDs are in WC_Email_Customer_Refunded_Order's trigger method.
*
* This method adds filters to prevent the default WooCommerce refund emails
* from being sent for orders created through the Point of Sale system.
* Instead, the POS-specific refund emails will be used.
*/
private function disable_default_refund_emails_for_pos_orders() {
add_filter( 'woocommerce_email_enabled_customer_partially_refunded_order', array( $this, 'disable_default_refund_email_for_pos_orders' ), 10, 3 );
add_filter( 'woocommerce_email_enabled_customer_refunded_order', array( $this, 'disable_default_refund_email_for_pos_orders' ), 10, 3 );
}
/**
* Disable the default WooCommerce refund email for POS orders.
*
* @param bool $enabled Whether the email is enabled.
* @param WC_Order|null $order The order object.
* @param WC_Email|null $email The email object.
* @return bool
*
* @internal For exclusive usage within this class, backwards compatibility not guaranteed.
*/
public function disable_default_refund_email_for_pos_orders( $enabled, $order, $email ) {
if ( $order && PointOfSaleOrderUtil::is_pos_order( $order ) ) {
return false;
}
return $enabled;
}
/**
* Register triggers for POS refund emails.
*
* This method adds actions to trigger the refund emails for POS orders.
* It ensures that the emails are sent correctly when a full or partial refund is made.
*/
private function register_refund_email_triggers() {
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 additional details to the order item totals table.
*
* @param array $total_rows Array of total rows.
* @param WC_Order $order Order object.
* @param string $tax_display Tax display.
* @return array Modified array of total rows.
*/
public function order_item_totals( $total_rows, $order, $tax_display ) {
$auth_code = $order->get_meta( '_charge_id', true );
if ( ! empty( $auth_code ) ) {
$total_rows['payment_auth_code'] = array(
'type' => 'payment_auth_code',
'label' => __( 'Auth code:', 'woocommerce' ),
'value' => $auth_code,
);
}
if ( $order->get_date_paid() !== null ) {
$total_rows['date_paid'] = array(
'type' => 'date_paid',
'label' => __( 'Time of payment:', 'woocommerce' ),
'value' => wc_format_datetime( $order->get_date_paid(), get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ),
);
}
return $total_rows;
}
/**
* Get the store name from POS settings.
*
* @return string
*/
private function get_pos_store_name() {
return $this->format_string(
get_option( 'woocommerce_pos_store_name', PointOfSaleDefaultSettings::get_default_store_name() )
);
}
/**
* Get the store email from POS settings.
*
* @return string
*/
private function get_pos_store_email() {
return $this->format_string(
get_option( 'woocommerce_pos_store_email', PointOfSaleDefaultSettings::get_default_store_email() )
);
}
/**
* Get the store phone number from POS settings.
*
* @return string
*/
private function get_pos_store_phone_number() {
return $this->format_string(
get_option( 'woocommerce_pos_store_phone' )
);
}
/**
* Get the store address from POS settings.
*
* @return string
*/
private function get_pos_store_address() {
return $this->format_string(
get_option( 'woocommerce_pos_store_address', PointOfSaleDefaultSettings::get_default_store_address() )
);
}
/**
* Get the refund and returns policy from POS settings.
*
* @return string
*/
private function get_pos_refund_returns_policy() {
return $this->format_string(
get_option( 'woocommerce_pos_refund_returns_policy' )
);
}
/**
* Replace footer text placeholders with POS-specific values.
*
* @param string $footer_text The footer text to be filtered.
* @param mixed $email Email object.
* @return string Modified footer text.
*
* @internal For exclusive usage within this class, backwards compatibility not guaranteed.
*/
public function replace_footer_placeholders( $footer_text, $email ) {
// Only replace placeholders if we're in the context of a POS email.
if ( $email->id !== $this->id ) {
return $footer_text;
}
return str_replace(
array(
'{site_title}',
'{store_address}',
'{store_email}',
),
array(
$this->get_pos_store_name(),
$this->get_pos_store_address(),
$this->get_pos_store_email(),
),
$footer_text
);
}
}
endif;
return new WC_Email_Customer_POS_Refunded_Order();

View File

@@ -0,0 +1,162 @@
<?php
/**
* Class WC_Email_Customer_Processing_Order file.
*
* @package WooCommerce\Emails
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_Processing_Order', false ) ) :
/**
* Customer Processing Order Email.
*
* An email sent to the customer when a new order is paid for.
*
* @class WC_Email_Customer_Processing_Order
* @version 3.5.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_Processing_Order extends WC_Email {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_processing_order';
$this->customer_email = true;
$this->title = __( 'Processing order', 'woocommerce' );
$this->email_group = 'order-updates';
$this->template_html = 'emails/customer-processing-order.php';
$this->template_plain = 'emails/plain/customer-processing-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Triggers for this email.
add_action( 'woocommerce_order_status_cancelled_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
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 );
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Send an email to customers notifying them that their order is being processed', 'woocommerce' )
: __( 'This is an order notification sent to customers containing order details after payment.', 'woocommerce' );
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'Order confirmation', 'woocommerce' );
$this->description = __( 'Notifies customers when their order has been received and is being processed.', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( 'Your {site_title} order has been received!', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'Thank you for your order', 'woocommerce' );
}
/**
* 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();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return $this->email_improvements_enabled
? __( 'Thanks again! If you need any help with your order, please contact us at {store_email}.', 'woocommerce' )
: __( 'Thanks for using {site_url}!', 'woocommerce' );
}
}
endif;
return new WC_Email_Customer_Processing_Order();

View File

@@ -0,0 +1,368 @@
<?php
/**
* Class WC_Email_Customer_Refunded_Order file.
*
* @package WooCommerce\Emails
*/
use Automattic\WooCommerce\Utilities\FeaturesUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_Refunded_Order', false ) ) :
/**
* Customer Refunded Order Email.
*
* Order refunded emails are sent to the customer when the order is marked refunded.
*
* @class WC_Email_Customer_Refunded_Order
* @version 3.5.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_Refunded_Order extends WC_Email {
/**
* Refund order.
*
* @var WC_Order|bool
*/
public $refund;
/**
* Is the order partial refunded?
*
* @var bool
*/
public $partial_refund;
/**
* Constructor.
*/
public function __construct() {
$this->customer_email = true;
$this->id = 'customer_refunded_order';
$this->title = __( 'Refunded order', 'woocommerce' );
$this->email_group = 'order-changes';
$this->template_html = 'emails/customer-refunded-order.php';
$this->template_plain = 'emails/plain/customer-refunded-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Triggers for this email.
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 );
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Send an email to customers notifying them when an order has been partially or fully refunded', 'woocommerce' )
: __( 'Order refunded emails are sent to customers when their orders are refunded.', 'woocommerce' );
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'Order refunded', 'woocommerce' );
$this->description = __( 'Notifies customers when their order has been partially or fully refunded.', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @param bool $partial Whether it is a partial refund or a full refund.
* @since 3.1.0
* @return string
*/
public function get_default_subject( $partial = false ) {
if ( $partial ) {
return __( 'Your {site_title} order #{order_number} has been partially refunded', 'woocommerce' );
} else {
return __( 'Your {site_title} order #{order_number} has been refunded', 'woocommerce' );
}
}
/**
* Get email heading.
*
* @param bool $partial Whether it is a partial refund or a full refund.
* @since 3.1.0
* @return string
*/
public function get_default_heading( $partial = false ) {
if ( $partial ) {
return $this->email_improvements_enabled
? __( 'Partial refund: Order {order_number}', 'woocommerce' )
: __( 'Partial Refund: Order {order_number}', 'woocommerce' );
} else {
return $this->email_improvements_enabled
? __( 'Order refunded: {order_number}', 'woocommerce' )
: __( 'Order Refunded: {order_number}', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @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_subject() );
}
/**
* Filter the email subject for customer refunded order.
*
* @param string $subject The email subject.
* @param WC_Order $order Order object.
* @param WC_Email_Customer_Refunded_Order $email Email object.
* @since 3.7.0
*/
$subject = apply_filters( 'woocommerce_email_subject_customer_refunded_order', $this->format_string( $subject ), $this->object, $this );
if ( $this->block_email_editor_enabled ) {
$subject = $this->personalizer->personalize_transactional_content( $subject, $this );
}
return $subject;
}
/**
* Get email heading.
*
* @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() );
}
/**
* Filter the email heading for customer refunded order.
*
* @param string $heading The email heading.
* @param WC_Order $order Order object.
* @param WC_Email_Customer_Refunded_Order $email Email object.
* @since 3.7.0
*/
return apply_filters( 'woocommerce_email_heading_customer_refunded_order', $this->format_string( $heading ), $this->object, $this );
}
/**
* Set email strings.
*
* @param bool $partial_refund Whether it is a partial refund or a full refund.
* @deprecated 3.1.0 Unused.
*/
public function set_email_strings( $partial_refund = false ) {}
/**
* Full refund notification.
*
* @param int $order_id Order ID.
* @param int $refund_id Refund ID.
*/
public function trigger_full( $order_id, $refund_id = null ) {
$this->trigger( $order_id, false, $refund_id );
}
/**
* Partial refund notification.
*
* @param int $order_id Order ID.
* @param int $refund_id Refund ID.
*/
public function trigger_partial( $order_id, $refund_id = null ) {
$this->trigger( $order_id, true, $refund_id );
}
/**
* Trigger.
*
* @param int $order_id Order ID.
* @param bool $partial_refund Whether it is a partial refund or a full refund.
* @param int $refund_id Refund ID.
*/
public function trigger( $order_id, $partial_refund = false, $refund_id = null ) {
$this->setup_locale();
$this->partial_refund = $partial_refund;
$this->id = $this->partial_refund ? 'customer_partially_refunded_order' : 'customer_refunded_order';
if ( $order_id ) {
$this->object = wc_get_order( $order_id );
$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 ( ! empty( $refund_id ) ) {
$this->refund = wc_get_order( $refund_id );
} else {
$this->refund = false;
}
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();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'refund' => $this->refund,
'partial_refund' => $this->partial_refund,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'blogname' => $this->get_blogname(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'refund' => $this->refund,
'partial_refund' => $this->partial_refund,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'blogname' => $this->get_blogname(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
return wc_get_template_html(
$this->template_block_content,
array(
'order' => $this->object,
'refund' => $this->refund,
'partial_refund' => $this->partial_refund,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return $this->email_improvements_enabled
? __( 'If you need any help with your order, please contact us at {store_email}.', 'woocommerce' )
: __( 'We hope to see you again soon.', 'woocommerce' );
}
/**
* Initialise settings form fields.
*/
public function init_form_fields() {
/* translators: %s: list of placeholders */
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable this email notification', 'woocommerce' ),
'default' => 'yes',
),
'subject_full' => array(
'title' => __( 'Full refund subject', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject(),
'default' => '',
),
'subject_partial' => array(
'title' => __( 'Partial refund subject', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject( true ),
'default' => '',
),
'heading_full' => array(
'title' => __( 'Full refund email heading', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading(),
'default' => '',
),
'heading_partial' => array(
'title' => __( 'Partial refund email heading', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading( true ),
'default' => '',
),
'additional_content' => array(
'title' => __( 'Additional content', 'woocommerce' ),
'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text,
'css' => 'width:400px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => $this->get_default_additional_content(),
'desc_tip' => true,
),
'email_type' => array(
'title' => __( 'Email type', 'woocommerce' ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
'default' => 'html',
'class' => 'email_type wc-enhanced-select',
'options' => $this->get_email_type_options(),
'desc_tip' => true,
),
);
if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
$this->form_fields['cc'] = $this->get_cc_field();
$this->form_fields['bcc'] = $this->get_bcc_field();
}
if ( $this->block_email_editor_enabled ) {
$this->form_fields['preheader'] = $this->get_preheader_field();
}
}
}
endif;
return new WC_Email_Customer_Refunded_Order();

View File

@@ -0,0 +1,210 @@
<?php
/**
* Class WC_Email_Customer_Reset_Password file.
*
* @package WooCommerce\Emails
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'WC_Email_Customer_Reset_Password', false ) ) :
/**
* Customer Reset Password.
*
* An email sent to the customer when they reset their password.
*
* @class WC_Email_Customer_Reset_Password
* @version 3.5.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Customer_Reset_Password extends WC_Email {
/**
* User ID.
*
* @var integer
*/
public $user_id;
/**
* User login name.
*
* @var string
*/
public $user_login;
/**
* User email.
*
* @var string
*/
public $user_email;
/**
* Reset key.
*
* @var string
*/
public $reset_key;
/**
* Constructor.
*/
public function __construct() {
$this->id = 'customer_reset_password';
$this->customer_email = true;
$this->title = __( 'Reset password', 'woocommerce' );
$this->description = __( 'Send an email to customers notifying them that their password has been reset', 'woocommerce' );
$this->template_html = 'emails/customer-reset-password.php';
$this->template_plain = 'emails/plain/customer-reset-password.php';
$this->email_group = 'accounts';
// Trigger.
add_action( 'woocommerce_reset_password_notification', array( $this, 'trigger' ), 10, 2 );
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `block_email_editor_enabled` property.
if ( $this->block_email_editor_enabled ) {
$this->title = __( 'Account password reset', 'woocommerce' );
$this->description = __( 'Notifies customers when their password has been reset.', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return $this->email_improvements_enabled
? __( 'Reset your password for {site_title}', 'woocommerce' )
: __( 'Password Reset Request for {site_title}', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return $this->email_improvements_enabled
? __( 'Reset your password', 'woocommerce' )
: __( 'Password Reset Request', 'woocommerce' );
}
/**
* Trigger.
*
* @param string $user_login User login.
* @param string $reset_key Password reset key.
*/
public function trigger( $user_login = '', $reset_key = '' ) {
$this->setup_locale();
if ( $user_login && $reset_key ) {
$this->object = get_user_by( 'login', $user_login );
$this->user_id = $this->object->ID;
$this->user_login = $user_login;
$this->reset_key = $reset_key;
$this->user_email = stripslashes( $this->object->user_email );
$this->recipient = $this->user_email;
}
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();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'email_heading' => $this->get_heading(),
'user_id' => $this->user_id,
'user_login' => $this->user_login,
'reset_key' => $this->reset_key,
'blogname' => $this->get_blogname(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'email_heading' => $this->get_heading(),
'user_id' => $this->user_id,
'user_login' => $this->user_login,
'reset_key' => $this->reset_key,
'blogname' => $this->get_blogname(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => false,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
return wc_get_template_html(
$this->template_block_content,
array(
'user_id' => $this->user_id,
'user_login' => $this->user_login,
'reset_key' => $this->reset_key,
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return __( 'Thanks for reading.', 'woocommerce' );
}
}
endif;
return new WC_Email_Customer_Reset_Password();

View File

@@ -0,0 +1,247 @@
<?php
/**
* Class WC_Email_Failed_Order file.
*
* @package WooCommerce\Emails
*/
use Automattic\WooCommerce\Utilities\FeaturesUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WC_Email_Failed_Order', false ) ) :
/**
* Failed Order Email.
*
* An email sent to the admin when payment fails to go through.
*
* @class WC_Email_Failed_Order
* @version 2.5.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_Failed_Order extends WC_Email {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'failed_order';
$this->title = __( 'Failed order', 'woocommerce' );
$this->email_group = 'orders';
$this->template_html = 'emails/admin-failed-order.php';
$this->template_plain = 'emails/plain/admin-failed-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Triggers for this email.
add_action( 'woocommerce_order_status_pending_to_failed_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_on-hold_to_failed_notification', array( $this, 'trigger' ), 10, 2 );
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Select who should be notified if an order that was previously processing or on-hold has failed.', 'woocommerce' )
: __( 'Failed order emails are sent to chosen recipient(s) when orders have been marked failed (if they were previously pending or on-hold).', 'woocommerce' );
// Other settings.
$this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
if ( $this->block_email_editor_enabled ) {
$this->description = __( 'Notifies admins when an order that was processing or on hold has failed.', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( '[{site_title}]: Order #{order_number} has failed', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return $this->email_improvements_enabled
? __( 'Order failed: #{order_number}', 'woocommerce' )
: __( 'Order Failed: #{order_number}', 'woocommerce' );
}
/**
* 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->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();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => true,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => true,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
return wc_get_template_html(
$this->template_block_content,
array(
'order' => $this->object,
'sent_to_admin' => true,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return $this->email_improvements_enabled
? __( 'We hope theyll be back soon! Read more about <a href="https://woocommerce.com/document/managing-orders/">troubleshooting failed payments</a>.', 'woocommerce' )
: __( 'Hopefully theyll be back. Read more about <a href="https://woocommerce.com/document/managing-orders/">troubleshooting failed payments</a>.', 'woocommerce' );
}
/**
* Initialise settings form fields.
*/
public function init_form_fields() {
/* translators: %s: list of placeholders */
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable this email notification', 'woocommerce' ),
'default' => 'yes',
),
'recipient' => array(
'title' => __( 'Recipient(s)', 'woocommerce' ),
'type' => 'text',
/* translators: %s: WP admin email */
'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to %s.', 'woocommerce' ), '<code>' . esc_attr( get_option( 'admin_email' ) ) . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
),
'subject' => array(
'title' => __( 'Subject', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject(),
'default' => '',
),
'heading' => array(
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading(),
'default' => '',
),
'additional_content' => array(
'title' => __( 'Additional content', 'woocommerce' ),
'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text,
'css' => 'width:400px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => $this->get_default_additional_content(),
'desc_tip' => true,
),
'email_type' => array(
'title' => __( 'Email type', 'woocommerce' ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
'default' => 'html',
'class' => 'email_type wc-enhanced-select',
'options' => $this->get_email_type_options(),
'desc_tip' => true,
),
);
if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
$this->form_fields['cc'] = $this->get_cc_field();
$this->form_fields['bcc'] = $this->get_bcc_field();
}
if ( $this->block_email_editor_enabled ) {
$this->form_fields['preheader'] = $this->get_preheader_field();
}
}
}
endif;
return new WC_Email_Failed_Order();

View File

@@ -0,0 +1,296 @@
<?php
/**
* Class WC_Email_New_Order file
*
* @package WooCommerce\Emails
*/
use Automattic\WooCommerce\Utilities\FeaturesUtil;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WC_Email_New_Order' ) ) :
/**
* New Order Email.
*
* An email sent to the admin when a new order is received/paid for.
*
* @class WC_Email_New_Order
* @version 2.0.0
* @package WooCommerce\Classes\Emails
* @extends WC_Email
*/
class WC_Email_New_Order extends WC_Email {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'new_order';
$this->title = __( 'New order', 'woocommerce' );
$this->email_group = 'orders';
$this->template_html = 'emails/admin-new-order.php';
$this->template_plain = 'emails/plain/admin-new-order.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Triggers for this email.
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_pending_to_completed_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_processing_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_failed_to_completed_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_cancelled_to_processing_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_cancelled_to_completed_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_order_status_cancelled_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
add_action( 'woocommerce_email_footer', array( $this, 'mobile_messaging' ), 9 ); // Run before the default email footer.
// Call parent constructor.
parent::__construct();
// Must be after parent's constructor which sets `email_improvements_enabled` property.
$this->description = $this->email_improvements_enabled
? __( 'Receive an email notification every time a new order is placed', 'woocommerce' )
: __( 'New order emails are sent to chosen recipient(s) when a new order is received.', 'woocommerce' );
// Other settings.
$this->recipient = $this->get_option( 'recipient', get_option( 'admin_email' ) );
if ( $this->block_email_editor_enabled ) {
$this->description = __( 'Notifies admins when a new order has been placed.', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return $this->email_improvements_enabled
? __( '[{site_title}]: You\'ve got a new order: #{order_number}', 'woocommerce' )
: __( '[{site_title}]: New order #{order_number}', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return $this->email_improvements_enabled
? __( 'New order: #{order_number}', 'woocommerce' )
: __( 'New Order: #{order_number}', 'woocommerce' );
}
/**
* 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 );
}
$email_already_sent = false;
if ( is_a( $order, 'WC_Order' ) ) {
$this->object = $order;
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$email_already_sent = $order->get_new_order_email_sent();
}
/**
* Controls if new order emails can be resend multiple times.
*
* @since 5.0.0
* @param bool $allows Defaults to false.
*/
if ( $email_already_sent && ! apply_filters( 'woocommerce_new_order_email_allows_resend', false ) ) {
return;
}
if ( $this->is_enabled() && $this->get_recipient() ) {
$email_sent_successfully = $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
if ( $email_sent_successfully ) {
$order->update_meta_data( '_new_order_email_sent', 'true' );
$order->save();
}
}
$this->restore_locale();
}
/**
* Get content html.
*
* @return string
*/
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => true,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Get content plain.
*
* @return string
*/
public function get_content_plain() {
return wc_get_template_html(
$this->template_plain,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'additional_content' => $this->get_additional_content(),
'sent_to_admin' => true,
'plain_text' => true,
'email' => $this,
)
);
}
/**
* Get block editor email template content.
*
* @return string
*/
public function get_block_editor_email_template_content() {
return wc_get_template_html(
$this->template_block_content,
array(
'order' => $this->object,
'sent_to_admin' => true,
'plain_text' => false,
'email' => $this,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return $this->email_improvements_enabled
? __( 'Congratulations on the sale!', 'woocommerce' )
: __( 'Congratulations on the sale.', 'woocommerce' );
}
/**
* Initialise settings form fields.
*/
public function init_form_fields() {
/* translators: %s: list of placeholders */
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '<code>' . implode( '</code>, <code>', array_keys( $this->placeholders ) ) . '</code>' );
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable this email notification', 'woocommerce' ),
'default' => 'yes',
),
'recipient' => array(
'title' => __( 'Recipient(s)', 'woocommerce' ),
'type' => 'text',
/* translators: %s: WP admin email */
'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to %s.', 'woocommerce' ), '<code>' . esc_attr( get_option( 'admin_email' ) ) . '</code>' ),
'placeholder' => '',
'default' => '',
'desc_tip' => true,
),
'subject' => array(
'title' => __( 'Subject', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject(),
'default' => '',
),
'heading' => array(
'title' => __( 'Email heading', 'woocommerce' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading(),
'default' => '',
),
'additional_content' => array(
'title' => __( 'Additional content', 'woocommerce' ),
'description' => __( 'Text to appear below the main email content.', 'woocommerce' ) . ' ' . $placeholder_text,
'css' => 'width:400px; height: 75px;',
'placeholder' => __( 'N/A', 'woocommerce' ),
'type' => 'textarea',
'default' => $this->get_default_additional_content(),
'desc_tip' => true,
),
'email_type' => array(
'title' => __( 'Email type', 'woocommerce' ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
'default' => 'html',
'class' => 'email_type wc-enhanced-select',
'options' => $this->get_email_type_options(),
'desc_tip' => true,
),
);
if ( FeaturesUtil::feature_is_enabled( 'email_improvements' ) ) {
$this->form_fields['cc'] = $this->get_cc_field();
$this->form_fields['bcc'] = $this->get_bcc_field();
}
if ( $this->block_email_editor_enabled ) {
$this->form_fields['preheader'] = $this->get_preheader_field();
}
}
/**
* Add mobile messaging.
*
* @param WC_Email $email that called for mobile messaging. May not contain a WC_Email for legacy reasons.
*/
public function mobile_messaging( $email ) {
if ( $email instanceof WC_Email_New_Order && null !== $this->object ) {
$domain = wp_parse_url( home_url(), PHP_URL_HOST );
wc_get_template(
'emails/email-mobile-messaging.php',
array(
'order' => $this->object,
'blog_id' => class_exists( 'Jetpack_Options' ) ? Jetpack_Options::get_option( 'id' ) : null,
'now' => new DateTime(),
'domain' => is_string( $domain ) ? $domain : '',
)
);
}
}
}
endif;
return new WC_Email_New_Order();

File diff suppressed because it is too large Load Diff