$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>woocommerce offtopic - Send admin new order email to logged in user as well|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

woocommerce offtopic - Send admin new order email to logged in user as well

matteradmin14PV0评论

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;
}
Post a comment

comment list (0)

  1. No comments so far