Search code examples
phpdrupal-7drupal-modulesnewsletterunsubscribe

Unsubscribe users from a general category if they unsubscribe from another category at Simplenews


I send newsletters from my Drupal-7 website using Simplenews module. I have a general category, that has all my site users and it is the category I use the most.
Although, some of the newsletters are sent to a smaller target group (women-only, men-only etc).
My problem is that when users click on the unsubscribe link from a newsletter that is not from my general category, then they unsubscribe from this category only and not the general.
What I want to achieve, is that when a user is unsubscribed from any newsletter category, to automatically unsubscribe him from the general category also.
Until now, I know I have to use hook_simplenews_unsubcribe_user and I have come up with the following code:

<?php


function unsubscribe_from_general_category_simplenews_unsubscribe_user($subscriber, $subscription) {
   simplenews_unsubscribe_user($mail, '106', FALSE , 'website');//$tid -s your genral category tid.
}  

but it doesn't seem to be working. My general category's tid is 106.
Any suggestions?


Solution

  • try it with

    simplenews_unsubscribe_user($mail, 106, FALSE , 'website');