Email problems after update WooCommerce 4.x.x

Len, April 3, 2020

After a recent update of WooCommerce 4, it may happen that your sent emails have strange errors. The formatting is incorrect, there are spaces in between words, or blocks of HTML code are displayed. Until now, this has occurred on all WooCommerce 4 versions, specifically 4.0.0 and 4.0.1.

Cause

Officially WooCommerce has not yet established a cause for this. Several people in the community have indicated that the general mail function used by WordPress can no longer handle certain formats that worked in previous versions.

Solution

WooCommerce itself has not yet officially offered a solution to this problem. However, at the moment there are two Workarounds you can apply to solve it for now:

Adding a block of code to functions.php

Your WordPress theme contains a file called functions.php. In this file you need to add the following code at the end:

/*
* Remove the default WooCommerce 3 JSON/LD structured data format
*/
function remove_output_structured_data() {
remove_action( ‘wp_footer’, array( WC()->structured_data, ‘output_structured_data’ ), 10 ); // Frontend pages
remove_action( ‘woocommerce_email_order_details’, array( WC()->structured_data, ‘output_email_structured_data’ ), 30 ); // Emails
}
add_action(‘init’, ‘remove_output_structured_data’ );

Empty the cache in WordPress, and the cache via admin.savvii.com to be sure. After this, the code should work immediately. Keep in mind that the code can be removed when performing a theme update. If you are using a child theme, it is better to apply the change. This way, the change will also remain active during a theme update.

Using an SMTP plugin

Because the error is partly caused by the PHPMailer function, you can bypass it by using an SMTP plugin to handle your emails. Because every website is different, we cannot recommend a plugin that is one hundred percent suitable for your website.

To use an SMTP plugin you will also need login details for a mail account. This email address can be created at your current mail hosting provider. You can also use SMTP services, which will take care of sending the email for you. Some of these providers will be discussed in our support article.

Leave a reply