2011-12-10 17:28:32 +00:00
< ? php
/**
2012-01-30 19:24:52 +00:00
* Email
*
* WooCommerce Emails Class which handles the sending on transactional emails and email templates
2011-12-10 17:28:32 +00:00
*
2012-01-27 16:38:39 +00:00
* @ class WC_Email
2012-08-14 19:42:38 +00:00
* @ version 1.6 . 4
2012-08-14 22:43:48 +00:00
* @ package WooCommerce / Classes
2012-08-14 19:42:38 +00:00
* @ author WooThemes
2011-12-10 17:28:32 +00:00
*/
2012-01-27 16:38:39 +00:00
class WC_Email {
2012-08-14 19:42:38 +00:00
2012-08-15 17:08:42 +00:00
/**
* @ var string Stores the emailer ' s address .
* @ access private
*/
2011-12-10 17:28:32 +00:00
private $_from_address ;
2012-08-15 17:08:42 +00:00
/**
* @ var string Stores the emailer ' s name .
* @ access private
*/
2011-12-10 17:28:32 +00:00
private $_from_name ;
2012-08-14 19:42:38 +00:00
/**
2012-08-15 17:08:42 +00:00
* Constructor for the email class hooks in all emails that can be sent .
2012-08-14 19:42:38 +00:00
*
* @ access public
* @ return void
*/
2011-12-10 17:28:32 +00:00
function __construct () {
$this -> _from_name = get_option ( 'woocommerce_email_from_name' );
$this -> _from_address = get_option ( 'woocommerce_email_from_address' );
/**
* Email Header + Footer
**/
add_action ( 'woocommerce_email_header' , array ( & $this , 'email_header' ));
add_action ( 'woocommerce_email_footer' , array ( & $this , 'email_footer' ));
/**
* Add order meta to email templates
**/
add_action ( 'woocommerce_email_after_order_table' , array ( & $this , 'order_meta' ), 10 , 2 );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
* Hooks for sending emails during store events
**/
add_action ( 'woocommerce_low_stock_notification' , array ( & $this , 'low_stock' ));
add_action ( 'woocommerce_no_stock_notification' , array ( & $this , 'no_stock' ));
add_action ( 'woocommerce_product_on_backorder_notification' , array ( & $this , 'backorder' ));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
add_action ( 'woocommerce_order_status_pending_to_processing_notification' , array ( & $this , 'new_order' ));
add_action ( 'woocommerce_order_status_pending_to_completed_notification' , array ( & $this , 'new_order' ));
add_action ( 'woocommerce_order_status_pending_to_on-hold_notification' , array ( & $this , 'new_order' ));
add_action ( 'woocommerce_order_status_failed_to_processing_notification' , array ( & $this , 'new_order' ));
add_action ( 'woocommerce_order_status_failed_to_completed_notification' , array ( & $this , 'new_order' ));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
add_action ( 'woocommerce_order_status_pending_to_processing_notification' , array ( & $this , 'customer_processing_order' ));
add_action ( 'woocommerce_order_status_pending_to_on-hold_notification' , array ( & $this , 'customer_processing_order' ));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
add_action ( 'woocommerce_order_status_completed_notification' , array ( & $this , 'customer_completed_order' ));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
add_action ( 'woocommerce_new_customer_note_notification' , array ( & $this , 'customer_note' ));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Let 3rd parties unhook the above via this hook
do_action ( 'woocommerce_email' , $this );
}
2012-08-14 19:42:38 +00:00
/**
* Get from name for email .
*
* @ access public
* @ return string
*/
2011-12-10 17:28:32 +00:00
function get_from_name () {
return $this -> _from_name ;
}
2012-08-14 19:42:38 +00:00
/**
* Get from email address .
*
* @ access public
* @ return string
*/
2011-12-10 17:28:32 +00:00
function get_from_address () {
return $this -> _from_address ;
}
2012-08-14 19:42:38 +00:00
/**
* Get the content type for the email .
*
* @ access public
* @ return string
*/
2011-12-10 17:28:32 +00:00
function get_content_type () {
return 'text/html' ;
}
2012-08-14 19:42:38 +00:00
/**
* Get the email header .
*
* @ access public
* @ param mixed $email_heading heading for the email
* @ return void
*/
2012-02-03 16:17:35 +00:00
function email_header ( $email_heading ) {
woocommerce_get_template ( 'emails/email-header.php' , array ( 'email_heading' => $email_heading ));
2011-12-10 17:28:32 +00:00
}
2012-08-14 19:42:38 +00:00
/**
* Get the email footer .
*
* @ access public
* @ return void
*/
2011-12-10 17:28:32 +00:00
function email_footer () {
2012-02-03 16:17:35 +00:00
woocommerce_get_template ( 'emails/email-footer.php' );
2011-12-10 17:28:32 +00:00
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 19:42:38 +00:00
* Wraps a message in the woocommerce mail template .
*
* @ access public
* @ param mixed $email_heading
* @ param mixed $message
* @ return string
*/
function wrap_message ( $email_heading , $message ) {
2011-12-10 17:28:32 +00:00
// Buffer
ob_start ();
2012-08-14 19:42:38 +00:00
2012-02-03 16:17:35 +00:00
do_action ( 'woocommerce_email_header' , $email_heading );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
echo wpautop ( wptexturize ( $message ));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
do_action ( 'woocommerce_email_footer' );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get contents
2012-01-13 11:58:35 +00:00
$message = ob_get_clean ();
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
return $message ;
}
2012-08-14 19:42:38 +00:00
/**
* Send the email .
*
* @ access public
* @ param mixed $to
* @ param mixed $subject
* @ param mixed $message
* @ param string $headers ( default : " Content-Type: text/html \r \n " )
* @ param string $attachments ( default : " " )
* @ return void
*/
function send ( $to , $subject , $message , $headers = " Content-Type: text/html \r \n " , $attachments = " " ) {
2011-12-10 17:28:32 +00:00
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' ) );
2012-08-14 19:42:38 +00:00
2012-01-17 17:31:42 +00:00
ob_start ();
2012-08-14 19:42:38 +00:00
2012-01-13 11:58:35 +00:00
wp_mail ( $to , $subject , $message , $headers , $attachments );
2012-08-14 19:42:38 +00:00
2012-01-17 17:31:42 +00:00
ob_end_clean ();
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Unhook
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' ) );
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 19:42:38 +00:00
* Prepare and send the new order email .
*
* @ access public
* @ param mixed $order_id
* @ return void
*/
2011-12-10 17:28:32 +00:00
function new_order ( $order_id ) {
2012-08-14 19:42:38 +00:00
2012-01-27 16:38:39 +00:00
$order = new WC_Order ( $order_id );
2012-08-14 19:42:38 +00:00
2012-01-05 11:31:22 +00:00
$email_heading = __ ( 'New Customer Order' , 'woocommerce' );
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$blogname = wp_specialchars_decode ( get_option ( 'blogname' ), ENT_QUOTES );
2012-08-14 19:42:38 +00:00
2012-06-20 17:18:16 +00:00
$subject = apply_filters ( 'woocommerce_email_subject_new_order' , sprintf ( __ ( '[%s] New Customer Order (%s)' , 'woocommerce' ), $blogname , $order -> get_order_number () ), $order );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Buffer
ob_start ();
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get mail template
2012-02-03 16:17:35 +00:00
woocommerce_get_template ( 'emails/admin-new-order.php' , array (
'order' => $order ,
'email_heading' => $email_heading
));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get contents
$message = ob_get_clean ();
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// CC, BCC, additional headers
2012-06-27 01:09:39 +00:00
$headers = apply_filters ( 'woocommerce_email_headers' , '' , 'new_order' , $order );
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// Attachments
2012-06-27 01:09:39 +00:00
$attachments = apply_filters ( 'woocommerce_email_attachments' , '' , 'new_order' , $order );
2012-03-03 11:34:49 +00:00
2012-08-14 19:42:38 +00:00
// Send the mail
2012-03-03 11:34:49 +00:00
$this -> send ( get_option ( 'woocommerce_new_order_email_recipient' ), $subject , $message , $headers , $attachments );
2011-12-10 17:28:32 +00:00
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 19:42:38 +00:00
* Prepare and send the customer processing order email .
*
* @ access public
* @ param mixed $order_id
* @ return void
*/
2011-12-10 17:28:32 +00:00
function customer_processing_order ( $order_id ) {
2012-08-14 19:42:38 +00:00
2012-01-27 16:38:39 +00:00
$order = new WC_Order ( $order_id );
2011-12-10 17:28:32 +00:00
2012-01-05 11:31:22 +00:00
$email_heading = __ ( 'Order Received' , 'woocommerce' );
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$blogname = wp_specialchars_decode ( get_option ( 'blogname' ), ENT_QUOTES );
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$subject = apply_filters ( 'woocommerce_email_subject_customer_procesing_order' , sprintf ( __ ( '[%s] Order Received' , 'woocommerce' ), $blogname ), $order );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Buffer
ob_start ();
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get mail template
2012-02-03 16:17:35 +00:00
woocommerce_get_template ( 'emails/customer-processing-order.php' , array (
'order' => $order ,
'email_heading' => $email_heading
));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get contents
$message = ob_get_clean ();
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// CC, BCC, additional headers
2012-06-27 01:09:39 +00:00
$headers = apply_filters ( 'woocommerce_email_headers' , '' , 'customer_processing_order' , $order );
2012-08-14 19:42:38 +00:00
2011-12-12 17:59:39 +00:00
// Attachments
2012-06-27 01:09:39 +00:00
$attachments = apply_filters ( 'woocommerce_email_attachments' , '' , 'customer_processing_order' , $order );
2012-08-14 19:42:38 +00:00
// Send the mail
2012-03-03 11:34:49 +00:00
$this -> send ( $order -> billing_email , $subject , $message , $headers , $attachments );
2011-12-10 17:28:32 +00:00
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 19:42:38 +00:00
* Prepare and send the completed order email .
*
* @ access public
* @ param mixed $order_id
* @ return void
*/
2011-12-10 17:28:32 +00:00
function customer_completed_order ( $order_id ) {
2012-08-14 19:42:38 +00:00
2012-01-27 16:38:39 +00:00
$order = new WC_Order ( $order_id );
2012-08-14 19:42:38 +00:00
2012-01-17 17:01:30 +00:00
if ( $order -> has_downloadable_item ()) :
2012-01-05 11:31:22 +00:00
$subject = __ ( '[%s] Order Complete/Download Links' , 'woocommerce' );
$email_heading = __ ( 'Order Complete/Download Links' , 'woocommerce' );
2011-12-10 17:28:32 +00:00
else :
2012-01-05 11:31:22 +00:00
$subject = __ ( '[%s] Order Complete' , 'woocommerce' );
$email_heading = __ ( 'Order Complete' , 'woocommerce' );
2011-12-10 17:28:32 +00:00
endif ;
2012-08-14 19:42:38 +00:00
2012-07-16 14:57:18 +00:00
$email_heading = apply_filters ( 'woocommerce_email_heading_customer_completed_order' , $email_heading );
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$blogname = wp_specialchars_decode ( get_option ( 'blogname' ), ENT_QUOTES );
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$subject = apply_filters ( 'woocommerce_email_subject_customer_completed_order' , sprintf ( $subject , $blogname ), $order );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Buffer
ob_start ();
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get mail template
2012-02-03 16:17:35 +00:00
woocommerce_get_template ( 'emails/customer-completed-order.php' , array (
'order' => $order ,
'email_heading' => $email_heading
));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get contents
$message = ob_get_clean ();
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// CC, BCC, additional headers
2012-06-27 01:09:39 +00:00
$headers = apply_filters ( 'woocommerce_email_headers' , '' , 'customer_completed_order' , $order );
2012-08-14 19:42:38 +00:00
2011-12-12 17:59:39 +00:00
// Attachments
2012-06-27 01:09:39 +00:00
$attachments = apply_filters ( 'woocommerce_email_attachments' , '' , 'customer_completed_order' , $order );
2012-08-14 19:42:38 +00:00
// Send the mail
2012-03-03 11:34:49 +00:00
$this -> send ( $order -> billing_email , $subject , $message , $headers , $attachments );
2011-12-10 17:28:32 +00:00
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 19:42:38 +00:00
* Prepare and send the customer invoice email .
*
* @ access public
* @ param mixed $pay_for_order
* @ return void
*/
2012-01-29 13:36:33 +00:00
function customer_invoice ( $pay_for_order ) {
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
$order = $pay_for_order ;
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$blogname = wp_specialchars_decode ( get_option ( 'blogname' ), ENT_QUOTES );
2012-08-14 19:42:38 +00:00
2012-03-26 20:11:39 +00:00
if ( $order -> status == 'processing' || $order -> status == 'completed' ) {
$email_heading = sprintf ( __ ( 'Your order on %s' , 'woocommerce' ), $blogname );
$subject = apply_filters ( 'woocommerce_email_subject_customer_invoice_paid' , sprintf ( __ ( '[%s] Your order' , 'woocommerce' ), $blogname ), $order );
} else {
2012-06-20 17:18:16 +00:00
$email_heading = sprintf ( __ ( 'Invoice for Order %s' , 'woocommerce' ), $order -> get_order_number () );
2012-03-26 20:11:39 +00:00
$subject = apply_filters ( 'woocommerce_email_subject_customer_invoice' , sprintf ( __ ( '[%s] Pay for Order' , 'woocommerce' ), $blogname ), $order );
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Buffer
ob_start ();
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get mail template
2012-02-03 16:17:35 +00:00
woocommerce_get_template ( 'emails/customer-invoice.php' , array (
'order' => $order ,
'email_heading' => $email_heading
));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get contents
$message = ob_get_clean ();
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// CC, BCC, additional headers
2012-06-27 01:09:39 +00:00
$headers = apply_filters ( 'woocommerce_email_headers' , '' , 'customer_invoice' , $order );
2012-08-14 19:42:38 +00:00
2011-12-12 17:59:39 +00:00
// Attachments
2012-06-27 01:09:39 +00:00
$attachments = apply_filters ( 'woocommerce_email_attachments' , '' , 'customer_invoice' , $order );
2012-08-14 19:42:38 +00:00
// Send the mail
2012-03-05 09:44:22 +00:00
$this -> send ( $order -> billing_email , $subject , $message , $headers , $attachments );
2011-12-10 17:28:32 +00:00
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 19:42:38 +00:00
* Prepare and send a customer note email .
*
* @ access public
* @ param mixed $args
* @ return void
*/
2011-12-10 17:28:32 +00:00
function customer_note ( $args ) {
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
$defaults = array (
'order_id' => '' ,
'customer_note' => ''
);
$args = wp_parse_args ( $args , $defaults );
2011-12-11 14:40:25 +00:00
extract ( $args );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
if ( ! $order_id || ! $customer_note ) return ;
2012-08-14 19:42:38 +00:00
2012-01-27 16:38:39 +00:00
$order = new WC_Order ( $order_id );
2012-08-14 19:42:38 +00:00
2012-01-05 11:31:22 +00:00
$email_heading = __ ( 'A note has been added to your order' , 'woocommerce' );
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$blogname = wp_specialchars_decode ( get_option ( 'blogname' ), ENT_QUOTES );
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$subject = apply_filters ( 'woocommerce_email_subject_customer_note' , sprintf ( __ ( '[%s] A note has been added to your order' , 'woocommerce' ), $blogname ), $order );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Buffer
ob_start ();
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get mail template
2012-02-03 16:17:35 +00:00
woocommerce_get_template ( 'emails/customer-note.php' , array (
'order' => $order ,
'email_heading' => $email_heading ,
'customer_note' => $customer_note
));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get contents
$message = ob_get_clean ();
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// CC, BCC, additional headers
2012-06-27 01:09:39 +00:00
$headers = apply_filters ( 'woocommerce_email_headers' , '' , 'customer_note' , $order );
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// Attachments
2012-06-27 01:09:39 +00:00
$attachments = apply_filters ( 'woocommerce_email_attachments' , '' , 'customer_note' , $order );
2012-08-14 19:42:38 +00:00
// Send the mail
2012-03-03 11:34:49 +00:00
$this -> send ( $order -> billing_email , $subject , $message , $headers , $attachments );
2011-12-10 17:28:32 +00:00
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 19:42:38 +00:00
* Low stock notification email .
*
* @ access public
* @ param mixed $product
* @ return void
*/
2011-12-10 17:28:32 +00:00
function low_stock ( $product ) {
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$blogname = wp_specialchars_decode ( get_option ( 'blogname' ), ENT_QUOTES );
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$subject = apply_filters ( 'woocommerce_email_subject_low_stock' , sprintf ( '[%s] %s' , $blogname , __ ( 'Product low in stock' , 'woocommerce' ) ), $product );
2012-08-14 19:42:38 +00:00
2012-03-07 13:38:51 +00:00
$sku = ( $product -> sku ) ? '(' . $product -> sku . ') ' : '' ;
2012-08-14 19:42:38 +00:00
if ( ! empty ( $product -> variation_id ) )
2012-03-07 13:38:51 +00:00
$title = sprintf ( __ ( 'Variation #%s of %s' , 'woocommerce' ), $product -> variation_id , get_the_title ( $product -> id )) . ' ' . $sku ;
2012-08-14 19:42:38 +00:00
else
2012-03-07 13:38:51 +00:00
$title = sprintf ( __ ( 'Product #%s - %s' , 'woocommerce' ), $product -> id , get_the_title ( $product -> id )) . ' ' . $sku ;
2012-08-14 19:42:38 +00:00
2012-03-07 13:38:51 +00:00
$message = $title . __ ( 'is low in stock.' , 'woocommerce' );
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// CC, BCC, additional headers
2012-06-27 01:09:39 +00:00
$headers = apply_filters ( 'woocommerce_email_headers' , '' , 'low_stock' , $product );
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// Attachments
2012-06-27 01:09:39 +00:00
$attachments = apply_filters ( 'woocommerce_email_attachments' , '' , 'low_stock' , $product );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Send the mail
2012-03-03 11:34:49 +00:00
wp_mail ( get_option ( 'woocommerce_stock_email_recipient' ), $subject , $message , $headers , $attachments );
2011-12-10 17:28:32 +00:00
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 19:42:38 +00:00
* No stock notification email .
*
* @ access public
* @ param mixed $product
* @ return void
*/
2011-12-10 17:28:32 +00:00
function no_stock ( $product ) {
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$blogname = wp_specialchars_decode ( get_option ( 'blogname' ), ENT_QUOTES );
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$subject = apply_filters ( 'woocommerce_email_subject_no_stock' , sprintf ( '[%s] %s' , $blogname , __ ( 'Product out of stock' , 'woocommerce' ) ), $product );
2012-03-07 13:38:51 +00:00
$sku = ( $product -> sku ) ? '(' . $product -> sku . ') ' : '' ;
2012-08-14 19:42:38 +00:00
if ( ! empty ( $product -> variation_id ) )
2012-03-07 13:38:51 +00:00
$title = sprintf ( __ ( 'Variation #%s of %s' , 'woocommerce' ), $product -> variation_id , get_the_title ( $product -> id )) . ' ' . $sku ;
2012-08-14 19:42:38 +00:00
else
2012-03-07 13:38:51 +00:00
$title = sprintf ( __ ( 'Product #%s - %s' , 'woocommerce' ), $product -> id , get_the_title ( $product -> id )) . ' ' . $sku ;
2012-08-14 19:42:38 +00:00
2012-03-07 13:38:51 +00:00
$message = $title . __ ( 'is out of stock.' , 'woocommerce' );
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// CC, BCC, additional headers
2012-06-27 01:09:39 +00:00
$headers = apply_filters ( 'woocommerce_email_headers' , '' , 'no_stock' , $product );
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// Attachments
2012-06-27 01:09:39 +00:00
$attachments = apply_filters ( 'woocommerce_email_attachments' , '' , 'no_stock' , $product );
2012-03-03 11:34:49 +00:00
2011-12-10 17:28:32 +00:00
// Send the mail
2012-03-03 11:34:49 +00:00
wp_mail ( get_option ( 'woocommerce_stock_email_recipient' ), $subject , $message , $headers , $attachments );
2011-12-10 17:28:32 +00:00
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 19:42:38 +00:00
* Backorder notification email .
*
* @ access public
* @ param mixed $args
* @ return void
*/
2011-12-10 17:28:32 +00:00
function backorder ( $args ) {
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
$defaults = array (
'product' => '' ,
2011-12-23 19:46:27 +00:00
'quantity' => '' ,
'order_id' => ''
2011-12-10 17:28:32 +00:00
);
$args = wp_parse_args ( $args , $defaults );
2011-12-11 14:40:25 +00:00
extract ( $args );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
if ( ! $product || ! $quantity ) return ;
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$blogname = wp_specialchars_decode ( get_option ( 'blogname' ), ENT_QUOTES );
2012-08-14 19:42:38 +00:00
2012-02-02 11:53:44 +00:00
$subject = apply_filters ( 'woocommerce_email_subject_backorder' , sprintf ( '[%s] %s' , $blogname , __ ( 'Product Backorder' , 'woocommerce' ) ), $product );
2012-08-14 19:42:38 +00:00
2012-03-07 13:38:51 +00:00
$sku = ( $product -> sku ) ? ' (' . $product -> sku . ')' : '' ;
2012-08-14 19:42:38 +00:00
if ( ! empty ( $product -> variation_id ) )
2012-03-07 13:38:51 +00:00
$title = sprintf ( __ ( 'Variation #%s of %s' , 'woocommerce' ), $product -> variation_id , get_the_title ( $product -> id )) . $sku ;
2012-08-14 19:42:38 +00:00
else
2012-03-07 13:38:51 +00:00
$title = sprintf ( __ ( 'Product #%s - %s' , 'woocommerce' ), $product -> id , get_the_title ( $product -> id )) . $sku ;
2012-08-14 19:42:38 +00:00
2012-03-07 13:38:51 +00:00
$message = sprintf ( __ ( '%s units of %s have been backordered in order #%s.' , 'woocommerce' ), $quantity , $title , $order_id );
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// CC, BCC, additional headers
2012-06-27 01:09:39 +00:00
$headers = apply_filters ( 'woocommerce_email_headers' , '' , 'backorder' , $args );
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// Attachments
2012-06-27 01:09:39 +00:00
$attachments = apply_filters ( 'woocommerce_email_attachments' , '' , 'backorder' , $args );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Send the mail
2012-03-03 11:34:49 +00:00
wp_mail ( get_option ( 'woocommerce_stock_email_recipient' ), $subject , $message , $headers , $attachments );
2011-12-10 17:28:32 +00:00
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 19:42:38 +00:00
* Add order meta to email templates .
*
* @ access public
* @ param mixed $order
* @ param mixed $sent_to_admin
* @ return void
*/
2011-12-10 17:28:32 +00:00
function order_meta ( $order , $sent_to_admin ) {
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
$meta = array ();
$show_fields = apply_filters ( 'woocommerce_email_order_meta_keys' , array ( 'coupons' ), $sent_to_admin );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
if ( $order -> customer_note ) :
2012-03-09 16:12:36 +00:00
$meta [ __ ( 'Note' , 'woocommerce' )] = wptexturize ( $order -> customer_note );
2011-12-10 17:28:32 +00:00
endif ;
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
if ( $show_fields ) foreach ( $show_fields as $field ) :
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
$value = get_post_meta ( $order -> id , $field , true );
if ( $value ) $meta [ ucwords ( esc_attr ( $field ))] = wptexturize ( $value );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
endforeach ;
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
if ( sizeof ( $meta ) > 0 ) :
2012-01-05 11:31:22 +00:00
echo '<h2>' . __ ( 'Order information' , 'woocommerce' ) . '</h2>' ;
2011-12-10 17:28:32 +00:00
foreach ( $meta as $key => $value ) :
echo '<p><strong>' . $key . ':</strong> ' . $value . '</p>' ;
endforeach ;
endif ;
}
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
/**
2012-08-14 19:42:38 +00:00
* Customer new account welcome email .
*
* @ access public
* @ param mixed $user_id
* @ param mixed $plaintext_pass
* @ return void
*/
2011-12-10 17:28:32 +00:00
function customer_new_account ( $user_id , $plaintext_pass ) {
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
if ( ! $user_id || ! $plaintext_pass ) return ;
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
$user = new WP_User ( $user_id );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
$user_login = stripslashes ( $user -> user_login );
$user_email = stripslashes ( $user -> user_email );
$user_pass = $plaintext_pass ;
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
$blogname = wp_specialchars_decode ( get_option ( 'blogname' ), ENT_QUOTES );
2012-08-14 19:42:38 +00:00
2012-01-05 11:31:22 +00:00
$subject = apply_filters ( 'woocommerce_email_subject_customer_new_account' , sprintf ( __ ( 'Your account on %s' , 'woocommerce' ), $blogname ), $user );
2012-03-30 20:02:36 +00:00
$email_heading = sprintf ( __ ( 'Welcome to %s' , 'woocommerce' ), $blogname );
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Buffer
ob_start ();
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get mail template
2012-02-03 16:17:35 +00:00
woocommerce_get_template ( 'emails/customer-new-account.php' , array (
'user_login' => $user_login ,
'user_pass' => $user_pass ,
'blogname' => $blogname ,
'email_heading' => $email_heading
));
2012-08-14 19:42:38 +00:00
2011-12-10 17:28:32 +00:00
// Get contents
$message = ob_get_clean ();
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// CC, BCC, additional headers
2012-06-27 01:09:39 +00:00
$headers = apply_filters ( 'woocommerce_email_headers' , '' , 'customer_new_account' , $user );
2012-08-14 19:42:38 +00:00
2012-03-03 11:34:49 +00:00
// Attachments
2012-06-27 01:09:39 +00:00
$attachments = apply_filters ( 'woocommerce_email_attachments' , '' , 'customer_new_account' , $user );
2012-08-14 19:42:38 +00:00
// Send the mail
2012-03-03 11:34:49 +00:00
$this -> send ( $user_email , $subject , $message , $headers , $attachments );
2011-12-10 17:28:32 +00:00
}
2012-01-27 16:38:39 +00:00
}
2012-08-14 19:42:38 +00:00
/**
* woocommerce_email class .
*
2012-08-15 17:08:42 +00:00
* @ extends WC_Email
* @ deprecated 1.4
* @ package WooCommerce / Classes
2012-08-14 19:42:38 +00:00
*/
2012-01-27 16:38:39 +00:00
class woocommerce_email extends WC_Email {
2012-08-14 19:42:38 +00:00
public function __construct () {
2012-01-27 16:38:39 +00:00
_deprecated_function ( 'woocommerce_email' , '1.4' , 'WC_Email()' );
2012-08-14 19:42:38 +00:00
parent :: __construct ();
}
}