Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Batch list user payment to Mailchimp
- $request_body_parameters = new stdClass();
- $request_body_parameters->operations = array();
- foreach ($sendEmail as $this_email) {
- json_encode($this_email);
- $email = $this_email['email'];
- $first = $this_email['firstName'];
- $last = $this_email['lastName'];
- $o = new stdClass();
- $o->method = 'PUT';
- $o->path = 'lists/' . MAILCHIMP_LIST_FESTIVAL_HK . '/members/' . md5(strtolower($email));
- $o->body = json_encode(array(
- 'email_address' => $email,
- 'status' => 'subscribed',
- "merge_fields" => [
- 'FNAME' => $first,
- 'LNAME' => $last
- ]
- ));
- $request_body_parameters->operations[] = $o;
- }
- $response = wp_remote_post('https://' . substr(MAILCHIMP_APIKEY, strpos(MAILCHIMP_APIKEY, '-') + 1) . '.api.mailchimp.com/3.0/batches', array(
- 'method' => 'POST',
- 'headers' => array(
- 'Authorization' => 'Basic ' . base64_encode('user:' . MAILCHIMP_APIKEY)
- ),
- 'body' => json_encode($request_body_parameters)
- ));
- if (wp_remote_retrieve_response_message($response) == 'OK') {
- $response_body_parameters = json_decode(wp_remote_retrieve_body($response));
- }
- //you can remove foreach
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement