The built-in checks compare emails, IP addresses, phone numbers and addresses. If your customers have another unique value, such as a membership number, VAT number or company ID, you can block rewards when the friend and the advocate share it.
Before you start: read Add code snippets safely. Checked with version 4.4.12. You need to know the user meta key the value is saved under, for example from your registration or checkout field plugin.
Add the snippet
Change membership_number to your meta key.
add_filter( 'gens_raf_order_info', function ( $raf_info, $order, $referrer_id ) {
$meta_key = 'membership_number';
// Only add a block. Never override the built-in checks.
if ( ! isset( $raf_info['generate'] ) || 'true' !== $raf_info['generate'] ) {
return $raf_info;
}
if ( ! is_numeric( $referrer_id ) || ! $order->get_user_id() ) {
return $raf_info;
}
$friend_value = trim( (string) get_user_meta( $order->get_user_id(), $meta_key, true ) );
$advocate_value = trim( (string) get_user_meta( $referrer_id, $meta_key, true ) );
if ( '' !== $friend_value && strcasecmp( $friend_value, $advocate_value ) === 0 ) {
$raf_info['info'] = 'Potential fraud: the friend and the advocate have the same ' . $meta_key . '.';
$raf_info['generate'] = 'false';
$raf_info['increase_referrals'] = 'false';
}
return $raf_info;
}, 10, 3 );
How it works
- The check runs when the friend places their order, after the built-in checks.
- It only blocks rewards. If a built-in check already flagged the order, that result is kept.
- It works when both the friend and the advocate have an account. Guest orders and guest advocates are skipped.
- A blocked order shows your message in its Refer a Friend Data box, and you can still approve it by hand. See Assign a referral to an order manually.
The snippet doesn’t send a fraud alert email, and the friend still gets their first-purchase discount.
Older versions of this snippet set every other referral to “All good, coupon will be generated.” That silently turned off the built-in fraud checks. If you use the old version, replace it with this one.
Check it worked
Give two test accounts the same value, refer one with the other, and place an order. The order’s Refer a Friend Data box should show your message, and Generate a coupon on order complete: should be No.