Hi,

I am looking for a way to hide the mailchimp subscribe block to registers users who have already subscribe to the list.

Is there a way?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ndewhurst’s picture

Version: 7.x-3.1 » 7.x-3.x-dev
Status: Active » Needs review
FileSize
7.48 KB

I wrote the attached code to help achieve this. It adds an option to each signup form so that (if the form is rendered in block mode) the block can be hidden from users who have subscribed to all lists associated with the form. It would be easy to add an alternate option like "hide block if user has signed up for any of the lists on this form.
What makes it somewhat tricky is that user signup can be managed via the fields provided by the mailchimp_lists module. I wrote a helper function to process any such fields so that we use the appropriate user email address for our query. For example:

  • There's a "Mailchimp Subscription" field called "field_list_a_signup" attached to users and linked to "List A." For that field, the email merge field is mapped to the standard user mail property.
  • There's a signup form associated with List A and rendered in block mode, with the "Hide block if current user has already subscribed to all lists" setting enabled.
  • There's a user, "Bob" whose primary email is "bob@bob.com," and who has a second email address ("bob2@othersite.com") stored in "field_email_2."
  • "bob@bob.com" is subscribed to List A
  • When logged in, Bob will not see the form block.
  • However, if the email merge field for field_list_a_signup were mapped to field_email_2, Bob would see the block, because his secondary email is not subscribed to List A.
  • If the signup form included a second list ("List B") for which there was no user subscription field, the system would check to see if bob@bob.com was subscribed to List B.

I've tested this with multi-list forms, various combinations of subscription fields and subscription states, etc. Hopefully someone else can test it and give some feedback.

ndewhurst’s picture

Category: Support request » Feature request
Colin @ PCMarket’s picture

Thank you for making this patch

I managed to apply the patch but after doing so I don't seem have the option to hide the block for subscribed users in the sign up forms admin.

hosais’s picture

Hi,
I need this function too. Hope this will work soon.

ruscoe’s picture

Status: Needs review » Closed (won't fix)

Thank you for your work on this, @ndewhurst. Unfortunately we're going to be ending support for the 7.x-3.x branch due to the upcoming deprecation of the v2.0 MailChimp API. If you're still interested in adding this, please feel free to reopen for the 7.x-4.x branch.