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!
By default, the WooCommerce Refer a Friend plugin checks that the shipping address and email address are unique to prevent fraud. If you have some unique data that every customer needs to have, you can use the code below to check if that data between the referred person and referral is the same, and if it is, prevent the use of the referral system:
function gens_check_social_num($raf_info,$order,$referrer_id) {
$customer_id = $order->get_user_id();
$customer_number = get_user_meta($customer_id, "social_number", true);
$referral_number = get_user_meta($referrer_id, "social_number", true);
$enable_referral = "yes";
if(!empty($customer_number) && !empty($referral_number) && ($customer_number == $referral_number)) {
$enable_referral = "no";
}
if($enable_referral === "no") {
$raf_info = array("info" => "Customer added same social security number", "generate" => "false", "increase_referrals" => "false");
} else {
$raf_info = array("info" => "All good, coupon will be generated.", "generate" => "true", "increase_referrals" => "true");
}
return $raf_info;
}
add_filter( 'gens_raf_order_info', 'gens_check_social_num',10,3);
Just make sure to change “social_number” to the correct user meta.