Add Custom Order Status & Emails in WooCommerce Easily

Enhancing your WooCommerce store with custom features allows you to better tailor it to your business needs. This tutorial will show you how to set up a custom order status and link it with personalized email notifications. With a few easy steps, you can fully integrate this new status into your store’s workflow.

 

Step 1: Define Your Custom Order Status

Begin by registering a new status using register_post_status. Add the code below to your theme’s functions.php or within a custom plugin:

// Register a custom order status
function add_custom_order_status() {
    register_post_status( 'wc-custom-status', array(
        'label'                     => _x( 'Custom Status', 'Order status', 'your-text-domain' ),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Custom Status (%s)', 'Custom Status (%s)', 'your-text-domain' )
    ) );
}
add_action( 'init', 'add_custom_order_status' );

Step 2: Display Status in Admin Orders List

Ensure your new status appears in the order filter dropdown with the wc_order_statuses filter:

// Add to admin order status filter
function add_custom_order_status_to_filter( $order_statuses ) {
    $order_statuses['wc-custom-status'] = _x( 'Custom Status', 'Order status', 'your-text-domain' );
    return $order_statuses;
}
add_filter( 'wc_order_statuses', 'add_custom_order_status_to_filter' );

Step 3: Register Email Trigger for Custom Status

Use woocommerce_email_actions to add a custom trigger:

// Email trigger for custom status
function add_custom_email_action( $email_actions ) {
    $email_actions[] = 'woocommerce_order_status_wc-custom-status';
    return $email_actions;
}
add_filter( 'woocommerce_email_actions', 'add_custom_email_action' );

Step 4: Create a Custom Email Handler Class

Next, build a class extending WC_Email. Save it as custom-new-order-email.php:

// custom-new-order-email.php
class Custom_New_Order_Email extends WC_Email {
    public function __construct() {
        $this->id             = 'custom_new_order';
        $this->title          = __( 'Custom New Order', 'your-text-domain' );
        $this->description    = __( 'Triggered when an order changes to your custom status.', 'your-text-domain' );
        $this->heading        = __( 'Custom New Order', 'your-text-domain' );
        $this->subject        = __( 'New Order: #{order_number}', 'your-text-domain' );
        $this->template_html  = 'emails/custom-new-order.php';
        $this->template_plain = 'emails/plain/custom-new-order.php';
        $this->template_base  = plugin_dir_path( __FILE__ );
        $this->placeholders   = array(
            '{order_number}' => '',
        );

        parent::__construct();
    }

    public function trigger( $order_id ) {
        $this->object = wc_get_order( $order_id );
        $this->recipient = $this->object->get_billing_email();
        $this->placeholders['{order_number}'] = $this->object->get_order_number();
        $this->heading = apply_filters( 'woocommerce_email_heading_' . $this->id, $this->heading, $this->object );
        $this->subject = apply_filters( 'woocommerce_email_subject_' . $this->id, $this->subject, $this->object );

        parent::trigger( $order_id );
    }
}

Step 5: Attach Custom Email to WooCommerce

Finally, register your email class via the woocommerce_email_classes filter:

// Add custom email class
function add_custom_email_class( $email_classes ) {
    require_once 'path/to/custom-new-order-email.php';
    $email_classes['Custom_New_Order_Email'] = new Custom_New_Order_Email();
    return $email_classes;
}
add_filter( 'woocommerce_email_classes', 'add_custom_email_class' );

Final Thoughts

You’ve now successfully added a custom order status in WooCommerce along with a dedicated email template. This approach helps improve communication with customers and streamline your workflow.

Pro Tip: Always make changes using a child theme or a custom plugin. Test thoroughly before applying on your live store.

Need more help? Check the official WooCommerce Email Customization Guide.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.