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.
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?
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.
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.
Are you sure the enable checkbox is ticked in the AffilieteWP Mailchimp settings page
Because the function I posted is meant to work.
http://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.
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.
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.
Hi jgarturo,
Were you able to get this sorted out?
Cheers.