WooCommerce 2.3 is still a ways out, but one of the things we’ve been working on is a better email class system in core. Primarily, we’ve refactored how emails are sent through WooCommerce. Any extension can send a WC branded email by loading the mailer and calling the send method. Like so:
// set subject $subject = 'WC Send Mail Test'; // load the mailer $mailer = WC()->mailer(); $mailer->send( get_option( 'admin_email' ), $subject, $mailer->wrap_message( $subject, 'a test message' ), '', '' );
The wrap_message() function wraps the email in the WooCommerce branding. If you want to send an email without any WooCommerce branding you can do so by not using the wrap_message() function.
A CSS Inliner for Prettier Email
If you’ve ever spent time customizing an email template you know how awful it is to work with different email clients and how none of them support regular CSS. This is a pain for developers and really confusing for end users. After refactoring the send methods we were able to add a CSS inliner. This will take regular CSS and rewrite it so that each element has the styles written inline. This prevents a lot of problems with email clients.
A New Way to Customize Email CSS
We used to have all of the CSS in the email-header.php template which was convenient programmatically but a bit confusing for users. We took all of this CSS and put it into it’s own template. An end user can now override the email-styles.php template.
A New Way to Customize Email CSS for Developers
Overriding templates is great for end users but it’s not great for developers. If you want to write a plugin that changes the email styles you can use the new
woocommerce_email_styles filter. I’ve made an example plugin that shows how to use this filter.
If you want to test this new functionality yourself it’s merged into the master branch of WooCommerce on GitHub.