Customer Emails
“Out of the box” WooCommerce includes 7 email types, 4 of which are sent to the customer and related to their order, these are the ones we’ll be concerning ourselves with (though any techniques can certainly apply to the other types):- Processing order – sent to the customer after payment and contains the order details.
- Completed order – sent to the customer when the order is marked complete, and usually indicates that the order has been shipped.
- Customer invoice – sent to the customer for an order which requires payment
- Customer note – sent to the customer when a customer note is added from the edit order admin
WooCommerce Global Email Options
The standard WooCommerce email looks like the following: The WooCommerce admin allows some basic customization of this default email layout, with options found by logging into your WordPress Admin and going to WooCommerce > Emails > Email Options. Some of options include:- Set the “From” name/address that the customer sees
- Add a header image
- Change the email footer text
- Choose different base, background, and body text colors
WooCommerce Email Specific Options
Each email type offers its own set of customization options. These can be found by going toWooCommerce > Settings > Emails > Processing order (for the processing order type, of course). Here you can further tweak the content for this particular email type, changing for instance:- Whether the email is even sent at all (enabled/disabled)
- The email subject
- Email heading (defaults to “Thank you for your order”)
- Whether the email is sent as HTML or plain text (defaults to HTML)
Overriding Email Templates
A more powerful (and advanced) way to customize order emails is to override an email template file. WooCommerce uses a convenient templating system that allows you to customize parts of your site (or emails) by copying the relevant template file into your theme, and modifying the code there. Each of the email types has a template file for its content (iewoocommerce/templates/emails/customer-process-order.php
) along with a number of shared templates that are used for all emails types (iewoocommerce/templates/emails/email-footer.php
). It is this latter which we will override to fix that hard-to-read footer text from before.
- First you make sure that the following directories exist in your wordpress install:
wp-content/themes/your-theme/woocommerce/emails/
- Next, copy the file found at
wp-content/plugins/woocommerce/templates/emails/email-footer.php
into your theme at:your-theme/woocommerce/emails/
. - Finally edit
your-theme/woocommerce/emails/email-footer.php
to change the footer text to black (only the relevant part of the template file code is shown, for brevity):
1
2
3
4
5
6
7
8
9
10 |
... $credit = " border:0; color: black; font-family: Arial; font-size:12px; line-height:125%; text-align:center; "; ... |
Conditional Customization with Actions/Filters
The final, and most powerful/advanced way to customize an email is to make use of the actions/filters provided by WooCommerce with some custom code. While this does require some comfort with simple PHP and the WordPress Plugin API, the benefit is that it’s more upgrade-friendly, as the original WooCommerce templates are still used: we’re just injecting/modifying some of the content. Makes sense? Great! For this example we’ll add some helpful payment instructions to the email, based on the checkout payment type used. To try this out, add the following to your theme’s functions.php:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
add_action( 'woocommerce_email_before_order_table' , 'add_order_email_instructions' , 10, 2 ); function add_order_email_instructions( $order , $sent_to_admin ) { if ( ! $sent_to_admin ) { if ( 'cod' == $order ->payment_method ) { // cash on delivery method echo '<p><strong>Instructions:</strong> Full payment is due immediately upon delivery: <em>cash only, no exceptions</em>.</p>' ; } else { // other methods (ie credit card) echo '<p><strong>Instructions:</strong> Please look for "Madrigal Electromotive GmbH" on your next credit card statement.</p>' ; } } } |
Plugin/Payment Gateway Options
There are a few plugins/payment gateways that actually allow you to customize portions of the order emails. For instance, the built-in bank/wire transfer payment method allows you to configure instructions (containing your wire transfer into, etc) right from the WooCommerce > Settings > Checkout > BACS admin. Although fairly uncommon, it’s good to be aware that these types of options can exist, when you’re choosing/configuring plugins for your site.In Closing
In this article we covered five techniques available for customizing WooCommerce order emails, ranging from trivial admin configuration, to advanced action/filter usage. We took the clean but undistinguished default order processing email, and styled it to match our imaginary shop. If you found this material useful and put any of the methods described above into practice, or have one of your own, please let us know with a comment below!Article Resources
Want to see more “How to” articles? We’ve got a whole category of them!- How to Code HTML Emails
- How to Add a Custom WooCommerce Email
- Overriding WooCommerce template files
- WordPress Action/Filter Reference
Revisions
- September 2, 2015 @ 14:16:44 [Current Revision] by PeterLugg
- September 2, 2015 @ 14:16:00 by PeterLugg
- September 2, 2015 @ 14:15:11 [Autosave] by PeterLugg
- September 2, 2015 @ 14:09:57 by PeterLugg
Revision Differences
There are no differences between the September 2, 2015 @ 14:15:11 [Autosave] revision and the current revision. (Maybe only post meta information was changed.)
No comments yet.