Send an Additional Transactional Email in WooCommerce

Sometimes you might need to notify a third party when an order is processed on your WooCommerce store. Fortunately, doing so is quite easy when you use the hooks available.

Creating the Function

Firstly, we want to hook into the action that is triggered when an order is set to processing on our store. This is the point at which payment has been accepted and paid for (if applicable). You’ll need to add the following functions to your theme’s functions.php file.

We’re hooking into the woocommerce_order_status_pending_to_processing_notification action, which occurs when an order is successfully processed. It accepts 1 parameter, which is the $order_id.

We can then use this data to generate our own email using the $mailer->send() helper. You can see the parameters I added are:

  • $recipient
    This is the email address of the person you;d like to notify.
  • $subject
    The subject of your email.
  • $content
    The email content. We’re fetching this from a custom function, which I’ll explain in a moment.
  • $headers
    This tells the mailer that we’re sending an HTML email.

It’s all quite simple at this stage. But what about the actual email content. How is that generated? Well, we’re using the iconic_get_processing_notification_content function, which looks like this:

Again, a fairly simple function. We’re using the wc_get_template_html() function to generate our email content, so this makes things a lot easier. Let’s take a look at the parameters for wc_get_template_html():

  • $template
    We’re passing the path to the customer-processing-order.php template file. You could create a woocommerce/emails folder in your own theme and duplicate any of the email templates from wp-content/plugins/woocommerce/templates/emails with a new name. This will allow you to create your own template for this email.
  • $args
    The second parameter is an array of arguments. We’re passing in the $order object, the $heading, the $mailer object, a sent_to_admin flag, and a plain_text flag. The heading is displayed at the top of the email with larger typography. We can modify the $heading of the email by passing in a different string of text in our iconic_processing_notification() function, at the $content variable. Currently we just use the subject line as a heading.

Wrap Up

This should get you on your way. Now you can create your new email template and use the functions above to send the email. Comments below, as usual!

Leave a Reply

7 Comments on "Send an Additional Transactional Email in WooCommerce"

avatar
  Subscribe  
newest oldest most voted
Notify of
ГенКлауд
Guest

Thx, mate. Pretty much works for me, but i’m just using it with ‘woocommerce_order_status_pending’ hook.
Do you have any idea how to send another of standart woocommerce email, like the one that goes for a new order?

Olivier G.
Guest

Thanks very much James. Simple but great ! Very Useful ! (y)

justin
Guest

Hi James,

We are trying to insert the name of the product that was ordered into a Custom Order Status Email. But can’t figure it out. Do you know the correct PHP to do this?

I.E.

Hello,

Thanks for purchasing “product name” your order etc….

Thanks,

Justin