Troubleshooting Files: How to Send Specific Order Process Emails in WooCommerce

By David Zimmerman, aka Zim Zala Bim faded laptop in background with html code highlighted on the screen

We had a helpdesk ticket come through from someone with a WooCommerce site who wanted to send different messages out in customer emails depending on which shipping method the customer used. There are a few ways to do that with WooCommerce. But, allowing the site owner or developers working on the updates to preview those email messages is not as straight-forward since the old “Order Actions” dropdown was simplified a few years ago. If you need to send specific order process emails in WooCommerce, like “Order Processing” or “Order Complete”, rather than the generic customer invoice, here is how to do it:

1. Figure Out Where To Start

Years ago, in earlier versions of WooCommerce, there were a few more options available in this dropdown:

But, those options were removed back in 2017.

Digging into WooCommerce’s source code, we find a few hooks we can use to put these options back in or add any other custom order actions. Getting the custom order actions into the “wc_order_action” dropdown is simple enough. After all, there’s a hook for that – woocommerce_order_actions

2. Add New Options to the Order Actions Dropdown

We can hook in here and add our custom actions. We’re going to add the Order Processing email, specifically, and denote it with an asterisk. Usually, this email is only sent when the order is actually “processing” in the system and can’t be resent once an order completes, but this allows us to resend it as needed. It should look something like this:

add_action( 'woocommerce_order_actions', 'mind_woo_order_actions' );

function mind_woo_order_actions( $actions ) {
    $actions['resend_order_processing_email'] =  '* Resend "Order Processing" Email';
    return $actions;
}

3. Define the Function to Run for the New Custom Action

Next, we need to define what happens when someone selects our custom action. WooCommerce automatically generates a hook based on the way you defined the custom order action in the last function. So, make sure you remember your action’s name, which is the key in the $actions array, and hook in with the “wc_order_action_” prefix. Where our action was “resend_order_processing_email”, we can hook into “woocommerce_order_action_resend_order_processing_email” with our custom function., like this:

add_action( 'woocommerce_order_action_resend_order_processing_email', 'mind_woo_resend_order_processing_email' );

function mind_woo_resend_order_processing_email( $order ) {
 // do stuff
}

4. Find the WooCommerce Email to Trigger

Now, we can use the built-in email triggers for WooCommerce to send the appropriate emails we want. Reference the WC Email class to make sure you’re using the right one.

add_action( 'woocommerce_order_action_resend_order_processing_email', 'mind_woo_resend_order_processing_email' );

function mind_woo_resend_order_processing_email( $order ) {
       $order_id = $order->get_id();
       $allmails = WC()->mailer()->emails;
       $email = $allmails['WC_Email_Customer_Processing_Order'];
       $email->trigger( $order_id );
}

You Can Add an Order Note Too

Let’s add an order note too, showing that it was resent:

$order->add_order_note( '"Order Processing" Email Resent' );

The Complete Code for Sending Specific Order Process Emails in WooCommerce

Putting everything together, it should look a little something like this:

add_action( 'woocommerce_order_actions', 'mind_woo_order_actions' );
function mind_woo_order_actions( $actions ) {
    $actions['resend_order_processing_email'] =  '* Resend "Order Processing" Email';
    return $actions;
}


add_action( 'woocommerce_order_action_resend_order_processing_email', 'mind_woo_resend_order_processing_email' );
function mind_woo_resend_order_processing_email( $order ) {
        $order_id = $order->get_id();
        $allmails = WC()->mailer()->emails;
        $email = $allmails['WC_Email_Customer_Processing_Order'];
        $email->trigger( $order_id );
        $order->add_order_note( '"Order Processing" Email Resent' );
}

Enjoy your new order action to resend specific order process emails in WooCommerce!

View Comments

10 responses to “Troubleshooting Files: How to Send Specific Order Process Emails in WooCommerce”

  1. Thanks for the code! It was really helpfull! In my case I needed to resend the completed order email. Just had to change the “WC_Email_Customer_Processing_Order” for “WC_Email_Customer_Completed_Order”.

    Worked perfectly! 😀

  2. what if you want to change the email address it’s sending to? For example, the “i didn’t receive the email.” So you send a copy to yourself that you can then forward on.

  3. Hi, First off

    Thanks so much for this snippet.

    Worked really well for me. I do have an issue when I “first use” it.

    It doesn’t seem to capture the meta box details (URL,tracking number ) I’m also using.

    Then I change the order email account, hit update, send it again using another email.

    Worked like a charm.

    What do you think is the best practice to ensure those meta box details are sent?

    Ty!

    • Hi Paul, if I understand correctly, the issue may be related to these being different order actions. It will depend on what else is going on in your specific situation (for example, you may need to save those fields in your custom action as well), but reviewing the WC_Admin_Meta_Boxes class may be a good place to start.

  4. Hey there,

    Do I have to have some sort of woocommerce_mind plugin installed (re: “mind_woo_resend_order_processing_email” ) The reason I ask is that I pasted this into my child theme functions.php and nothing changed. I logged in and out a few times to my wp-admin as well.

    Thanks!

  5. Hey Andrew, no, the mind_ prefix was used arbitrarily for those functions, no additional plugins required. If you’re not seeing new options in the dropdown after using the woocommerce_order_actions hook, some additional troubleshooting would be required.

  6. Brilliant, thank you for this. I’m honing my email templates and though there must be a better solution than placing dozens of test orders.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Are You Ready To Do More with Mind?

Click the link below to get started!

Work With Mind