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?

  • 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? – Athoxx Aug 6 '19 at 12:52
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.

  • 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' – Athoxx Aug 6 '19 at 12:48
  • its a while ago, but I recall testing this with a debugger on a project I was working on then – jdog Aug 7 '19 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 <rana_imagine@yahoo.com>';
  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 <rana_imagine@yahoo.com>' . "\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 <rana_imagine@yahoo.com>' . "\r\n";
  }
  return $headers;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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