Hide AffiliateWP’s affiliate registration form until the visitor is referred by an existing (and valid) affiliate. Only the affiliate registration form shown via the [affiliate_area] shortcode will be hidden.

<?php

/**
 * Hide the affiliate registration form unless the user is referred by a valid affiliate.
 * Only the affiliate registration form shown with the [affiliate_area] shortcode will be hidden.
 *
 * @return bool $return Whether the affiliate registration form can be shown.
 */
function am_affwp_hide_affiliate_registration_form_unless_referred( $return ) {

	// Bail if AffiliateWP is not active.
	if ( ! function_exists( 'affiliate_wp' ) ) {
		return false;
	}

	// Determine if the current user was referred by a valid affiliate.
	$was_referred = affiliate_wp()->tracking->was_referred();

	// Hide the affiliate registration form if the user was not referred by an affiliate.
	if ( ! $was_referred ) {
		$return = false;
	}

	return $return;

}
add_filter( 'affwp_affiliate_area_show_registration', 'am_affwp_hide_affiliate_registration_form_unless_referred' );

Leave a Reply

Your email address will not be published. Required fields are marked *