01273 264503 info@mootpoint.org

One of the great plusses of WooCommerce is the amount of thought the developers have put into customising almost every aspect of its functions. When customising the notification emails that are sent out with a new order or completed order etc., there are several approaches to take:

  • WooCommerce Settings – simple control of appearance such as font colour and footer text can be accessed in WooCommerce > Settings > Emails > Email Options. However, these will apply to all notification emails, and do not offer fine-grained control.
  • Template Overrides – much more sophisticated customisation of each email’s appearance is possible by copying the relevant email template from woocommerce/templates/emails/ to yourtheme/woocommerce/emails/ – you can do this from the back-end in WooCommerce > Settings > Emails > <email name>. The theme email template will now be used in place of the standard template, and can be customised to your heart’s content.
  • Hooks and Filters – WooCommerce provides a wide range of hooks and filters to customise almost every aspect of the notification emails, which is useful if you want to have some programmatic control of the emails – for example, sending different new order emails to registered customers and guest checkouts. The WooCommerce documentation of these is pretty minimal so I’ve fleshed it out below:

Notification email header hooks

apply_filters( 'woocommerce_email_subject_' . $this->id, $this->format_string( $this->subject ), $this->object );
apply_filters( 'woocommerce_email_heading_' . $this->id, $this->format_string( $this->heading ), $this->object );
apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object );
apply_filters( 'woocommerce_email_headers', "Content-Type: " . $this->get_content_type() . "\r\n", $this->id, $this->object );
apply_filters( 'woocommerce_email_attachments', array(), $this->id, $this->object );

$this->id can have the following values:

  • new_order
  • customer_processing_order
  • customer_completed_order
  • customer_invoice
  • customer_note
  • low_stock
  • no_stock
  • backorder
  • customer_new_account
  • customer_invoice_paid

For example, to change the email heading of new order emails, use:

add_filter('woocommerce_email_heading_new_order', 'my_email_heading_customisation_function', 1, 2);

Notification email appearance hooks

add_filter( 'woocommerce_email_style_inline_tags', array( $this, 'style_inline_tags' ) );
add_filter( 'woocommerce_email_style_inline_h1_tag', array( $this, 'style_inline_h1_tag' ) );
add_filter( 'woocommerce_email_style_inline_h2_tag', array( $this, 'style_inline_h2_tag' ) );
add_filter( 'woocommerce_email_style_inline_h3_tag', array( $this, 'style_inline_h3_tag' ) );
add_filter( 'woocommerce_email_style_inline_a_tag', array( $this, 'style_inline_a_tag' ) );
add_filter( 'woocommerce_email_style_inline_img_tag', array( $this, 'style_inline_img_tag' ) );

Other notification email hooks

apply_filters( 'woocommerce_email_enabled_' . $this->id, $enabled, $this->object );

Examples

Customise the admin new order email subject for registered customers only:

// Change new order email subject for registered customers
function wc_change_admin_new_order_email_subject( $subject, $order ) {
	global $woocommerce;
	if ( check_user_role( 'customer' ) ) {
		$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
		$subject = sprintf( '[%s] New Customer Order (%s) from %s %s', $blogname, $order->get_order_number(), $order->billing_first_name, $order->billing_last_name );
	}
	return $subject;
}
add_filter('woocommerce_email_subject_new_order', 'wc_change_admin_new_order_email_subject', 1, 2);

Customise the admin new order email recipient to redirect to different departments for registered customers and guest checkouts:

// Change new order email recipient for registered customers
function wc_change_admin_new_order_email_recipient( $recipient, $order ) {
	global $woocommerce;
	if ( check_user_role( 'customer' ) ) {
		$recipient = "accounts@yourdomain.com";
	} else {
		$recipient = "newbusiness@yourdomain.com";
	}
	return $recipient;
}
add_filter('woocommerce_email_recipient_new_order', 'wc_change_admin_new_order_email_recipient', 1, 2);