Multiple Email Recipients for WooCommerce Subscriptions

Last November I switched my hosting renewals over to WooCommerce Subscription. I previously used Xero to handle all of my subscriptions via a repeat invoice, however it wasn’t really intended to handle my type of business. Also I just wanted to get my hands inside of WooCommerce for learning purposes.  WooCommerce makes it really easy to sync all the data back using their Xero addon, and I still use Xero for accounting and bookkeeping.

One feature I really miss from Xero was the ability to include multiple people on a single invoice. That sort of functionality is not included with WooCommerce Subscriptions. Also, most WooCommerce multiple recipients plugins are solving a different problem.

Using ACF to collect additional emails

I decided the simplest way to manage the email recipients would be to manage them on the WooCommerce Subscriptions page itself. Subscriptions are already a custom post type so attaching a field with ACF works like so.

Screen Shot 2017-07-20 at 8.50.54 AM.png

Now on subscription page there will be a box to add additional email recipients.

Screen Shot 2017-07-20 at 9.13.27 AM

To make this all work some custom code is required. The following will hook into WooCommerce Subscription email notifications and attach any additional email recipients.

// Checks subscription for additional emails
add_filter( 'woocommerce_email_recipient_customer_completed_renewal_order', 'woocommerce_email_customer_invoice_add_recipients', 10, 2 );
add_filter( 'woocommerce_email_recipient_customer_renewal_invoice', 'woocommerce_email_customer_invoice_add_recipients', 10, 2 );
function woocommerce_email_customer_invoice_add_recipients( $recipient, $order ) {

    // Finds subscription for the order
    $subscription = wcs_get_subscriptions_for_order( $order, array( 'order_type' => array( 'parent', 'renewal' ) ) );

    if ( $subscription and array_values($subscription)[0] ) {
        // Find first subscription ID
        $subscription_id = array_values($subscription)[0]->id;
        // Check ACF field for additional emails
        $additional_emails = get_field('additional_emails', $subscription_id);

        if ($additional_emails) {
            // Found additional emails so add them to the $recipients list
            $recipient .= ', ' . $additional_emails;
        }
    }
    return $recipient;
}

Verify everything is working using Log Emails

Testing emails can be tricky. I recommend installing the plugin Log Emails. With this enabled you’ll be able to see who your emails were sent to right from the WordPress backend.

Screen Shot 2017-07-20 at 8.57.02 AM.png