• I’m registering affiliates via function call, hooked to user_register (priority 20) so I can use a third party registration form. My code looks like:

    $data = array(
    			'user_id'		=> $user_id,
    			'payment_email'	=> $user->user_email
    		);
    
    	$result = affwp_add_affiliate( $data );

    The affiliates are registered correctly in the pending status, but even after I click “accept”, they aren’t added to my configured Mailchimp list. In my AffiliateWP Mailchimp settings, I have “Auto Subscribed” checked. Any suggestions? Thanks.

    https://www.ads-software.com/plugins/affiliatewp-mailchimp-add-on/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Tunbosun Ayinla

    (@tubiz)

    Hi jgarturo,

    The affiliate can’t be added via that function call as the hook that add the affiliate to the Mailchimp list is not located in the affwp_add_affiliate function.

    How are affiliates being added on your site?
    Are you using the AffiliateWP registration or you are using a custom created form.

    Let me know your use case, so I can recommend a way to get it done.

    Cheers.

    Thread Starter jgarturo

    (@jgarturo)

    I’m using a custom registration form. The full code looks like:

    function wpf_register_affiliate( $user_id ) {
    
    	// Only run on UserPro forms
    	if(!isset($_POST['unique_id']))
    		return;
    
    	// Only run on affiliate registration forms
    	if(!isset($_POST['form_role-' . $_POST['unique_id']]))
    		return;
    
    	$user = get_userdata( $user_id );
    
    	$data = array(
    			'user_id'		=> $user_id,
    			'payment_email'	=> $user->user_email
    		);
    
    	$result = affwp_add_affiliate( $data );
    
    }
    
    add_action( 'user_register', 'wpf_register_affiliate', 20, 1 );

    How can I best auto-subscribe someone to the configured Mailchimp list?

    Plugin Author Tunbosun Ayinla

    (@tubiz)

    Use this code instead

    function wpf_register_affiliate( $user_id ) {
    
    	// Only run on UserPro forms
    	if(!isset($_POST['unique_id']))
    		return;
    
    	// Only run on affiliate registration forms
    	if(!isset($_POST['form_role-' . $_POST['unique_id']]))
    		return;
    
    	$user = get_userdata( $user_id );
    
    	$status = affiliate_wp()->settings->get( 'require_approval' ) ? 'pending' : 'active';
    
    	$affiliate_id       = affiliate_wp()->affiliates->add( array(
    		'status'        => $status,
    		'user_id'       => $user_id,
    		'payment_email' => $user->user_email
    	) );
    
    	do_action( 'affwp_register_user', $affiliate_id, $status );
    
    }
    
    add_action( 'user_register', 'wpf_register_affiliate', 20, 1 );

    Let me know once you have tried it.

    Cheers.

    Thread Starter jgarturo

    (@jgarturo)

    Your modified function registers the affiliate correctly in pending status but doesn’t add the user to the list. Ideally I’d like to only add the user to the list when they’ve been accepted as an affiliate… but if your plugin isn’t set up that way I can find a workaround.

    Plugin Author Tunbosun Ayinla

    (@tubiz)

    Are you sure the enable checkbox is ticked in the AffilieteWP Mailchimp settings page
    Because the function I posted is meant to work.

    Thread Starter jgarturo

    (@jgarturo)

    https://oi59.tinypic.com/fy1iis.jpg

    Any obvious solutions? I can probably figure this out with some error_log’ing on my local install.. was just looking for a quick answer if you had one. I’ll play with it today / tomorrow and post back here when I get it working.

    Plugin Author Tunbosun Ayinla

    (@tubiz)

    Actually I haven’t tested the function to verify if it works.
    But once am free in some couple of hours will work on it, the next reply you will get from me will be a working function.
    Cheers.

    Plugin Author Tunbosun Ayinla

    (@tubiz)

    Actually the snippet I shared earlier on wasnt’t tested.
    Will test it in some couple of hours. Be rest assured the next response you are getting from me is the code that is working.

    Cheers.

    Thread Starter jgarturo

    (@jgarturo)

    Any luck with this?

    Plugin Author Tunbosun Ayinla

    (@tubiz)

    Hi jgarturo,

    Were you able to get this sorted out?

    Cheers.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Subscribers not getting added when affiliates registered via function’ is closed to new replies.