WooCommerce sends different email notifications when customers place orders, complete payments, cancel orders, or receive shipping updates. Sometimes, you may want to display custom content or send an email notification only for a particular email type.
For example, you might want to:
- Display a custom message only in New Order emails.
- Send order notifications to an additional warehouse email address.
- Notify a manager when an order exceeds a specific amount.
- Send different notifications depending on the products purchased.
- Customize email content without changing every WooCommerce email template.
WooCommerce provides an email object that contains a unique email ID. You can use $email->id inside supported email hooks to identify the notification currently being generated.
In this tutorial, you will learn how to target WooCommerce email notifications by email ID and customize recipients and email content using practical PHP examples.
What Is a WooCommerce Email ID?
WooCommerce assigns an ID to each built-in email notification. These IDs help developers identify which email is being generated.
Here are some commonly used WooCommerce email IDs:
new_order– New Order notification sent to the store administrator.cancelled_order– Cancelled Order notification.failed_order– Failed Order notification.customer_processing_order– Processing Order email sent to the customer.customer_completed_order– Completed Order email sent to the customer.customer_on_hold_order– Order On-Hold email sent to the customer.customer_refunded_order– Refunded Order email sent to the customer.
Each email ID identifies a particular WooCommerce email type. Instead of checking only the order status, you can use the email ID to run code for the exact notification being generated.
How to Target a WooCommerce Email Notification by Email ID
WooCommerce provides several email-related hooks. One useful action is woocommerce_email_before_order_table, which runs before the order table in supported order emails.
This action provides four arguments:
$order– The WooCommerce order object.$sent_to_admin– Indicates whether the email is intended for the administrator.$plain_text– Indicates whether the email is being generated as plain text.$email– The WooCommerce email object containing the email ID.
Example: Display Content Only in New Order Emails
Suppose you want to display a custom message only in the New Order email sent to the administrator.
Add this code to your child theme’s functions.php file or a custom plugin:
add_action(
'woocommerce_email_before_order_table',
'gh_custom_email_content',
10,
4
);
function gh_custom_email_content(
$order,
$sent_to_admin,
$plain_text,
$email
) {
if ( ! $email || $email->id !== 'new_order' ) {
return;
}
if ( $plain_text ) {
echo "This content appears only in New Order emails.\n";
} else {
echo '<p>This content appears only in New Order emails.</p>';
}
}
How Does This Code Work?
1. Register the WooCommerce action:
add_action(
'woocommerce_email_before_order_table',
'gh_custom_email_content',
10,
4
);
This registers your callback function and tells WordPress to pass four arguments to it.
2. Receive the email object:
function gh_custom_email_content(
$order,
$sent_to_admin,
$plain_text,
$email
) {
The fourth argument contains the WooCommerce email object. You can access its ID using $email->id.
3. Check the email ID:
if ( ! $email || $email->id !== 'new_order' ) {
return;
}
This condition stops the function when the current notification is not the New Order email.
As a result, the custom message appears only in the targeted notification.
Default WooCommerce Email Settings
Before customizing email notifications with PHP, it is useful to understand the default WooCommerce email settings.
Go to:
WordPress Dashboard → WooCommerce → Settings → Emails
From this section, you can manage supported email notifications and configure settings such as:
- Enable or disable individual email notifications.
- Change email subjects and heading text.
- Customize email content where supported.
- Set recipient addresses for administrator notifications.
- Manage sender details and email appearance.
These settings are useful for basic customization. If you need conditional behavior, such as sending an email to a warehouse only for physical orders, you can use WooCommerce email hooks.
How to Add Multiple Email Recipients in WooCommerce
You can send certain administrator email notifications to multiple email addresses without writing custom PHP.
For example, a New Order email can be sent to the store administrator, warehouse team, and store manager.
Enter multiple email addresses separated by commas in the recipient field:
admin@example. com, manager@example. com, warehouse@example. com
This approach is useful for administrator notifications such as:
- New Order emails.
- Cancelled Order emails.
- Failed Order emails.
The available recipient settings depend on the individual email notification. Always check the settings for the email type you want to configure.
Advanced WooCommerce Email Customization Using PHP
If you need more control over email recipients, WooCommerce provides recipient filters that allow you to modify the destination email addresses dynamically.
Example 1: Add an Additional Recipient to New Order Emails
Suppose you want to send every New Order notification to the existing administrator recipient and an additional warehouse address.
Use this code:
add_filter(
'woocommerce_email_recipient_new_order',
'gh_add_new_order_recipient',
10,
2
);
function gh_add_new_order_recipient( $recipient, $order ) {
$additional_email = 'warehouse@example.com';
if ( ! empty( $recipient ) ) {
$recipient .= ', ';
}
$recipient .= $additional_email;
return $recipient;
}
This filter modifies the recipient list for the New Order email. The existing recipient is preserved, and the warehouse address is added.
Replace warehouse@example.com with your actual email address.
Example 2: Notify the Warehouse Only for Physical Orders
An online store may sell both physical and virtual products. In this situation, the warehouse team does not need notifications for every order.
You can use the order object’s needs_shipping_address() method to check whether the order requires shipping.
add_filter(
'woocommerce_email_recipient_new_order',
'gh_warehouse_email_for_physical_orders',
10,
2
);
function gh_warehouse_email_for_physical_orders(
$recipient,
$order
) {
if ( ! $order instanceof WC_Order ) {
return $recipient;
}
if ( $order->needs_shipping_address() ) {
$warehouse_email = 'warehouse@example.com';
if ( ! empty( $recipient ) ) {
$recipient .= ', ';
}
$recipient .= $warehouse_email;
}
return $recipient;
}
Now the warehouse email address is added only when the order requires a shipping address.
This is useful for stores that sell a combination of physical products and downloadable or virtual products.
Example 3: Notify the Manager for High-Value Orders
You may want to notify a manager whenever a customer places an order above a particular amount.
For example, if the order total exceeds 10,000, an additional notification can be sent to the manager.
add_filter(
'woocommerce_email_recipient_new_order',
'gh_manager_email_for_high_value_orders',
10,
2
);
function gh_manager_email_for_high_value_orders(
$recipient,
$order
) {
if ( ! $order instanceof WC_Order ) {
return $recipient;
}
if ( $order->get_total() > 10000 ) {
$manager_email = 'manager@example.com';
if ( ! empty( $recipient ) ) {
$recipient .= ', ';
}
$recipient .= $manager_email;
}
return $recipient;
}
Change the amount and manager email address according to your requirements.
Important: The example uses the order total in the store’s configured currency. If your store supports multiple currencies, make sure the threshold matches the currency conversion behavior used by your store.
Example 4: Send Notifications Based on Product Category
Some WooCommerce stores have different teams responsible for different product categories.
For example:
- Electronics orders should notify the technical team.
- Clothing orders should notify the inventory team.
- Furniture orders should notify the furniture department.
You can check the product categories associated with the items in an order and add the appropriate recipient.
Here is an example for Electronics and Clothing categories:
add_filter(
'woocommerce_email_recipient_new_order',
'gh_category_based_email_recipients',
10,
2
);
function gh_category_based_email_recipients(
$recipient,
$order
) {
if ( ! $order instanceof WC_Order ) {
return $recipient;
}
$additional_recipients = array();
foreach ( $order->get_items() as $item ) {
$product_id = $item->get_product_id();
if ( ! $product_id ) {
continue;
}
if ( has_term( 'electronics', 'product_cat', $product_id ) ) {
$additional_recipients[] = 'tech@example.com';
}
if ( has_term( 'clothing', 'product_cat', $product_id ) ) {
$additional_recipients[] = 'inventory@example.com';
}
}
$additional_recipients = array_unique(
$additional_recipients
);
if ( ! empty( $additional_recipients ) ) {
$new_recipients = implode(
', ',
$additional_recipients
);
if ( ! empty( $recipient ) ) {
$recipient .= ', ';
}
$recipient .= $new_recipients;
}
return $recipient;
}
Replace the category slugs and email addresses with the values used on your website.
This example checks product categories for each order item and adds the matching department email addresses. If an order contains products from multiple categories, the corresponding teams can receive the notification.
For variable products, the example checks the parent product ID returned by the order item. If your store uses custom product relationships or category rules, adjust the logic accordingly.
How to Customize WooCommerce Email Content
Changing email recipients is only one part of WooCommerce email customization. You can also customize the content and appearance of order emails.
For example, you may want to display product images, additional order information, delivery instructions, or a custom message.
WooCommerce provides hooks that allow you to add content without editing the original email templates.
For example, you can learn how to display product images in WooCommerce order emails using PHP.
Customize the Email Appearance
Go to:
WooCommerce → Settings → Emails
Depending on your WooCommerce version and email configuration, you can manage settings such as:
- Header image or logo.
- Footer text.
- Base email colors.
- Background colors.
- Text colors.
Advanced Method: Override WooCommerce Email Templates
If you need to change the HTML structure or layout of an email, WooCommerce supports template overrides.
The original email templates are located inside:
wp- content/ plugins/ woocommerce/ templates/ emails/
To customize a template, copy the required file into the corresponding WooCommerce folder in your child theme:
wp- content/ themes/ your- child- theme/ woocommerce/ emails/
For example, you can override an email template such as customer-processing-order.php.
You can then customize the supported template markup and content without directly editing WooCommerce plugin files.
Important: Template overrides may need updates when WooCommerce changes its original templates. Check the template version information and test your customized emails after WooCommerce updates.
Best Practices for WooCommerce Email Customization
- Use a child theme or custom plugin: Avoid adding permanent functionality directly to WooCommerce plugin files or a parent theme.
- Check the email ID: Use the correct email ID when targeting a specific notification.
- Preserve existing recipients: Append additional recipients instead of replacing the existing recipient list unless replacement is intentional.
- Validate order objects: Check that the order object is valid before calling its methods.
- Test different order types: Test physical, virtual, cancelled, failed, and high-value orders where relevant.
- Check email delivery: Confirm that messages reach the intended recipients and are not rejected or marked as spam.
- Use a staging website: Test custom email code before adding it to a live WooCommerce store.
Frequently Asked Questions
1. What is a WooCommerce email ID?
A WooCommerce email ID is a unique identifier used by WooCommerce to identify a particular email notification. Examples include new_order, failed_order, and customer_processing_order.
2. Why should I use an email ID instead of checking only the order status?
An order status describes the current state of an order, while an email ID identifies the notification being generated. Using the email ID allows you to target a specific email type, even when multiple notifications are related to similar order events.
3. Can I customize WooCommerce emails without installing a plugin?
Yes. You can use WooCommerce actions and filters in a custom plugin or child theme. For example, you can use woocommerce_email_before_order_table to add content and woocommerce_email_recipient_new_order to modify New Order email recipients.
4. Can I add multiple recipients to WooCommerce emails?
Yes. You can enter multiple addresses separated by commas in supported email recipient settings or use a recipient filter to add addresses dynamically based on order conditions.
5. Can I target a customer email using its email ID?
Yes. You can check the email object’s ID in a supported email hook. For example, customer_processing_order identifies the customer Processing Order notification.
6. Where should I add custom WooCommerce email code?
For reusable functionality, a custom plugin is generally a good choice. You can also use a child theme’s functions.php file for theme-specific customizations. Avoid editing WooCommerce core plugin files.
Final Thoughts
Targeting WooCommerce email notifications by email ID gives developers more control over how order emails behave. Instead of applying the same customization to every notification, you can use the email object to identify the exact email type and run the required PHP code.
You can use this approach to add custom messages, send notifications to additional recipients, notify different departments, and customize email content based on order details.
For long-term projects, keep your customizations in a dedicated plugin and test every email type before deploying changes to a live store.