2011-08-10 17:11:11 +00:00
< ? php
/**
* WooCommerce Emails
*
* Email handling for important shop events .
*
* @ package WooCommerce
* @ category Emails
* @ author WooThemes
*/
2011-08-16 14:06:08 +00:00
2011-08-10 17:11:11 +00:00
/**
* Mail from name / email
**/
function woocommerce_mail_from_name ( $name ) {
2011-10-01 22:48:26 +00:00
return esc_attr ( get_bloginfo ( 'name' ));
2011-08-10 17:11:11 +00:00
}
function woocommerce_mail_from ( $email ) {
2011-10-01 22:48:26 +00:00
return get_option ( 'admin_email' );
2011-08-10 17:11:11 +00:00
}
2011-09-26 11:21:27 +00:00
/**
* HTML emails from WooCommerce
**/
function woocommerce_mail ( $to , $subject , $message ) {
2011-10-01 22:48:26 +00:00
add_filter ( 'wp_mail_from' , 'woocommerce_mail_from' );
add_filter ( 'wp_mail_from_name' , 'woocommerce_mail_from_name' );
add_filter ( 'wp_mail_content_type' , 'woocommerce_email_content_type' );
2011-09-26 11:21:27 +00:00
2011-09-23 11:15:36 +00:00
// Send the mail
wp_mail ( $to , $subject , $message );
// Unhook
2011-10-01 22:48:26 +00:00
remove_filter ( 'wp_mail_from' , 'woocommerce_mail_from' );
remove_filter ( 'wp_mail_from_name' , 'woocommerce_mail_from_name' );
remove_filter ( 'wp_mail_content_type' , 'woocommerce_email_content_type' );
2011-09-23 11:15:36 +00:00
}
2011-08-16 14:06:08 +00:00
/**
* Email Header
**/
add_action ( 'woocommerce_email_header' , 'woocommerce_email_header' );
function woocommerce_email_header () {
woocommerce_get_template ( 'emails/email_header.php' , false );
}
/**
* Email Footer
**/
add_action ( 'woocommerce_email_footer' , 'woocommerce_email_footer' );
function woocommerce_email_footer () {
woocommerce_get_template ( 'emails/email_footer.php' , false );
}
/**
* HTML email type
**/
function woocommerce_email_content_type ( $content_type ){
return 'text/html' ;
}
/**
* Fix recieve password mail links
**/
function woocommerce_retrieve_password_message ( $content ){
return htmlspecialchars ( $content );
}
2011-08-10 17:11:11 +00:00
/**
* Hooks for emails
**/
add_action ( 'woocommerce_low_stock_notification' , 'woocommerce_low_stock_notification' );
add_action ( 'woocommerce_no_stock_notification' , 'woocommerce_no_stock_notification' );
add_action ( 'woocommerce_product_on_backorder_notification' , 'woocommerce_product_on_backorder_notification' , 1 , 2 );
/**
* New order notification email template
**/
2011-09-21 15:43:37 +00:00
add_action ( 'woocommerce_order_status_pending_to_processing' , 'woocommerce_new_order_notification' );
add_action ( 'woocommerce_order_status_pending_to_completed' , 'woocommerce_new_order_notification' );
add_action ( 'woocommerce_order_status_pending_to_on-hold' , 'woocommerce_new_order_notification' );
2011-09-22 19:50:58 +00:00
add_action ( 'woocommerce_order_status_failed_to_processing' , 'woocommerce_new_order_notification' );
add_action ( 'woocommerce_order_status_failed_to_completed' , 'woocommerce_new_order_notification' );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
function woocommerce_new_order_notification ( $id ) {
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
global $order_id , $email_heading ;
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$order_id = $id ;
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$email_heading = __ ( 'New Customer Order' , 'woothemes' );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$subject = sprintf ( __ ( '[%s] New Customer Order (# %s)' , 'woothemes' ), get_bloginfo ( 'name' ), $order_id );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Buffer
ob_start ();
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Get mail template
woocommerce_get_template ( 'emails/new_order.php' , false );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Get contents
$message = ob_get_clean ();
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Send the mail
2011-09-23 11:15:36 +00:00
woocommerce_mail ( get_option ( 'admin_email' ), $subject , $message );
2011-08-10 17:11:11 +00:00
}
/**
* Processing order notification email template
**/
2011-09-21 15:43:37 +00:00
add_action ( 'woocommerce_order_status_pending_to_processing' , 'woocommerce_processing_order_customer_notification' );
add_action ( 'woocommerce_order_status_pending_to_on-hold' , 'woocommerce_processing_order_customer_notification' );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
function woocommerce_processing_order_customer_notification ( $id ) {
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
global $order_id , $email_heading ;
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$order_id = $id ;
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$order = & new woocommerce_order ( $order_id );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$email_heading = __ ( 'Order Received' , 'woothemes' );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$subject = '[' . get_bloginfo ( 'name' ) . '] ' . __ ( 'Order Received' , 'woothemes' );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Buffer
ob_start ();
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Get mail template
woocommerce_get_template ( 'emails/customer_processing_order.php' , false );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Get contents
$message = ob_get_clean ();
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Send the mail
2011-09-23 11:15:36 +00:00
woocommerce_mail ( $order -> billing_email , $subject , $message );
2011-08-10 17:11:11 +00:00
}
/**
* Completed order notification email template - this one includes download links for downloadable products
**/
2011-09-21 15:43:37 +00:00
add_action ( 'woocommerce_order_status_completed' , 'woocommerce_completed_order_customer_notification' );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
function woocommerce_completed_order_customer_notification ( $id ) {
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
global $order_id , $email_heading ;
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$order_id = $id ;
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$order = & new woocommerce_order ( $order_id );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$email_heading = __ ( 'Order Complete' , 'woothemes' );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$subject = '[' . get_bloginfo ( 'name' ) . '] ' . __ ( 'Order Complete' , 'woothemes' );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Buffer
ob_start ();
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Get mail template
woocommerce_get_template ( 'emails/customer_completed_order.php' , false );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Get contents
$message = ob_get_clean ();
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Send the mail
2011-09-23 11:15:36 +00:00
woocommerce_mail ( $order -> billing_email , $subject , $message );
2011-08-10 17:11:11 +00:00
}
/**
* Pay for order notification email template - this one includes a payment link
**/
2011-08-16 14:06:08 +00:00
function woocommerce_pay_for_order_customer_notification ( $id ) {
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
global $order_id , $email_heading ;
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$order_id = $id ;
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$order = & new woocommerce_order ( $order_id );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$email_heading = __ ( 'Pay for Order' , 'woothemes' );
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
$subject = '[' . get_bloginfo ( 'name' ) . '] ' . __ ( 'Pay for Order' , 'woothemes' );
// Buffer
ob_start ();
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Get mail template
woocommerce_get_template ( 'emails/customer_pay_for_order.php' , false );
// Get contents
$message = ob_get_clean ();
2011-08-10 17:11:11 +00:00
2011-08-16 14:06:08 +00:00
// Send the mail
2011-09-23 11:15:36 +00:00
woocommerce_mail ( $order -> billing_email , $subject , $message );
2011-08-10 17:11:11 +00:00
}
/**
* Low stock notification email
**/
function woocommerce_low_stock_notification ( $product ) {
$_product = & new woocommerce_product ( $product );
$subject = '[' . get_bloginfo ( 'name' ) . '] ' . __ ( 'Product low in stock' , 'woothemes' );
$message = '#' . $_product -> id . ' ' . $_product -> get_title () . ' (' . $_product -> sku . ') ' . __ ( 'is low in stock.' , 'woothemes' );
$message = wordwrap ( html_entity_decode ( strip_tags ( $message ) ), 70 );
wp_mail ( get_option ( 'admin_email' ), $subject , $message );
}
/**
* No stock notification email
**/
function woocommerce_no_stock_notification ( $product ) {
$_product = & new woocommerce_product ( $product );
$subject = '[' . get_bloginfo ( 'name' ) . '] ' . __ ( 'Product out of stock' , 'woothemes' );
$message = '#' . $_product -> id . ' ' . $_product -> get_title () . ' (' . $_product -> sku . ') ' . __ ( 'is out of stock.' , 'woothemes' );
$message = wordwrap ( html_entity_decode ( strip_tags ( $message ) ), 70 );
wp_mail ( get_option ( 'admin_email' ), $subject , $message );
}
/**
* Backorder notification email
**/
function woocommerce_product_on_backorder_notification ( $product , $amount ) {
$_product = & new woocommerce_product ( $product );
$subject = '[' . get_bloginfo ( 'name' ) . '] ' . __ ( 'Product Backorder' , 'woothemes' );
$message = $amount . __ ( ' units of #' , 'woothemes' ) . $_product -> id . ' ' . $_product -> get_title () . ' (' . $_product -> sku . ') ' . __ ( 'have been backordered.' , 'woothemes' );
$message = wordwrap ( html_entity_decode ( strip_tags ( $message ) ), 70 );
wp_mail ( get_option ( 'admin_email' ), $subject , $message );
}