0

I need to be able to send the admin email for a new order also to the e-mail address linked to the current logged in user.

This is required as 1 account is for different people (people who give a present), but the originally created account is still linked to the original user e-mail address (from the parents).

This way, parents are notified via email when a new gift is given.

I don't seem to find the fix here. I started to adapt the code from Adding a second email address to a completed order in WooCommerce, but now I want to dynamically add the e-mail address of the user.

Any ideas what I'm doing wrong here?

/* SEND ADMIN E-MAIL TO LOGGED IN USER */
/* --- */
add_filter( 'woocommerce_email_recipient_new_order', 'your_email_recipient_filter_function', 10, 2);

/* Add parents e-mail address to new order admin mail */
function your_email_recipient_filter_function($recipient, $object) {
    $user_info = get_userdata($order->user_id);
    $recipient = $recipient . ', ' . $user_info->user_email;
    return $recipient;
}
1

What you have makes sense, except that your variable names dont match. You have $object in your function definition and in the function code you are trying to use $order.

Adjusted:

/* SEND ADMIN E-MAIL TO LOGGED IN USER */
/* --- */
add_filter( 'woocommerce_email_recipient_new_order', 'your_email_recipient_filter_function', 10, 2);

/* Add parents e-mail address to new order admin mail */
function your_email_recipient_filter_function($recipient, $order) {
    $user_info = get_userdata($order->user_id);
    $recipient = $recipient . ', ' . $user_info->user_email;
    return $recipient;
}
  • Thanks a million! That does the trick. Code is working now 👌🏼! – BarrieO Mar 20 at 16:32

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.