Block emails: billing and shipping addresses missing in Apple Mail and other clients
Problem
When the block email editor is enabled, order emails can show no billing and shipping addresses in some email clients, including Apple Mail. The rest of the email renders: the order summary, customer note and footer are all there. Only the addresses table is missing. The table is in the HTML, and Chrome (for example Mailpit's preview) renders it correctly.
This happens on trunk. It is not caused by PR #69140, which changes the address styles.
New order preview email in Mailpit
New order preview email in Apple email
Cause
WC_Structured_Data::output_email_structured_data() is hooked to woocommerce_email_order_details (includes/class-wc-structured-data.php:46). It prints order JSON-LD in a hidden element, right before the addresses table:
<div style="display: none; font-size: 0; max-height: 0; line-height: 0; padding: 0; mso-hide: all;"><script type="application/ld+json">{...}</script></div>
<hr ...>
<table id="addresses" ...>- Classic emails:
WC_Email::style_inline()removes everydisplay: noneelement after inlining (HtmlPruner::removeElementsWithDisplayNone(),includes/emails/class-wc-email.php:977). The JSON-LD never reaches the client. - Block emails: the removal is skipped, so the preheader (preview text) is kept. The JSON-LD reaches the client. Some clients then hide the element after it, which is the addresses table.
We don't know exactly why these clients hide the next element. The HTML is valid: all tags are closed and nested correctly, and the table is not inside a conditional comment.
Evidence
Tested in Email on Acid, with emails sent from a local wp-env to Mailpit:
| JSON-LD | Addresses in Apple Mail and other clients | |
|---|---|---|
Block email, trunk |
yes | missing |
| Block email, PR #69140 | yes | missing |
| Block email, PR #69140, JSON-LD unhooked | no | shown |
The editor's "Send test email" preview (dummy order #12345) has the same problem in Apple Mail.
History
| Commit | Release | Change |
|---|---|---|
52939e800c |
3.1.0 | Order JSON-LD added to emails in a hidden element. |
6612d1f859 |
4.1.0 | Classic emails remove display: none elements, so the JSON-LD stops shipping. |
da5c3e1a5e (#57330) |
9.9.0 | Block emails skip that removal, to keep the preheader. The JSON-LD ships again, in block emails only. |
So block emails have had this bug since 9.9.0.
Suggested fix
Do not output the JSON-LD in block emails. For example, unhook output_email_structured_data while WooContentProcessor::get_woo_content() renders the Woo content. This matches classic emails, which have not shipped the JSON-LD since 4.1.0.
Another option is to remove hidden elements in block emails too, but keep the preheader. Emogrifier keeps elements with the -emogrifier-keep class. That changes the email-editor package, which MailPoet also uses, and it would also remove any display: none content that blocks add on purpose. So it is the riskier option.
Steps to reproduce
- Enable the block email editor in WooCommerce > Settings > Advanced > Features.
- Create an order with a billing and a shipping address, and a shipping method other than local pickup.
- Send the "New order" email, for example with Order actions > Resend new order notification.
- Open the email in Apple Mail. The billing and shipping addresses are missing.
- Disable the block email editor and repeat. The addresses are shown.
Screenshots
Screenshots follow below.
Source: woocommerce/woocommerce