5iveleaf Posted October 12, 2016 Share Posted October 12, 2016 I've got this working as a standalone PHP file, but for some reason when I set it up as a custom hook in WHMCS, it no longer works. Here is the content of my hook_mailchimp_unsubscribe.php file which I've placed in /includes/hooks. I thought perhaps it didn't like the email variable, but I've tried hard-coding this with a known email addresses as well which also didn't work. Any ideas what I might be doing wrong here? X's are obviously for obfuscation of actual MailChimp account information. add_hook('AfterShoppingCartCheckout', 1, function ($vars) { // email variable from WHMCS //$email = $vars['clientdetails']['email']; // Mailchimp call to unsubscribe user based on email $user = 'XXXXXXX'; $apiKey = 'XXXXXXX-us12'; $auth = base64_encode( 'user:' . $apiKey); $listId = 'XXXXXXXXXX'; $memberId = md5(strtolower($email)); $dataCenter = substr($apiKey,strpos($apiKey,'-')+1); $url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' .$memberId; $json = json_encode( array( 'status' => 'unsubscribed' // "subscribed","unsubscribed","cleaned","pending" ) ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/3.0'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Authorization: Basic '.$auth)); $result = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return $httpCode; }); - - - Updated - - - Oh, and in my actual code the $email = $vars['clientdetails']['email']; is not commented out. - - - Updated - - - I've also tried setting the priority to 2 in case there was a conflict of hooks. No dice there either. 0 Quote Link to comment Share on other sites More sharing options...
5iveleaf Posted October 12, 2016 Author Share Posted October 12, 2016 Also tried using the ClientAdd hook instead of AfterShoppingCartCheckout along with $email = $vars['email']; Still not working. Is there an issue with running JSON calls within custom hooks? I should probably also mention we're running v 5.3.14 (I know, ancient). 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.