Menu Close

WooCommerce: Add Content to a Specific Order Email

default

Customizing WooCommerce emails via the WordPress dashboard is not easy and – sometimes – not possible. For example, you can’t edit or add content to them unless you’re familiar with code.

Well, here’s a quick example to learn how to add content to any WooCommerce default order email. In this case study, our goal is showing an upsell to get buyers to go back to the website and buy with a coupon code. Enjoy!

WooCommerce - how to add content to the order email
WooCommerce – how to add content to the order email

PHP Snippet: Add Content to the WooCommerce Customer Processing Order Email

/**
 * @snippet       Add Text to Customer Processing Order Email
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @testedwith    Woo 4.6
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_action( 'woocommerce_email_before_order_table', 'bbloomer_add_content_specific_email', 20, 4 );
 
function bbloomer_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 WooCommerce Order Emails

Using the same snippet above, you can target different emails by changing the email ID

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' ) {}
View Source
Posted in WooCommerce Tips