How to Add Content to Order Email in WooCommerce?

Sometimes, you need to customize WooCommerce emails. Such customization brings more personalization to your emails. However, adding new content to your order emails using WordPress is not easy. At times, it is nearly impossible. You must know coding to edit or add content to order email. In this article, you will exactly learn how to do it.

So, here is an example showing customized email. Below we are upselling a product through content written in the email. Our goal is to send buyers back to the website & buy using our coupon codes. 

Here is an example of how it will look:

Image showing how to add content to order email

PHP Snippet: Add Content to Order Email in WooCommerce

add_action( 'woocommerce_email_before_order_table', 'phpsof_add_content_specific_email', 20, 4 );
function phpsof_add_content_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
   if ( $email->id == 'customer_processing_order' ) {
      echo '<h2 class="email-upsell-title">Get 20% off</h2><p class="email-upsell-p">Thank you for making this purchase! Come back and use the code "<strong>Back4More</strong>" to receive a 20% discount on your next purchase! Click here to continue shopping.</p>';

How to target other customer processing WooCommerce order emails?

To modify other emails, you can use the above snippet by changing email IDs. 

if ( $email->id == 'cancelled_order' ) {}
if ( $email->id == 'customer_completed_order' ) {}
if ( $email->id == 'customer_invoice' ) {}
if ( $email->id == 'customer_new_account' ) {}
if ( $email->id == 'customer_note' ) {}
if ( $email->id == 'customer_on_hold_order' ) {}
if ( $email->id == 'customer_refunded_order' ) {}
if ( $email->id == 'customer_reset_password' ) {}
if ( $email->id == 'failed_order' ) {}
if ( $email->id == 'new_order' ) {}

Where do you add this snippet – Add Content to Order Email?

So, this is how you activate this snippet in WooCommerce. It is a great way to encourage sales after one successful order sale. Also, it is easier to activate this function with this code. So, to apply this code, just add this PHP snippet at your child theme function.php file’s bottom. It should be placed before “?>”, if you have it there. Apart from this, CSS goes in your child theme style.css file. 

Is this snippet still valid?

So, this is how you add content to order email. You can upsell any products by adding a simple content to your specific order email through this code. So, I have applied this code on the Storefront theme and WordPress friendly hosting PHP 7.3. Let me know if everything works as expected. Share it further if you find this snippet useful for you and it had saved your time.

Also Read, How to Set Custom WooCommerce Order Status for New Orders?

How to Remove Checkout Billing Fields if Virtual Product @ Cart in WooCommerce 

Important links: WooCommerce –