Limit maximum number of coupons/referrals user can earn

READ FIRST: This code works on 2.0+ version of a plugin. Also, 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 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 for some reason you want to limit the number of coupons one user can earn via Refer a Friend plugin, add a code below to functions.php file, of course, change "20" to the number you want to limit to.

function gens_limit_number_of_coupons($raf_info,$order,$referrer_id) {
    $num_referrals = intval(get_user_meta($referrer_id, "gens_num_friends", true));
    if($num_referrals > 20) {
    	$raf_info = array("info" => "User has reached maximum number of referred customers.", "generate" => "false", "increase_referrals" => "false");
    return $raf_info;
add_filter( 'gens_raf_order_info', 'gens_limit_number_of_coupons',10,3);

If you also want to hide the referral link after this, add the this code as well:

function gens_raf_link($raf_link, $referral_id, $type) {
	$user_id = get_current_user_id();
        $num_referrals = intval(get_user_meta($user_id, "gens_num_friends", true));
        if($num_referrals > 20) {
	  return "You have reached maximum number of customers you can refer.";
    return $raf_link;

Still need help? Contact Us Contact Us