Make New MemberPress Members Affiliates Automatically in Affiliate Royale

In this article we will show you how to use some custom code to accomplish two different ways of making MemberPress users affiliates automatically through the MemberPress registration page. The first method covers how to make subscribers to specific memberships (not all) affiliates in Affiliate Royale. The second is how to make every subscriber to any membership affiliates in Affiliate Royale with the exception of any specified memberships.

First Option:

  1. Disable the “make all new users affiliates” option (if you have it enabled) in your Affiliate Royale > Options > Affiliate Settings > Affiliate Registration.
  2. Download the plugin My Custom Functions here and install and activate onto your WordPress site. This is where you’ll place the custom code.
  3. Paste this code into My Custom Functions:
    function make_new_user_affiliate($txn) {
      $membership_ids_for_affs = array(123,321,789);
      
      if(in_array($txn->product_id, $membership_ids_for_affs, false) && class_exists('WafpUser')) {
        global $wafp_options;
    
        if(!$wafp_options->make_new_users_affiliates) {
          $user = new WafpUser($txn->user_id);
    
          if(!$user->get_is_affiliate()) {
            $user->set_is_affiliate(true);
            $user->store();
            $user->send_account_notifications($user->get_password(), $wafp_options->welcome_email, $wafp_options->welcome_email);
          }
        }
      }
    }
    add_action('mepr-txn-status-complete', 'make_new_user_affiliate');
  4. Change the second line of the array of ID’s and put your own Membership ID’s there (Where to find a Membership’s ID?)
  5. Save the code and then test to make sure it is working how you need.

Second Option:

  1. For this one you want to make sure that you have enabled the “make all new users affiliates” option (if you have it disabled) in your Affiliate Royale > Options > Affiliate Settings > Affiliate Registration.
  2. Download the plugin My Custom Functions here and install and activate onto your WordPress site. This is where you’ll place the custom code.
  3. Paste this code into My Custom Functions:
    function no_auto_aff($errors) {
      $exclude = array(123,321,789);
      if(isset($_POST['mepr_product_id']) && in_array((int)$_POST['mepr_product_id'], $exclude, false)) {
        $_REQUEST['no_wafp_aff'] = true;
      }
    
      return $errors;
    }
    add_filter('mepr-validate-signup', 'no_auto_aff');
  4. Change the second line of the array of ID’s to reflect your own Membership ID’s that you want to exclude from being added as affiliates. (Where to find a Membership’s ID?)
  5. Save the code and then test to make sure it is working how you need.

Still Not Working?

If you find that it’s still not working according to your tests, start by reviewing your code to make sure that you’ve entered it correctly. It it looks correct to you, one way to double check is to copy the code directly from this page, and then paste it into My Custom Functions using CTRL+Shift+v to paste. Finally, feel free to reach out to our support team here for additional help.