WooCommerce PHP Beginner Requires WooCommerce

Add Custom Text to WooCommerce Emails

Add a message, such as next steps or a support link, to the emails customers get for processing and completed orders.

Tested on WordPress 7.1 PHP 8.3 Updated
functions.php 14 lines
add_action( 'woocommerce_email_before_order_table', function ( WC_Order $order, bool $sent_to_admin, bool $plain_text, $email ): void {
	// Only in emails to the customer for these order emails.
	if ( $sent_to_admin || ! in_array( $email->id, [ 'customer_processing_order', 'customer_completed_order' ], true ) ) {
		return;
	}

	$message = 'Questions about your order? Reply to this email and we\'ll help.';

	if ( $plain_text ) {
		echo esc_html( $message ) . "\n\n";
	} else {
		echo '<p>' . esc_html( $message ) . '</p>';
	}
}, 10, 4 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Order emails are the most-read messages your store sends. Adding a line about delivery times, a support contact or a care guide answers questions before customers ask.

How it works

The woocommerce_email_before_order_table action runs inside every WooCommerce email that includes an order table. It passes the order, whether the email goes to the store admin, whether it’s plain text and the email object.

The snippet checks $email->id so the message only appears in the customer’s processing and completed order emails, and prints plain text or HTML to match the email format.

Things to watch

  • Other email ids include customer_on_hold_order, customer_invoice, customer_refunded_order and new_order (to the admin).
  • You can use order details in the message, such as $order->get_billing_first_name().

How to test it

Go to WooCommerce → Settings → Emails and open the Processing order email preview, or place a test order and check the email.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only