WooCommerce has the option to send emails in three different formats for each type of notification:
| Name | Content-type | Description |
|---|---|---|
| Plain text | text/plain | Plain text without formatting or images. WooCommerce automatically wraps the email content at 70 characters. The documentation mentions a 155 character length limitation on text fields, but I haven’t found anywhere that limitation applies. |
| HTML | text/html | More control over formatting, the ability to include images, order tables, etc. |
| Multipart | multipart/alternative | Multipart MIME includes both the plain text and HTML versions so that the recipient’s email client can choose the best format for them. In this format, WooCommerce wraps the plain-text emails at 75 characters rather than 70. |
You can change this setting from the WordPress admin area by opening WooCommerce, Settings, Emails and clicking the Manage button. There will be an “Email type” dropdown at the bottom.
The default is HTML, but setting it to Multipart might make spam filters slightly friendlier to your emails. However, if you enable multipart and also customize your emails with template files or hooks, read on for additional considerations.
Gotchas when customizing templates/hooks with Multipart enabled
- Template files: every time you make a change to an HTML template file (e.g.
customer-completed-order.php), make the same changes to the corresponding file one level down in theplaindirectory (e.g.plain/customer-completed-order.php). - Hooks: email-related hooks will usually provide a
$plain_textparameter that’strueif you need to write plain-text output. Actions likewoocommerce_email_headerandwoocommerce_email_footerdon’t include it because they aren’t used in the plain-text emails.
A fix for the email type dropdown only allowing plain text
If the email settings for an email in WooCommerce only has “plain text” as an option, I’ll bet you good money it’s because your PHP installation doesn’t have XML available (WC_Email::get_email_type_options() tests if DOMDocument is available before allowing the HTML and multipart options). To fix this, you or your host should check two things:
- Make sure
extension=dom.sois in your php.ini in the extensions section. - Make sure PHP wasn’t compiled with
--disable-domand recompile it without that flag if so. Or if you’re on a platform without the extension available by default, you can try asudo apt-get install php-xmlorsudo yum install php-xmldepending on your package manager.
You made it to the end!
As a reward, here are 3 randomly-generated emojis that will surely tell a compelling story:
Pingback: MyBlog