READ FIRST: This code needs to be added at the end of the functions.php file. If you are familiar with editing functions.php, feel free to continue reading. If you haven’t done this before, adding this code in the wrong place might bring the site down and the only way to access it is by editing functions.php file again via FTP. Feel free to contact us if you need help!
If you want to add a referral indication within the new order email, add this code to functions.php file:
add_action('woocommerce_email_order_details', 'add_referral_info_to_order_email', 20, 4);
function add_referral_info_to_order_email($order, $sent_to_admin, $plain_text, $email)
{
// Only add info to admin emails
if (!$sent_to_admin) {
return;
}
$raf_id = $order->get_meta('_wpgens_raf_id', true);
if (!$raf_id) {
return;
}
$user_query_args = array(
'meta_key' => 'gens_referral_id',
'meta_value' => $raf_id,
);
$user_query = new WP_User_Query($user_query_args);
$users = $user_query->get_results();
if (!empty($users)) {
$user = reset($users);
$email = $user->user_email;
// $grouped_orders[$raf_id]['user_name'] = $user->first_name ? $user->first_name.' '.$user->last_name : '-';
// $grouped_orders[$raf_id]['user_link'] = get_edit_user_link($user->ID);
} else {
$email = $raf_id;
}
echo '<br><strong>Referral order, referred by: ' . $email . '</strong><br><br><br>';
}