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-25 12:54:16 +00:00
return get_option ( 'woocommerce_email_from_name' );
2011-08-10 17:11:11 +00:00
}
function woocommerce_mail_from ( $email ) {
2011-10-25 12:54:16 +00:00
return get_option ( 'woocommerce_email_from_address' );
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-10-25 12:54:16 +00:00
2011-08-16 14:06:08 +00:00
// Send the mail
2011-11-01 17:11:57 +00:00
woocommerce_mail ( get_option ( 'woocommerce_new_order_email_recipient' ), $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-10-24 06:40:20 +00:00
$subject = sprintf ( __ ( '[%s] Order Received' , 'woothemes' ), get_bloginfo ( 'name' ));
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-10-12 17:32:30 +00:00
if ( $order -> has_downloadable_item ()) :
2011-10-28 13:43:54 +00:00
$subject = __ ( '[%s] Order Complete/Download Links' , 'woothemes' );
$email_heading = __ ( 'Order Complete/Download Links' , 'woothemes' );
2011-10-12 17:32:30 +00:00
else :
2011-10-28 13:43:54 +00:00
$subject = __ ( '[%s] Order Complete' , 'woothemes' );
$email_heading = __ ( 'Order Complete' , 'woothemes' );
2011-10-12 17:32:30 +00:00
endif ;
$email_heading = apply_filters ( 'woocommerce_completed_order_customer_notification_subject' , $email_heading );
2011-08-10 17:11:11 +00:00
2011-10-28 13:43:54 +00:00
$subject = sprintf ( $subject , get_bloginfo ( 'name' ));
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-11-11 14:30:32 +00:00
function woocommerce_pay_for_order_customer_notification ( $order ) {
2011-08-10 17:11:11 +00:00
2011-11-13 12:35:30 +00:00
global $order_id , $the_order , $email_heading ;
2011-08-10 17:11:11 +00:00
2011-11-11 14:30:32 +00:00
$order_id = $order -> id ;
2011-11-13 12:35:30 +00:00
$the_order = $order ;
2011-08-10 17:11:11 +00:00
2011-11-11 14:30:32 +00:00
$email_heading = sprintf ( __ ( 'Invoice for Order #%s' , 'woothemes' ), $order_id );
2011-08-10 17:11:11 +00:00
2011-10-24 06:40:20 +00:00
$subject = sprintf ( __ ( '[%s] Pay for Order' , 'woothemes' ), get_bloginfo ( 'name' ));
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_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 );
2011-11-01 17:11:57 +00:00
wp_mail ( get_option ( 'woocommerce_stock_email_recipient' ), $subject , $message );
2011-08-10 17:11:11 +00:00
}
/**
* 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 );
2011-11-01 17:11:57 +00:00
wp_mail ( get_option ( 'woocommerce_stock_email_recipient' ), $subject , $message );
2011-08-10 17:11:11 +00:00
}
/**
* 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 );
2011-11-01 17:11:57 +00:00
wp_mail ( get_option ( 'woocommerce_stock_email_recipient' ), $subject , $message );
2011-10-30 00:00:32 +00:00
}
/**
* Preview Emails
**/
add_action ( 'admin_init' , 'woocommerce_preview_emails' );
function woocommerce_preview_emails () {
if ( isset ( $_GET [ 'preview_woocommerce_mail' ])) :
$nonce = $_REQUEST [ '_wpnonce' ];
if ( ! wp_verify_nonce ( $nonce , 'preview-mail' ) ) die ( 'Security check' );
global $email_heading ;
$email_heading = __ ( 'Email preview' , 'woothemes' );
do_action ( 'woocommerce_email_header' );
echo '<h2>WooCommerce sit amet</h2>' ;
echo wpautop ( ' Ut ut est qui euismod parum . Dolor veniam tation nihil assum mazim . Possim fiant habent decima et claritatem . Erat me usus gothica laoreet consequat . Clari facer litterarum aliquam insitam dolor .
Gothica minim lectores demonstraverunt ut soluta . Sequitur quam exerci veniam aliquip litterarum . Lius videntur nisl facilisis claritatem nunc . Praesent in iusto me tincidunt iusto . Dolore lectores sed putamus exerci est . ' );
do_action ( 'woocommerce_email_footer' );
exit ;
endif ;
2011-11-01 14:12:18 +00:00
}
/**
* Add order meta to email templates
**/
add_action ( 'woocommerce_email_after_order_table' , 'woocommerce_email_order_meta' , 10 , 2 );
function woocommerce_email_order_meta ( $order , $sent_to_admin ) {
$meta = array ();
$show_fields = apply_filters ( 'woocommerce_email_order_meta_keys' , array ( 'coupons' ), $sent_to_admin );
if ( $order -> customer_note ) :
$meta [ __ ( 'Note:' , 'woothemes' )] = wptexturize ( $order -> customer_note );
endif ;
if ( $show_fields ) foreach ( $show_fields as $field ) :
$value = get_post_meta ( $order -> id , $field , true );
if ( $value ) $meta [ ucwords ( esc_attr ( $field ))] = wptexturize ( $value );
endforeach ;
if ( sizeof ( $meta ) > 0 ) :
echo '<h2>' . __ ( 'Order information' , 'woothemes' ) . '</h2>' ;
foreach ( $meta as $key => $value ) :
echo '<p><strong>' . $key . ':</strong> ' . $value . '</p>' ;
endforeach ;
endif ;
}
2011-11-08 13:47:49 +00:00
/**
* Customer new account welcome email
**/
function woocommerce_customer_new_account ( $user_id , $plaintext_pass ) {
global $email_heading , $user_login , $user_pass , $blogname ;
if ( empty ( $plaintext_pass ) ) return ;
$user = new WP_User ( $user_id );
$user_login = stripslashes ( $user -> user_login );
$user_email = stripslashes ( $user -> user_email );
$user_pass = $plaintext_pass ;
$blogname = wp_specialchars_decode ( get_option ( 'blogname' ), ENT_QUOTES );
$subject = sprintf ( __ ( 'Your account on %s' , 'woothemes' ), $blogname );
$email_heading = __ ( 'Your account details' , 'woothemes' );
// Buffer
ob_start ();
// Get mail template
woocommerce_get_template ( 'emails/customer_new_account.php' , false );
// Get contents
$message = ob_get_clean ();
// Send the mail
woocommerce_mail ( $user_email , $subject , $message );
}