8889841cclass-wc-email-cancelled-order.php 0000644 00000014643 15051374377 0013123 0 ustar 00 id = 'cancelled_order';
$this->title = __( 'Cancelled order', 'woocommerce' );
$this->description = __( 'Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously processing or on-hold).', 'woocommerce' );
$this->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();
// 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 __( '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,
)
);
}
/**
* 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' ), '' . esc_html( implode( '
, ', array_keys( $this->placeholders ) ) ) . '
' );
$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' ), '' . esc_attr( get_option( 'admin_email' ) ) . '
' ),
'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,
),
);
}
}
endif;
return new WC_Email_Cancelled_Order();
class-wc-email-customer-invoice.php 0000644 00000016636 15051374377 0013377 0 ustar 00 id = 'customer_invoice';
$this->customer_email = true;
$this->title = __( 'Customer invoice / Order details', 'woocommerce' );
$this->description = __( 'Customer invoice emails can be sent to customers containing their order information and payment links.', 'woocommerce' );
$this->template_html = 'emails/customer-invoice.php';
$this->template_plain = 'emails/plain/customer-invoice.php';
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
);
// Call parent constructor.
parent::__construct();
$this->manual = true;
}
/**
* 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 ) {
if ( $paid ) {
return __( 'Invoice for order #{order_number} on {site_title}', 'woocommerce' );
} else {
return __( 'Your latest {site_title} invoice', '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 ) {
if ( $paid ) {
return __( 'Invoice for order #{order_number}', 'woocommerce' );
} else {
return __( 'Your invoice for order #{order_number}', 'woocommerce' );
}
}
/**
* Get email subject.
*
* @return string
*/
public function get_subject() {
if ( $this->object->has_status( array( 'completed', 'processing' ) ) ) {
$subject = $this->get_option( 'subject_paid', $this->get_default_subject( true ) );
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() );
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 __( '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' ), '' . esc_html( implode( '
, ', array_keys( $this->placeholders ) ) ) . '
' );
$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,
),
);
}
}
endif;
return new WC_Email_Customer_Invoice();
class-wc-email.php 0000644 00000101335 15051374377 0010075 0 ustar 00 ', // Greater-than.
'<', // Less-than.
'&', // Ampersand.
'&', // Ampersand.
'(c)', // Copyright.
'(tm)', // Trademark.
'(R)', // Registered.
'--', // mdash.
'-', // ndash.
'*', // Bullet.
'£', // Pound sign.
'EUR', // Euro sign. € ?.
'$', // Dollar sign.
'', // Unknown/unhandled entities.
' ', // Runs of spaces, post-handling.
);
/**
* Strings to find/replace in subjects/headings.
*
* @var array
*/
protected $placeholders = array();
/**
* Strings to find in subjects/headings.
*
* @deprecated 3.2.0 in favour of placeholders
* @var array
*/
public $find = array();
/**
* Strings to replace in subjects/headings.
*
* @deprecated 3.2.0 in favour of placeholders
* @var array
*/
public $replace = array();
/**
* Constructor.
*/
public function __construct() {
// Find/replace.
$this->placeholders = array_merge(
array(
'{site_title}' => $this->get_blogname(),
'{site_address}' => wp_parse_url( home_url(), PHP_URL_HOST ),
'{site_url}' => wp_parse_url( home_url(), PHP_URL_HOST ),
),
$this->placeholders
);
// Init settings.
$this->init_form_fields();
$this->init_settings();
// Default template base if not declared in child constructor.
if ( is_null( $this->template_base ) ) {
$this->template_base = WC()->plugin_path() . '/templates/';
}
$this->email_type = $this->get_option( 'email_type' );
$this->enabled = $this->get_option( 'enabled' );
add_action( 'phpmailer_init', array( $this, 'handle_multipart' ) );
add_action( 'woocommerce_update_options_email_' . $this->id, array( $this, 'process_admin_options' ) );
}
/**
* Handle multipart mail.
*
* @param PHPMailer $mailer PHPMailer object.
* @return PHPMailer
*/
public function handle_multipart( $mailer ) {
if ( $this->sending && 'multipart' === $this->get_email_type() ) {
$mailer->AltBody = wordwrap( // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
preg_replace( $this->plain_search, $this->plain_replace, wp_strip_all_tags( $this->get_content_plain() ) )
);
$this->sending = false;
}
return $mailer;
}
/**
* Format email string.
*
* @param mixed $string Text to replace placeholders in.
* @return string
*/
public function format_string( $string ) {
$find = array_keys( $this->placeholders );
$replace = array_values( $this->placeholders );
// If using legacy find replace, add those to our find/replace arrays first. @todo deprecate in 4.0.0.
$find = array_merge( (array) $this->find, $find );
$replace = array_merge( (array) $this->replace, $replace );
// Take care of blogname which is no longer defined as a valid placeholder.
$find[] = '{blogname}';
$replace[] = $this->get_blogname();
// If using the older style filters for find and replace, ensure the array is associative and then pass through filters. @todo deprecate in 4.0.0.
if ( has_filter( 'woocommerce_email_format_string_replace' ) || has_filter( 'woocommerce_email_format_string_find' ) ) {
$legacy_find = $this->find;
$legacy_replace = $this->replace;
foreach ( $this->placeholders as $find => $replace ) {
$legacy_key = sanitize_title( str_replace( '_', '-', trim( $find, '{}' ) ) );
$legacy_find[ $legacy_key ] = $find;
$legacy_replace[ $legacy_key ] = $replace;
}
$string = str_replace( apply_filters( 'woocommerce_email_format_string_find', $legacy_find, $this ), apply_filters( 'woocommerce_email_format_string_replace', $legacy_replace, $this ), $string );
}
/**
* Filter for main find/replace.
*
* @since 3.2.0
*/
return apply_filters( 'woocommerce_email_format_string', str_replace( $find, $replace, $string ), $this );
}
/**
* Set the locale to the store locale for customer emails to make sure emails are in the store language.
*/
public function setup_locale() {
if ( $this->is_customer_email() && apply_filters( 'woocommerce_email_setup_locale', true ) ) {
wc_switch_to_site_locale();
}
}
/**
* Restore the locale to the default locale. Use after finished with setup_locale.
*/
public function restore_locale() {
if ( $this->is_customer_email() && apply_filters( 'woocommerce_email_restore_locale', true ) ) {
wc_restore_locale();
}
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return $this->subject;
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return $this->heading;
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return '';
}
/**
* Return content from the additional_content field.
*
* Displayed above the footer.
*
* @since 3.7.0
* @return string
*/
public function get_additional_content() {
$content = $this->get_option( 'additional_content', '' );
return apply_filters( 'woocommerce_email_additional_content_' . $this->id, $this->format_string( $content ), $this->object, $this );
}
/**
* Get email subject.
*
* @return string
*/
public function get_subject() {
return apply_filters( 'woocommerce_email_subject_' . $this->id, $this->format_string( $this->get_option( 'subject', $this->get_default_subject() ) ), $this->object, $this );
}
/**
* Get email heading.
*
* @return string
*/
public function get_heading() {
return apply_filters( 'woocommerce_email_heading_' . $this->id, $this->format_string( $this->get_option( 'heading', $this->get_default_heading() ) ), $this->object, $this );
}
/**
* Get valid recipients.
*
* @return string
*/
public function get_recipient() {
$recipient = apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object, $this );
$recipients = array_map( 'trim', explode( ',', $recipient ) );
$recipients = array_filter( $recipients, 'is_email' );
return implode( ', ', $recipients );
}
/**
* Get email headers.
*
* @return string
*/
public function get_headers() {
$header = 'Content-Type: ' . $this->get_content_type() . "\r\n";
if ( in_array( $this->id, array( 'new_order', 'cancelled_order', 'failed_order' ), true ) ) {
if ( $this->object && $this->object->get_billing_email() && ( $this->object->get_billing_first_name() || $this->object->get_billing_last_name() ) ) {
$header .= 'Reply-to: ' . $this->object->get_billing_first_name() . ' ' . $this->object->get_billing_last_name() . ' <' . $this->object->get_billing_email() . ">\r\n";
}
} elseif ( $this->get_from_address() && $this->get_from_name() ) {
$header .= 'Reply-to: ' . $this->get_from_name() . ' <' . $this->get_from_address() . ">\r\n";
}
return apply_filters( 'woocommerce_email_headers', $header, $this->id, $this->object, $this );
}
/**
* Get email attachments.
*
* @return array
*/
public function get_attachments() {
return apply_filters( 'woocommerce_email_attachments', array(), $this->id, $this->object, $this );
}
/**
* Return email type.
*
* @return string
*/
public function get_email_type() {
return $this->email_type && class_exists( 'DOMDocument' ) ? $this->email_type : 'plain';
}
/**
* Get email content type.
*
* @param string $default_content_type Default wp_mail() content type.
* @return string
*/
public function get_content_type( $default_content_type = '' ) {
switch ( $this->get_email_type() ) {
case 'html':
$content_type = 'text/html';
break;
case 'multipart':
$content_type = 'multipart/alternative';
break;
default:
$content_type = 'text/plain';
break;
}
return apply_filters( 'woocommerce_email_content_type', $content_type, $this, $default_content_type );
}
/**
* Return the email's title
*
* @return string
*/
public function get_title() {
return apply_filters( 'woocommerce_email_title', $this->title, $this );
}
/**
* Return the email's description
*
* @return string
*/
public function get_description() {
return apply_filters( 'woocommerce_email_description', $this->description, $this );
}
/**
* Proxy to parent's get_option and attempt to localize the result using gettext.
*
* @param string $key Option key.
* @param mixed $empty_value Value to use when option is empty.
* @return string
*/
public function get_option( $key, $empty_value = null ) {
$value = parent::get_option( $key, $empty_value );
return apply_filters( 'woocommerce_email_get_option', $value, $this, $value, $key, $empty_value );
}
/**
* Checks if this email is enabled and will be sent.
*
* @return bool
*/
public function is_enabled() {
return apply_filters( 'woocommerce_email_enabled_' . $this->id, 'yes' === $this->enabled, $this->object, $this );
}
/**
* Checks if this email is manually sent
*
* @return bool
*/
public function is_manual() {
return $this->manual;
}
/**
* Checks if this email is customer focussed.
*
* @return bool
*/
public function is_customer_email() {
return $this->customer_email;
}
/**
* Get WordPress blog name.
*
* @return string
*/
public function get_blogname() {
return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
}
/**
* Get email content.
*
* @return string
*/
public function get_content() {
$this->sending = true;
if ( 'plain' === $this->get_email_type() ) {
$email_content = wordwrap( preg_replace( $this->plain_search, $this->plain_replace, wp_strip_all_tags( $this->get_content_plain() ) ), 70 );
} else {
$email_content = $this->get_content_html();
}
return $email_content;
}
/**
* Apply inline styles to dynamic content.
*
* We only inline CSS for html emails, and to do so we use Emogrifier library (if supported).
*
* @version 4.0.0
* @param string|null $content Content that will receive inline styles.
* @return string
*/
public function style_inline( $content ) {
if ( in_array( $this->get_content_type(), array( 'text/html', 'multipart/alternative' ), true ) ) {
ob_start();
wc_get_template( 'emails/email-styles.php' );
$css = apply_filters( 'woocommerce_email_styles', ob_get_clean(), $this );
$emogrifier_class = 'Pelago\\Emogrifier';
if ( $this->supports_emogrifier() && class_exists( $emogrifier_class ) ) {
try {
$emogrifier = new $emogrifier_class( $content, $css );
do_action( 'woocommerce_emogrifier', $emogrifier, $this );
$content = $emogrifier->emogrify();
$html_prune = \Pelago\Emogrifier\HtmlProcessor\HtmlPruner::fromHtml( $content );
$html_prune->removeElementsWithDisplayNone();
$content = $html_prune->render();
} catch ( Exception $e ) {
$logger = wc_get_logger();
$logger->error( $e->getMessage(), array( 'source' => 'emogrifier' ) );
}
} else {
$content = '' . $content;
}
}
return $content;
}
/**
* Return if emogrifier library is supported.
*
* @version 4.0.0
* @since 3.5.0
* @return bool
*/
protected function supports_emogrifier() {
return class_exists( 'DOMDocument' );
}
/**
* Get the email content in plain text format.
*
* @return string
*/
public function get_content_plain() {
return '';
}
/**
* Get the email content in HTML format.
*
* @return string
*/
public function get_content_html() {
return '';
}
/**
* Get the from name for outgoing emails.
*
* @param string $from_name Default wp_mail() name associated with the "from" email address.
* @return string
*/
public function get_from_name( $from_name = '' ) {
$from_name = apply_filters( 'woocommerce_email_from_name', get_option( 'woocommerce_email_from_name' ), $this, $from_name );
return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
}
/**
* Get the from address for outgoing emails.
*
* @param string $from_email Default wp_mail() email address to send from.
* @return string
*/
public function get_from_address( $from_email = '' ) {
$from_email = apply_filters( 'woocommerce_email_from_address', get_option( 'woocommerce_email_from_address' ), $this, $from_email );
return sanitize_email( $from_email );
}
/**
* Send an email.
*
* @param string $to Email to.
* @param string $subject Email subject.
* @param string $message Email message.
* @param string $headers Email headers.
* @param array $attachments Email attachments.
* @return bool success
*/
public function send( $to, $subject, $message, $headers, $attachments ) {
add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
$message = apply_filters( 'woocommerce_mail_content', $this->style_inline( $message ) );
$mail_callback = apply_filters( 'woocommerce_mail_callback', 'wp_mail', $this );
$mail_callback_params = apply_filters( 'woocommerce_mail_callback_params', array( $to, $subject, $message, $headers, $attachments ), $this );
$return = $mail_callback( ...$mail_callback_params );
remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
/**
* Action hook fired when an email is sent.
*
* @since 5.6.0
* @param bool $return Whether the email was sent successfully.
* @param int $id Email ID.
* @param WC_Email $this WC_Email instance.
*/
do_action( 'woocommerce_email_sent', $return, $this->id, $this );
return $return;
}
/**
* Initialise Settings Form Fields - these are generic email options most will use.
*/
public function init_form_fields() {
/* translators: %s: list of placeholders */
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce' ), '' . esc_html( implode( '
, ', array_keys( $this->placeholders ) ) ) . '
' );
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'woocommerce' ),
'type' => 'checkbox',
'label' => __( 'Enable this email notification', 'woocommerce' ),
'default' => 'yes',
),
'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,
),
);
}
/**
* Email type options.
*
* @return array
*/
public function get_email_type_options() {
$types = array( 'plain' => __( 'Plain text', 'woocommerce' ) );
if ( class_exists( 'DOMDocument' ) ) {
$types['html'] = __( 'HTML', 'woocommerce' );
$types['multipart'] = __( 'Multipart', 'woocommerce' );
}
return $types;
}
/**
* Admin Panel Options Processing.
*/
public function process_admin_options() {
// Save regular options.
parent::process_admin_options();
$post_data = $this->get_post_data();
// Save templates.
if ( isset( $post_data['template_html_code'] ) ) {
$this->save_template( $post_data['template_html_code'], $this->template_html );
}
if ( isset( $post_data['template_plain_code'] ) ) {
$this->save_template( $post_data['template_plain_code'], $this->template_plain );
}
}
/**
* Get template.
*
* @param string $type Template type. Can be either 'template_html' or 'template_plain'.
* @return string
*/
public function get_template( $type ) {
$type = basename( $type );
if ( 'template_html' === $type ) {
return $this->template_html;
} elseif ( 'template_plain' === $type ) {
return $this->template_plain;
}
return '';
}
/**
* Save the email templates.
*
* @since 2.4.0
* @param string $template_code Template code.
* @param string $template_path Template path.
*/
protected function save_template( $template_code, $template_path ) {
if ( current_user_can( 'edit_themes' ) && ! empty( $template_code ) && ! empty( $template_path ) ) {
$saved = false;
$file = get_stylesheet_directory() . '/' . WC()->template_path() . $template_path;
$code = wp_unslash( $template_code );
if ( is_writeable( $file ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writeable
$f = fopen( $file, 'w+' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen
if ( false !== $f ) {
fwrite( $f, $code ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite
fclose( $f ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
$saved = true;
}
}
if ( ! $saved ) {
$redirect = add_query_arg( 'wc_error', rawurlencode( __( 'Could not write to template file.', 'woocommerce' ) ) );
wp_safe_redirect( $redirect );
exit;
}
}
}
/**
* Get the template file in the current theme.
*
* @param string $template Template name.
*
* @return string
*/
public function get_theme_template_file( $template ) {
return get_stylesheet_directory() . '/' . apply_filters( 'woocommerce_template_directory', 'woocommerce', $template ) . '/' . $template;
}
/**
* Move template action.
*
* @param string $template_type Template type.
*/
protected function move_template_action( $template_type ) {
$template = $this->get_template( $template_type );
if ( ! empty( $template ) ) {
$theme_file = $this->get_theme_template_file( $template );
if ( wp_mkdir_p( dirname( $theme_file ) ) && ! file_exists( $theme_file ) ) {
// Locate template file.
$core_file = $this->template_base . $template;
$template_file = apply_filters( 'woocommerce_locate_core_template', $core_file, $template, $this->template_base, $this->id );
// Copy template file.
copy( $template_file, $theme_file );
/**
* Action hook fired after copying email template file.
*
* @param string $template_type The copied template type
* @param string $email The email object
*/
do_action( 'woocommerce_copy_email_template', $template_type, $this );
?>
' . esc_html( implode( '
, ', array_keys( $this->placeholders ) ) ) . '
' );
$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' ), '' . esc_attr( get_option( 'admin_email' ) ) . '
' ),
'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,
),
);
}
}
endif;
return new WC_Email_Failed_Order();
class-wc-email-customer-reset-password.php 0000644 00000010061 15051374377 0014707 0 ustar 00 id = 'customer_reset_password';
$this->customer_email = true;
$this->title = __( 'Reset password', 'woocommerce' );
$this->description = __( 'Customer "reset password" emails are sent when customers reset their passwords.', 'woocommerce' );
$this->template_html = 'emails/customer-reset-password.php';
$this->template_plain = 'emails/plain/customer-reset-password.php';
// Trigger.
add_action( 'woocommerce_reset_password_notification', array( $this, 'trigger' ), 10, 2 );
// Call parent constructor.
parent::__construct();
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( 'Password Reset Request for {site_title}', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( '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,
)
);
}
/**
* 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();
class-wc-email-customer-on-hold-order.php 0000644 00000010024 15051374377 0014375 0 ustar 00 id = 'customer_on_hold_order';
$this->customer_email = true;
$this->title = __( 'Order on-hold', 'woocommerce' );
$this->description = __( 'This is an order notification sent to customers containing order details after an order is placed on-hold.', 'woocommerce' );
$this->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();
}
/**
* 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 __( 'We look forward to fulfilling your order soon.', 'woocommerce' );
}
}
endif;
return new WC_Email_Customer_On_Hold_Order();
class-wc-email-customer-completed-order.php 0000644 00000007627 15051374377 0015030 0 ustar 00 id = 'customer_completed_order';
$this->customer_email = true;
$this->title = __( 'Completed order', 'woocommerce' );
$this->description = __( 'Order complete emails are sent to customers when their orders are marked completed and usually indicate that their orders have been shipped.', 'woocommerce' );
$this->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();
}
/**
* 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 {site_title} order is now complete', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( '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 __( 'Thanks for shopping with us.', 'woocommerce' );
}
}
endif;
return new WC_Email_Customer_Completed_Order();
class-wc-email-customer-processing-order.php 0000644 00000010206 15051374377 0015213 0 ustar 00 id = 'customer_processing_order';
$this->customer_email = true;
$this->title = __( 'Processing order', 'woocommerce' );
$this->description = __( 'This is an order notification sent to customers containing order details after payment.', 'woocommerce' );
$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();
}
/**
* 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 __( 'Thanks for using {site_url}!', 'woocommerce' );
}
}
endif;
return new WC_Email_Customer_Processing_Order();
class-wc-email-new-order.php 0000644 00000016433 15051374377 0012001 0 ustar 00 id = 'new_order';
$this->title = __( 'New order', 'woocommerce' );
$this->description = __( 'New order emails are sent to chosen recipient(s) when a new order is received.', 'woocommerce' );
$this->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 );
// Call parent constructor.
parent::__construct();
// 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}]: New order #{order_number}', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( '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 );
}
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_meta( '_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 ( 'true' === $email_already_sent && ! apply_filters( 'woocommerce_new_order_email_allows_resend', false ) ) {
return;
}
if ( $this->is_enabled() && $this->get_recipient() ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$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,
)
);
}
/**
* Default content to show below main email content.
*
* @since 3.7.0
* @return string
*/
public function get_default_additional_content() {
return __( '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' ), '' . implode( '
, ', array_keys( $this->placeholders ) ) . '
' );
$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' ), '' . esc_attr( get_option( 'admin_email' ) ) . '
' ),
'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,
),
);
}
}
endif;
return new WC_Email_New_Order();
class-wc-email-customer-refunded-order.php 0000644 00000022070 15051374377 0014635 0 ustar 00 customer_email = true;
$this->id = 'customer_refunded_order';
$this->title = __( 'Refunded order', 'woocommerce' );
$this->description = __( 'Order refunded emails are sent to customers when their orders are refunded.', 'woocommerce' );
$this->template_html = 'emails/customer-refunded-order.php';
$this->template_plain = 'emails/plain/customer-refunded-order.php';
$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();
}
/**
* 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 __( 'Partial Refund: Order {order_number}', 'woocommerce' );
} else {
return __( '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() );
}
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() );
}
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(),
'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(),
'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 __( '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' ), '' . esc_html( implode( '
, ', array_keys( $this->placeholders ) ) ) . '
' );
$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,
),
);
}
}
endif;
return new WC_Email_Customer_Refunded_Order();
class-wc-email-customer-note.php 0000644 00000007725 15051374377 0012707 0 ustar 00 id = 'customer_note';
$this->customer_email = true;
$this->title = __( 'Customer note', 'woocommerce' );
$this->description = __( 'Customer note emails are sent when you add a note to an order.', 'woocommerce' );
$this->template_html = 'emails/customer-note.php';
$this->template_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();
}
/**
* Get email subject.
*
* @since 3.1.0
* @return string
*/
public function get_default_subject() {
return __( 'Note added to your {site_title} order from {order_date}', 'woocommerce' );
}
/**
* Get email heading.
*
* @since 3.1.0
* @return string
*/
public function get_default_heading() {
return __( 'A note has been added to your order', 'woocommerce' );
}
/**
* 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 __( 'Thanks for reading.', 'woocommerce' );
}
}
endif;
return new WC_Email_Customer_Note();