How to create custom WooCommerce order email templates based on product type

WooCommerce provides a flexible email system, but it does not natively support sending different email content based on product type or category. For stores that sell a mix of simple products, complex items, and services, this can create limitations in customer communication.

In this guide, we walk through how to create multiple custom WooCommerce email templates with conditional logic based on the products in an order.

Issue Background

A WooCommerce store required three different order confirmation emails depending on the type of product purchased. These included a standard message for simple products, custom instructions for complex products, and send-in instructions for service orders.

The solution also needed to allow email templates to be editable within WooCommerce settings and apply logic based on product categories or types.

Diagnosis

WooCommerce sends a single default email for order confirmations, regardless of what products are included in the order. While templates can be overridden in a theme, this only changes the design and does not allow conditional logic.

To send different emails based on product type, custom development is required. This includes creating new email classes, adding logic to determine when they should be triggered, and ensuring they integrate with WooCommerce settings.

Resolution Steps

1. Create custom email classes.

Develop a custom plugin that registers multiple WooCommerce email types. Each email should extend the WC_Email class and define its own subject, heading, and template.

2. Register emails in WooCommerce settings.

Ensure each custom email appears under WooCommerce > Settings > Emails so it can be managed from the admin panel.

3. Add conditional logic based on products.

Hook into the order process and check product categories or types to determine which email should be triggered.

foreach ($order->get_items() as $item) {
    $product = $item->get_product();
    if (has_term('service', 'product_cat', $product->get_id())) {
        // Trigger service email
    }
}

4. Prevent duplicate emails.

Disable or override default WooCommerce emails where necessary to avoid sending multiple confirmations for a single order.

5. Customize templates in your theme.

Override email templates in your theme directory to control layout and messaging.

6. Support multiple categories.

Ensure your logic accounts for products assigned to multiple categories and prioritizes the correct email type.

7. Test all order scenarios.

Test simple, complex, service, and mixed-product orders to confirm the correct email is sent and that no blank emails are generated.

Final Outcome

With the custom implementation in place, the store was able to send different order confirmation emails based on product type. Each email was fully editable within WooCommerce settings and aligned with the correct fulfillment workflow.

The key takeaway is that while WooCommerce supports email customization, advanced conditional logic requires a custom plugin or code-based solution.

If you need help customizing WooCommerce emails or building advanced order workflows, contact Freshy.