Sync Mailchimp Audience Members Updates to WordPress

In this tutorial I am going to show how you can sync any member preferences updates in Mailchimp audiences to WordPress users.

Sometimes I’m getting asked to add this functionality to my Simple Mailchimp Sync plugin, but every time I’m starting writing the code, I always come to a conclusion that the plugin will become “not simple” at all. So now it is possible only with a free add-on (or you can use code examples below for sure). Everything we need is just a little bit of configuration in Mailchimp account and a small code snippet.

Create a Mailchimp Webhook

Before creating any Mailchimp webhooks you have to know that every webhook relates to a specific Mailchimp audience. So if you’re going to sync multiple Mailchimp audiences to WordPress, you will need multiple webhooks.


Open an audience you need to configure a webhook for and then go Settings > Webhooks.

Mailchimp webhook settings

Then click the “Add new webhook” button and on a newly opened page select the following:

Creating a new webhook in Mailchimp

On the screenshot above:

  • We’ve checked only “Profile updates” because in terms of this tutorial we are about to update user’s last name or something when it has been updated in the audience directly.
  • Also let’s skip changes made via API, so it will not interfere with Simple Mailchimp Sync plugin in case you’re using it on your website.
  • And the last but not the least, please pay attention to ?secret_key=secret_value part in the webhook callback URL, you have to replace both parameters with some random values and don’t store them publicly. For example ?mishawhook=jhcj89fjocksd123.

Using Mailchimp API

In case you decided to create some kind of an add-on which does that automatically (or you can take a look at my add-on), you can use the code below to create webhooks. And yes, this code is using WordPress HTTP API.

$api_key = '';
$audience_id = '';

	'https://' . substr($api_key,strpos($api_key,'-')+1) . '' . $audience_id . '/webhooks/', 
		'headers' => array(
			'Authorization' => 'Basic ' . base64_encode( 'user:'. $api_key )
		'body' => json_encode(
				'url' => '',
				'events' => array(
					'profile' => true,
				'sources' => array(
					'user' => true,
					'admin' => true,

This piece of code should run only once and it will create exactly the same webhook we created manually before.

Process the Webhook on the Website

Here is just a simple code snippet that can go to your theme functions.php file or something.

add_action( 'template_redirect', function(){

	// exit the function in case it is not our hook
	if( empty( $_GET[ 'secret_key' ] ) || 'secret_value' !== $_GET[ 'secret_key' ] ) {

	// check the action (it is totally optional in this example)
	if( empty( $_POST[ 'type' ] ) || 'profile' !== $_POST[ 'type' ] ) {

	// we can also check the list ID to improve the security of the webhook
	if( 'abcdef12345' !== $_POST[ 'data' ][ 'list_id' ] ) {

	// do the thing
	$user = get_user_by( 'email', $_POST[ 'data' ][ 'email' ] );
	if( $user ) {

		update_user_meta( $user->ID, 'last_name', sanitize_text_field( $_POST[ 'data' ][ 'merges' ][ 'LNAME' ] ) );

} );
Misha Rudrastyh

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

Follow me on X