Jump to content

Extended Mailchimp hook


milstanyu

Recommended Posts

Hello,

 

I would like to customize the existing mailchimpsubscribe.php hook and to add support for 2 mailing lists. So, when product #1 is purchased, user to be subscribed to the list #1, and when product #2 is purchased, user to be subscribed to the list #2.

 

Original script is this:

 

<?php

function hook_mail_chimp_subscribe($vars) {

// ******MailChimp API and List ID******
// Replace XXXX with your API key retrieved from http://admin.mailchimp.com/account/api/
$api_key = "APIKEY";
// Replace XXXX with your list Unique ID obtained by going to http://admin.mailchimp.com/lists/ and clicking on the Settings link for the list. Unique ID found a the bottom of the page
$list_id = "LISTID";

// ******Additional Settings******
// Replace with your datacenter. Retrieved from dashboard URL eg. - https://us2.admin.mailchimp.com/
$datacenter = "us1";
// Set to true if you would like the user to confirm their subscription before being added to your list
$doubleoptin = "false";
// Don't bother changing this unless you really, really....REALLY have to!
$output = "php";

// ******New subscriber information******
$first_name = str_replace(" ", "%20", $vars['firstname']);
$last_name = str_replace(" ", "%20", $vars['lastname']);
   $email = $vars['email'];

   $url = "http://$datacenter.api.mailchimp.com/1.3/?output=$output&method=listSubscribe&apikey=$api_key&id=$list_id&email_address=$email&merge_vars[FNAME]=$first_name&merge_vars[LNAME]=$last_name&double_optin=$doubleoptin";
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   $retval = curl_exec($ch);
   curl_close($ch);

   logActivity("Debugging: MailChimp Hook - URL: $url - Response: ".htmlentities($retval));

}

add_hook("ClientAdd",1,"hook_mail_chimp_subscribe");

?>

 

I don't know how to access the purchased product ID. I tried to add this:

 

$pid =  $vars['params']['packageid'];

if($pid==1) {
	$list_id = "LIST1ID";
	$api_key = "API1KEY";
	$datacenter = "us9";
}else{
	$list_id = "LIST2ID";
	$api_key = "API2KEY";
	$datacenter = "us1";
}

 

But it doesn't seems to work. How do I get "packageid" in the ClientAdd hook?

 

Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated