61
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!
PHP Snippet: Add Content to the WooCommerce Customer Processing Order Email
/**
* @snippet Add Text to Customer Processing Order Email
* @how-to Get tutoraspire.com FREE
* @author Tutor Aspire
* @testedwith Woo 4.6
* @donate $9 https://tutoraspire.com
*/
add_action( 'woocommerce_email_before_order_table', 'tutoraspire_add_content_specific_email', 20, 4 );
function tutoraspire_add_content_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
if ( $email->id == 'customer_processing_order' ) {
echo 'Get 20% off
Thank you for making this purchase! Come back and use the code "Back4More" to receive a 20% discount on your next purchase! Click here to continue shopping.
';
}
}
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' ) {}