How to Sync WordPress User Registrations to Mailchimp
In this tutorial I will show you two different ways how you can sync WordPress user registrations to Mailchimp. The first way is more for developers, we are going to create API requests, the second one – for regular users, so all you have to do is just to install the plugin.
Sync User Registrations with Mailchimp API
In this first method we are going to configure WordPress user registrations syncronization with some code. If a code solution is not what you’re looking for then I recommend you to skip to the second part of this tutorial.
user_register
Everything begins with this hook. Hook user_register
in WordPress will be fired in the following situations:
- When a user registers on the website.
- When administrators register a user via admin area Users > Add New.
- When user is registered via a function in the code, for example with
wp_insert_user()
orwp_create_user()
.
So everything begins with running user_register
hook somewhere on your website.
add_action( 'user_register', 'rudr_sync_wp_users_to_mailchimp', 10, 2 );
function rudr_sync_wp_users_to_mailchimp( $user_id, $userdata ) {
// do some Mailchimp API stuff
}
Please not that $userdata
parameter was added in WordPress 5.8, so if you’re using an earlier version of WordPress, you have to get user emails from ID with get_user_by()
function.
Interacting with Mailchimp API using WordPress HTTP API
Now, since we know where we run the requests to Mailchimp API, it is time to create them. There are a lot different ways how you can perform them, the most popular one over the internet is with cURL, but since we’re working with WordPress, I assume it would be a more correct and clean way to use WordPress functions for that, wouldn’t it?
I have a different tutorial, where I describe how to perform Mailchimp API requests using WordPress HTTP API functions, so if you want to learn a bit more about it, please check it.
And here is the complete code for our goal:
add_action( 'user_register', 'rudr_sync_wp_users_to_mailchimp', 10, 2 );
function rudr_sync_wp_users_to_mailchimp( $user_id, $userdata ) {
$list_id = 'YOUR AUDIENCE ID';
$api = 'YOUR API KEY';
$email = $userdata->user_email;
$response = wp_remote_request(
'https://' . substr($api,strpos($api,'-')+1) . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . md5(strtolower($email)),
array(
'method' => 'PUT',
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'user:'. $api )
),
'body' => json_encode(
array(
'email_address' => $email,
'status' => 'subscribed'
)
)
)
);
}
Believe or not, but this is our final code for your functions.php
of wherever you’re going to use it. Let me highlight a couple moments:
- You have to decide to what Mailchimp audience (list) you’re going to subscribe newly registered WordPress users, here is how to get an audience ID. In case you would like to subscribe your users to different lists depending on their user role on the website, then take a look at the plugin solution.
- You will also need a Mailchimp API key, here is how to get it.
- The last but not the least, if you respect the users privacy, probably you could change the status on line 19 from
subscribed
topending
, in this case users will get a confirmation email before they are going to be subscribed to a list.
Sync User Registrations with WordPress plugin
I hope the API solution seems clear and simple for you. In case it doesn’t or maybe you just need a little bit more customization, I recommend you an “install-and-use” solution, which means that all you have to do is to install my Simple Mailchimp Sync plugin for WordPress, all the work it will do for you.
Just check how cool its settings are:

So you can:
- Sync every WordPress user role to a different Mailchimp audience (yes, I have already mentioned it before).
- Add tags to every rule. In case your Mailchimp pricing plan doesn’t allow you to create more audiences, you can use the single audience and segment users by tags!
- Provide more user data to Mailchimp like first name, last name and whatever else.
- And of course it allows you to bulk re-sync all existing users on your WordPress website.

Misha Rudrastyh
Hey guys and welcome to my website. For more than 10 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Thanks for your code, it works great! However when a user is already registered to the website, there’a a way to update his data on mailchimp if they change their first name or last name from woocommerce my_account page or when they add more data like address and phone during the checkout?
Hi Tom,
Simple subscribe method works just great, for WordPress you can find a well described example here.
But in case you would like just update user, not add him, use
PATCH
method instead ofPUT
(that’s all you need to change).Thanks! works like a charme (as usual) :)
Just another question: you use this action
to hook the function and send data to Mailchimp when a user registered himself on the website.
I successfully hooked your function in my_account page to update Mailchimp when a user change their data using this action:
.
I supposed to do the same in the checkout page when a user confirm his purchase but unfortunately I can’t find any hook to perform this. Do you know have any ideas? Thanks a lot!
Tom
Did you try hooks like this
woocommerce_order_status_{order status}
?It works! Thanks!
Wow, thank you so much for this script !! Very helpful !
And what if I want to add or update tags ? I tried to add a $tags_array in the $data, but it doesn’t work, can you help me, please ?
Hi Nathalie,
Do you mean merge fields? or.. ?
Thanks for your reply !
I need to add tags to the subscribers’ profile and it seems you can’t add them in the merge fields or I don’t know how I have to do that. I tried to add an array “TAGS => array(“tag1″ => value1”, “tage2” => value 2 etc, but it returned null
Otherwise I could add interests but I also don’t know how…
(I’m talking about the tags you can add at the end of the form when you add a subscriber manually on MC website)
Did you try to use an array key
merge_fields
instead ofTAGS
?I already have a merge_fields array, to send the details of the subscriber, but I need to add an array tags too and I don’t know how to proceed. When I add the tags into the the merge_fields, I get an error
Did you try this?
Is it possible to sync users without First and Last name, as my form doesn’t have it?
Thanks!
Hey,
Yes, both first name and last name are optional
Hi Misha, thank you for this. It’s fabulous. Question. This seems to work when I subscribe someone via the WP admin, but when a user subscribes to the site (using BuddyBoss form, no user is subscribed to Mailchimp. It seems like it should work since once the user subscribes to the site, they are added as a subscriber in WP just as if I had added them directly. Any Advice?
Thanks so much.