Hi, you’re welcome. happy to help.
there are some plugins to send email to users. check out Email Users and WP Email Users. you can use [wp-referral-code var=”ref_link”] shortcode to display refer link in email content. and [wp-referral-code var=”ref_code”] for refer code.
here is a simple snippet. it emails refer link to user on registration. you should modify subject and body(html) variables.
add_action('user_register', function ($user_id) {
/** @var WP_User $user */
$user = WP_user::get_data_by('id', $user_id);
$ref_code = new WP_Refer_Code($user_id);
$to = $user->user_email;
$subject = 'The Email subject';
$body = 'Hey '.$user->first_name.'. Your refer code is: <a href="'
.$ref_code->get_ref_link().'" target="_blank">'.$ref_code->get_ref_link()."</a>";
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($to, $subject, $body, $headers);
});