Mailchimp for WP add subscriber programmatically

i am trying to add an user to a MailChimp list programmatically (so he is a subscriber of any emails i will send).
I do have the pro-version of the MailChimp for WordPress plugin.

Is there a way to add – and remove a user (Email and three fields) to a list dynamically?
There seems to be an API (http://developer.mc4wp.com/), but i did not found a function to do so.

Read More

Is there one?

Related posts

2 comments

  1. Use the mc4wp_get_api function to grab an instance of the MailChimp for WordPress API. Then call the subscribe() function add an email to a list:

    $list_id = "2341ca4321";
    $email = "subscriber@email.com";
    $api = mc4wp_get_api();
    $api->subscribe($list_id, $email);
    
    • The subscribe() function returns a boolean. This return value simply reports if the subscribe request succeeded. Will return false if the user is already on the list
    • $list_id can be found when logged into MailChimp, looking under a list, Settings > List name and campaign defaults > List ID
  2. include('/MailChimp.php');
    $MailChimp = new DrewMMailChimpMailChimp("API-KEY");
    $result = $MailChimp->get('lists');
    $list_id = 'a0123a45f';  //  List Key
    $result = $MailChimp->post("lists/$list_id/members", [
                    'email_address' => test@test.com,
                    'status'        => 'subscribed',
                    'merge_fields' => array('FNAME'=>'test', 'LNAME'=>'tester'),
                ]);
    

Comments are closed.