0

I'd like to customise the recipient of a new order in WooCommerce. According to the documentation and various examples I can do this like so:

function wc_change_admin_new_order_email_recipient( $recipient, $order ) {
    global $woocommerce;

//some code
    return $recipient;
}
add_filter('woocommerce_email_recipient_new_order', 'wc_change_admin_new_order_email_recipient', 10, 2);

However I cannot get this filter to trigger on my local development machine, nor can I get the site to send order emails even with this code removed.

I have a working local debugger and the code stops at various points in the wc_email class, however it only gets to the get_recipient function when I change the admin email in the backend.

Here is what I have tried:

  • turned all other plugins off
  • made sure Wordpress, WooCommerce, Theme is up to date
  • Some theme files are shown as not up to date, but admin-new-order.php does not show in this list
  • admin-new-order.php in overrides folder is identical to WooCommerce version, so I have also tried to remove the override completely
  • Lost password sends me an email on my local system (over the Internet), so email delivery is working

Is there a cron job used for delivery of the admin new order email, if so how can I trigger it?

Any other ideas?

1
  • I'm having this exact same issue, and I find it hard to believe that "new_order" is only triggered after the order was paid, as there is a filter for specifically that event: woocommerce_email_recipient_customer_invoice_paid. Did you ever find a solution? Commented Aug 6, 2019 at 12:52

2 Answers 2

0

The order notification email to admin is sent as part of the Payment notification process - in this case Paypal IPN

To test this on a local domain, the best way was to trigger the order email from the orders list in the backend.

The above code works fine.

2
  • Is this actually true? Shouldn't "new_order" be triggered as the order is placed? There are filter hooks pertaining to when orders have been processed, paid etc, such as 'woocommerce_email_recipient_customer_invoice_paid' Commented Aug 6, 2019 at 12:48
  • its a while ago, but I recall testing this with a debugger on a project I was working on then
    – jdog
    Commented Aug 7, 2019 at 1:00
0

WordPress Version: 5.2.2

WooCommerce version: 3.7.0

To send a static recipient (override default)

add_filter( 'woocommerce_email_headers', 'hasan_headers_filter_function', 10, 2);

function hasan_headers_filter_function( $headers, $object ) {
  $headers = 'Test Dealer <[email protected]>';
  return $headers;
}

To send extra static recipient along with admin

add_filter( 'woocommerce_email_headers', 'hasan_headers_filter_function', 10, 2);

function hasan_headers_filter_function( $headers, $object ) {
  $headers .= 'CC: Test Dealer <[email protected]>' . "\r\n";
  return $headers;
}

if you only want to send when order is complete

add_filter( 'woocommerce_email_headers', 'hasan_headers_filter_function', 10, 2);

function hasan_headers_filter_function( $headers, $object ) {
  if ($object == 'customer_completed_order') {
    $headers .= 'CC: Test Dealer <[email protected]>' . "\r\n";
  }
  return $headers;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.