Chris Gerard
Chris Gerard

Reputation: 1

Mailchimp API 2.0 using listSubscribe() multipe times

I'm making an integration of Shopp and Mailchimp for a client on a WordPress-based site. The checkout page has input for multiple email addresses, all of which should be added to MailChimp via the API. I've had success with listSubscribe() using the MCAPI.php wrapper in getting the first email to work. Can the listSubscribe() be re-used in the same PHP function that runs as checkout is processed?

Here's the code I have at the moment:

/* include MailChimp API on checkout init */
add_action('shopp_order_success', 'opc_mc_checkout');
function opc_mc_checkout () {
// do stuff
require_once 'MCAPI.class.php';
$apikey='redacted'; // Enter your API key
$api = new MCAPI($apikey);
$retval = $api->lists();
$listid='redacted'; // Enter list Id here
$email=shopp('purchase.email', 'return=true'); // Enter subscriber email address
$name=shopp('purchase.firstname', 'return=true'); // Enter subscriber first name
$lname=shopp('purchase.lastname', 'return=true'); // Enter subscriber last name

// By default this sends a confirmation email - you will not see new members
// until the link contained in it is clicked!

$merge_vars = array('FNAME' => $name, 'LNAME' => $lname);
if($api->listSubscribe($listid, $email,$merge_vars) === true) {
}

/* teacher extra emails */
$apikey='redacted'; // Enter your API key
$api = new MCAPI($apikey);
$retval = $api->lists();
$listid='redacted';  // Enter list Id here
$teacher_1_email=shopp('purchase.data', 'name=Teacher 1 Email&return=true'); // Enter subscriber email //$teacher_1_email=$_POST['Teacher 1 Email']; // Enter subscriber email 
$teacher_1_name=shopp('purchase.firstname', 'return=true'); // Enter subscriber first name
$teacher_1_lname=shopp('purchase.lastname', 'return=true'); // Enter subscriber last name


$merge_vars = array('FNAME' => $teacher_1_name, 'LNAME' => $teacher_1_lname);
if($api->listSubscribe($listid, $teacher_1_email,$merge_vars) === true) {
}

I've searched Google and the API documentation up and down without luck. Ay help would be greatly appreciated!

Thanks!

Upvotes: 0

Views: 103

Answers (0)

Related Questions