Hide referral link for customers without any order

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 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!

Via wpgens_raf_link filter, you can show referral link to specific customers. In this example, we are hiding referral link for customers that have zero orders. 

function gens_raf_link($raf_link, $referral_id, $type) {
	$user_id = get_current_user_id();
	if($user_id == 0) {
	$customer_orders = get_posts( array(
	    'numberposts' => 999,
	    'meta_query' => array(
				'key'    => '_customer_user',
	    		'value'  => $user_id,
	    'post_type'   => wc_get_order_types(),
	    'post_status' => 'wc-completed',
	) );

	if(count($customer_orders) < 1) {
		return "You need at least one order for referral link";
	} else {
		return $raf_link;

You can use similar code to hide referral links per user roles. Contact us if you need help.

Still need help? Contact Us Contact Us