admin管理员组

文章数量:1435859

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;
}

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;
}
Share Improve this question edited Mar 20, 2019 at 12:51 butlerblog 5,1313 gold badges28 silver badges44 bronze badges asked Mar 20, 2019 at 11:42 BarrieOBarrieO 992 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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;
}

本文标签: woocommerce offtopicSend admin new order email to logged in user as well