Generate a coupon code on every nth referral.

READ FIRST: This code was used on older version of a plugin, before 2.0. With 2.0 version, this comes as a field inside Refer a Friend Settings page, so no need to use this code anymore.

By default, the plugin will generate a coupon code on every successful referral. You can change this via built-in filter so that you can reward customer on every nth referral.

// Minimum three orders
function min_five_orders($not_active,$num_friends_refered,$order,$referrer_id) {
	if($num_friends_refered % 3 == 0) {
		$not_active = "no";        
	} else {
		// Dont generate coupon, but increase number of people referred.
		$not_active = "yes";
		update_user_meta( $referrer_id, 'gens_num_friends', (int)$num_friends_refered + 1 );
	}
	return $not_active;
}
add_filter( 'gens_raf_not_active', 'min_five_orders',10,4);

The example above will generate a coupon code for every 3rd referred friend. You can change the code above to generate coupon until x amount of friends are referred as well.

We are passing the order object, a number of friends customer have referred and his id. You can use a combination of these two to limit coupon generation per any case.

Still need help? Contact Us Contact Us