Thread Starter
Matt
(@mugwumpman)
I don’t think I’m doing it right, and it’s not synchronising yet, but here’s what I’ve got so far…
Variables:
- $user_id
- $first_name
- $last_name
- $user_email
- $list_id
Code:
$api = mc4wp_get_api();
$data['FNAME'] = $first_name;
$data['LNAME'] = $last_name;
$data['NAME'] = sprintf( '%s %s', $first_name, $last_name );
$data['EMAIL'] = $user_email;
$merge_vars = $data;
$success = $api->update_subscriber( $list_id, array( 'leid' => $user_id ), $merge_vars );
Is this for importing to wordpress from mailchimp? I’m also trying to figure this out but also need it to import to buddypress. I’m not sure if this will be useful to you at all, it’s how I sync the buddypress fields with the mailchimp fields
//Add buddypress xprofile field to MailChimp Sync
//Call the function
add_filter( 'mailchimp_sync_user_data', 'mailchimp_buddypress', 10, 2 );
//Write the function
function mailchimp_buddypress( $data, $user ) {
//Get user ID
$user_id = $user->ID;
// Store Xprofile fields in the $data variable
$data['STREET'] = xprofile_get_field_data( 13 , $user_id );
$data['STREET2'] = xprofile_get_field_data( 14 , $user_id );
$data['CITY'] = xprofile_get_field_data( 7 , $user_id );
$data['STATE'] = xprofile_get_field_data( 14 , $user_id );
$data['ZIP'] = xprofile_get_field_data( 9 , $user_id );
$data['PHONE1'] = xprofile_get_field_data( 16 , $user_id );
$data['PHONE2'] = xprofile_get_field_data( 17 , $user_id );
$data['COUNTRY'] = xprofile_get_field_data( 28 , $user_id );
//$data['FINSHLINE'] = xprofile_get_field_data( 20 , $user_id );
$data['EMPLOYER'] = xprofile_get_field_data( 3 , $user_id );
$data['INDUSTRY'] = xprofile_get_field_data( 4 , $user_id );
$data['JOBTITLE'] = xprofile_get_field_data( 5 , $user_id );
$data['MAJOR'] = xprofile_get_field_data( 6 , $user_id );
$data['YEARSROWED'] = xprofile_get_field_data( 10 , $user_id );
$data['YEARROWED'] = xprofile_get_field_data( 11 , $user_id );
$data['COACH'] = xprofile_get_field_data( 18 , $user_id );
$data['ADVDEG'] = xprofile_get_field_data( 19 , $user_id );
//Return the data
return $data;
}
Thread Starter
Matt
(@mugwumpman)
No, I’m looking for how to trigger an individual WordPress user to have their details exported to MailChimp for synchronising.
Thread Starter
Matt
(@mugwumpman)
I’ve since found that do_action( 'mailchimp_sync_update_subscriber', $id ); should do this, but that isn’t working either.
Hi Matt,
It should indeed be the following:
do_action( 'mailchimp_sync_update_subscriber', 5 );
In this example, 5 is the ID of your user.
Please note that this will only work if you have configured the plugin on the settings page, a MailChimp list should be chosen at a minimum.
Also this will only work if called after the plugins_loaded hook has run. So if you’re calling this from another plugin, you need to schedule the function call on a later hook. Something like this, for example:
add_action( 'init', function() {
do_action( 'mailchimp_sync_update_subscriber', 5 );
});
Hope that helps. If not, let me know!