Mailchimp add-on: trigger an automation inside mailchimp

In addition to sending FNAME, LNAME and EMAIL, I want to send a MMERGE=X. That way I can trigger an automation inside mailchimp, because they get tagged when they are added to the list.

How can I do this in the Mailchimp add-on from Membership 2 Pro?

  • Katya Tsihotska
    • Support & QA

    Hi stripedrhino

    Hope you’re having a great day!

    Since this is dealing with more advanced coding topics, we’ve pinged our SLS Team (code experts) to get their valuable feedback on this. One of our SLS members will reply back here as soon as more information is available.

    Please keep in mind that our SLS Team deals with more complicated issues, thus it may take a little longer for them to reply here. Thank you for your patience while we look into this further.

    Kind regards,


  • Konstantinos Xenos
    • Rubber Duck Debugger

    Hey stripedrhino ,

    You can edit your themes functions.php ( preferably your child themes ) via FTP or Appearance -> Editor, or your servers file manager and add the following filter.

    What you can do with this basically is pass into $merge_vars as many extra fields as you like. As an example from what you mentioned in the OP this code will simply add MMERGE=X by writing and send it over to MailChimp along with the default variables. I'm also adding a screenshot from my tests, this was tested by automatically subscribing users when registering via Membership 2 Pro.

    Tell me if this works for you!

    function sr_mailchimp_trigger( $merge_vars ) {

    $merge_vars['MMERGE'] = 'X';
    return $merge_vars;

    add_filter( 'ms_addon_mailchimp_subscribe_user_merge_vars', 'sr_mailchimp_trigger' );



  • stripedrhino
    • Site Builder, Child of Zeus

    Hello Konstantinos,

    Thank you for your help with this. Does the code you provided allow me to attach the variable to a registration of a particular membership? I will have many different memberships on this site, and the idea is to pass a merge code to their “membership” field based on what they register for.

    So, for membership 1 I might want to pass “class1” and membership 2 might be “class2”.

    Thanks again.

  • Konstantinos Xenos
    • Rubber Duck Debugger

    Hey stripedrhino !

    Could you give me some more information on your setup as well? Usually more memberships mean different lists as well so there might be 2-3 different options here so I can see and come up with a code that it would be easy for you to extend as well if needed.

    For example if you have different lists we could easily just read the list ID and change the merge variable that you like instead of the membership ( that could be more easily identifiable by you for example ).

    If you can provide a thorough example of your set up so I can replicate your settings I’ll check what would work best for you.



  • stripedrhino
    • Site Builder, Child of Zeus

    Hello Konstantinos Xenos,

    Actually, we have one master list in MailChimp that has many hidden fields. We also have different groups on the single list. MailChimp makes it easy to autofill a hidden text field (or two) in an embedded form. Alternatively, certain wp plugins we are using may allow us to put the user into a specific group on the list.

    Idk how familiar you are with MailChimp, but text fields, lists and groups are different in that I can “tag” a user with information in a text field and they might not know it, but they always have the option to update their profile and adjust what list they may be on, or the groups on that list.

    This strategy allows us to keep our list from having duplicate emails (keeping costs down), and also run a lot of automation.

    Our hope is that we can allow a change of MS2P membership status to be passing predefined variables to a MailChimp hidden text field on our list. Because MailChimp allows segmentation on a list to be continuously updated, the member’s change of status would trigger the different series of emails that are in place for their appropriate status.

    I will use exactly what we want to accomplish as the example.

    We have one MailChimp list. It has hidden fields. We have a website using MS2P that has X number of memberships. A user joins memberships 1, 2, 3 or 4, which are allowing them access to video content that is protected by MS2P shortcodes on public wp posts.

    During the registration process, and depending on which membership, we want to pass different variables into a hidden text field. The variables would be as follows:

    Membership 1 = FREE

    Membership 2 = PAID

    Membership 3 = TRIAL

    Membership 4 = VIP

    If they unsubscribe from any of these four memberships, I want to replace the variable in this hiddent text field with UNSUBSCRIBED.

    The other memberships would have their own appropriate variables.

    I don’t really know enough about how MS2P works to understand if they are considered unsubscribed from a membership if a credit card fails to process or something like that, but I think it would be OK to make MailChimp the slave to the user’s MS2P membership status.

    Right now we’re manually updating the information on the users MailChimp profile based on their MS2P status. I’d love to automate it.

    Thanks for taking the time to process this.

  • Konstantinos Xenos
    • Rubber Duck Debugger

    Hey stripedrhino ,

    Based on the last filter I gave you, you could try this:

    add_filter( 'ms_addon_mailchimp_subscribe_user_merge_vars', function( $merge_vars, $member, $list_id ) {

    $membership_id = null;

    if ( isset( $_REQUEST['membership_id'] ) ) {
    $membership_id = intval( $_REQUEST['membership_id'] );
    if ( 11 == $membership_id ) {
    $merge_vars['MMERGE'] = 'FREE';
    } elseif ( 24 == $membership_id ) {
    $merge_vars['MMERGE'] = 'TRIAL';
    } elseif ( 25 == $membership_id ) {
    $merge_vars['MMERGE'] = 'PAID';
    } elseif ( 26 == $membership_id ) {
    $merge_vars['MMERGE'] = 'VIP';
    } else {
    $merge_vars['MMERGE'] = 'NO_ID';
    } else {
    $merge_vars['MMERGE'] = 'UNSUBSCRIBED';

    return $merge_vars;

    }, 10, 3 );

    You will have to replace the 11,24,25,26 with the corresponding IDs from your memberships ( you can easily find it by checking the URL when editing a membership, you’ll see a membership_id= value.

    There seems to be a hiccup on contacting MailChimp, I will inform our developers about my findings and try to check it out myself if possible in case I can find a quick workaround for you but for the time being this will only work for new Registrations, the updates on memberships or alterations ( moving between memberships etc ) will probably not be updating your list.

    I hope this helps a bit and I’ll keep you posted if I can make the updates happen as well.



  • stripedrhino
    • Site Builder, Child of Zeus

    Hello Konstantinos Xenos, thanks again for your help above. We have made some progress, but have another question for you.

    When a user is added to our MailChimp list, MailChimp allows you to default their signup form field to a certain status, for example, let’s say they’ve been added to our site but have not yet signed up for a membership. We could have it say “no membership” using MC functionality. Then, when the user registers for an MS2P membership, we have been able to pass a variable into MailChimp after making some modifications to the code you previously provided above.

    We are not sure, however, how to pass another variable into MailChimp when the user UNsubscribes from that same MS2P membership.

    Is there a hook or trigger that we can connect to via our child theme’s functions.php file that will recognize a membership status change? Or maybe, would we need to set up a cronjob to ping for status changes or something like that?

    We’re getting close!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.