Events Made Easy › Forums › How do I … › MailChimp Newsletter Subscription Option on RSVP form?
Tagged: MailChimp, Newsletter
- This topic has 13 replies, 2 voices, and was last updated 9 years, 7 months ago by Anonymous.
-
AuthorPosts
-
Fri 3 Apr 2015 at 11:40 #53933AnonymousInactive
Hi,
has anybody successfully added an option to subscribe to a newsletter via MailChimp along with a RSVP form?
I like to add a checkbox that would allow, while registering for an event, to subscribe to a newsletter via MailChimp.
Anybody done this already and can give some guidance where to start?
Many thanks and happy Eatser!
Cheers
JKSat 4 Apr 2015 at 00:03 #53937FrankyKeymasterUse the following action hook in EME for this: eme_insert_rsvp_action
and then call the mailchimp API (which I must admit: I do not know)Tue 7 Apr 2015 at 20:37 #54065AnonymousInactiveThank you Franky for the hint.
But again as I’m not a programmer I’m struggling to find a solution …
What I found is a description to the MailChimp API that shows a subscription call I think…
Tue 7 Apr 2015 at 23:37 #54068FrankyKeymasterI’m sorry, but while I do provide all means to do what you want here (with action hook examples), this is functionality not related to Events Made Easy, so you should hire an external party to do it for you if you can’t do this. You could hire me, but I’m charging by the hour for these things. Or you could try to ask mailchimp for the support.
Start from this (do it for a specific event_id or for all, and change MY_FIELD_NAME to the field you want to check.add_action('eme_insert_rsvp_action', 'my_eme_discount_function',20,1); function my_eme_discount_function($booking) { global $wpdb; $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME; $where = array(); $fields = array(); $booking_id = $booking['booking_id']; $event_id = $booking['event_id']; $event = eme_get_event($event_id); $person = eme_get_person($booking['person_id']); if ($event_id == 5) { /* put in the event_id that needs processing, or leave out this line to process all events */ $answers = eme_get_answers($booking_id); $my_answer = ""; foreach ($answers as $answer) { if ($answer['field_name'] == "MY_FIELD_NAME") { $my_answer = $answer['answer']; } } if ($my_answer == "my wanted text") { // do mailchimp thing here, based on the info in $booking, $event and/or $person } } return; }
Mon 20 Apr 2015 at 17:03 #54108AnonymousInactiveHello Franky,
I absolutely understand!
May I just ask two questions to not run into a death end please?
1) Am I on a good way with this?
add_action('eme_insert_rsvp_action', 'my_eme_mailchimpsubscription',20,1); /** * Custom function to subscribe to the newsletter */ function my_eme_mailchimpsubscription($booking) { global $wpdb; $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME; $event_id = $booking['event_id']; $booking_id = $booking['booking_id']; $answers = eme_get_answers($booking_id); $newsletter = ""; foreach ($answers as $answer) { if ($answer['field_name'] == "Newsletter") { $newsletter = $answer['answer']; } } if ($newsletter == "Subscribe") { //do subscription } return; }
2) Can I have multiple actions?
add_action(’eme_insert_rsvp_action’, ‘my_eme_coupons’,20,1);
add_action(’eme_insert_rsvp_action’, ‘my_eme_mailchimpsubscription’,20,1);Do I have to modify something?
Many thanks in advance.
Cheers
JKMon 20 Apr 2015 at 17:09 #54109FrankyKeymasterConcerning 1: yes, seems to be ok
Concerning 2: good question … according to what I find on the net, wordpress has no issues with this. Although you should use the priority option correctly to define which one to run first.
Or: do everything in the same action hook, and call other functions from there (seems cleaner to me).
Edit: see also http://wordpress.stackexchange.com/questions/6688/how-many-times-can-i-hook-into-the-same-action (the last answer)Wed 22 Apr 2015 at 08:29 #54110AnonymousInactiveHi Franky,
I’m sorry just another question…
$person = eme_get_person($booking['person_id']);
How do I get the Firstname, Lastname and Emailaddress out of $person into a variable?
Many thanks for any direction.
Cheers
JKWed 22 Apr 2015 at 09:16 #54111AnonymousInactiveI was trying to do this:
$person = eme_get_person($booking['person_id']); $subscribeemail = $person.email; $subscribelname = $person.lastname; $subscribefname = $person.firstname;
Wed 22 Apr 2015 at 09:35 #54112AnonymousInactiveBut I think it has to be:
$person = eme_get_person($booking['person_id']); $subscribeemail = $person['email']; $subscribelname = $person['lastname']; $subscribefname = $person['firstname'];
Wed 22 Apr 2015 at 11:47 #54113FrankyKeymasterIndeed, $person is a plain php array.
Wed 22 Apr 2015 at 11:54 #54114AnonymousInactiveCool 😀
I now have installed a small api wrapper (https://github.com/drewm/mailchimp-api/) for MailChimp.
And adjusted my code and decided to do as you said adding all into a single action…
/** * Add a hook for the Events Made Easy system to allow for coupon codes */ add_action('eme_insert_rsvp_action', 'my_eme_custom_stuff',20,1); /** * Custom function to calculate coupon code discounts for events */ function my_eme_custom_stuff($booking) { include('/myurl/wp-content/uploads/MailChimp.php'); global $wpdb; $bookings_table = $wpdb->prefix.BOOKINGS_TBNAME; $discount = 10; $dealprice = 89; $where = array(); $fields = array(); // Grab the coupon code from the extra answers $event_id = $booking['event_id']; $booking_id = $booking['booking_id']; $person = eme_get_person($booking['person_id']); $answers = eme_get_answers($booking_id); $newsletter = ""; $coupon = ""; foreach ($answers as $answer) { if ($answer['field_name'] == "Coupon") { $coupon = $answer['answer']; } else if ($answer['field_name'] == "Newsletter") { $newsletter = $answer['answer']; } } // As long as the coupon code isn't empty, look for matches // make the coupon code CAPITALS $coupon = strtoupper($coupon); if ($coupon == "COUNPON10") { // If coupon code used, apply the appropriate price change $price = $booking['booking_price'] - ( $booking['booking_price'] * ($discount / 100)); $fields['booking_price'] = $price; $where['booking_id'] = $booking['booking_id']; $wpdb->update($bookings_table, $fields, $where); } else if ($coupon == "NEWSLETTER2015" || $coupon == "CAMPAIN2015") { // If coupon code used, apply the appropriate price change $price = $dealprice; $fields['booking_price'] = $price; $where['booking_id'] = $booking['booking_id']; $wpdb->update($bookings_table, $fields, $where); } // Subscription to MailChimp if ($newsletter == "Ich möchte den Sensorgrafie Newsletter erhalten.") { $MailChimp = new \Drewm\MailChimp('MYAPIREF-us10'); // Grab if subscription is asked from the extra answers $result = $MailChimp->call('lists/subscribe', array( 'id' => 'MYLISTID', 'email' => array('email'=> $person['email']), 'merge_vars' => array('FNAME'=> $person['firstname'], 'LNAME'=> $person['lastname']), 'double_optin' => false, 'update_existing' => true, 'replace_interests' => false, 'send_welcome' => true, )); } return; }
Just to contribute if anybody likes to add the service as well 😉
Wed 22 Apr 2015 at 12:09 #54115FrankyKeymasterThanks for this mailchimp API example!
Small question: is that really the content of your field: “Ich möchte den Sensorgrafie Newsletter erhalten.” ? Maybe just a checkbox with values 0/1 would be easier to check 🙂Wed 22 Apr 2015 at 12:38 #54116AnonymousInactiveYes, it is, just forgot to delete this in the example…
Wed 22 Apr 2015 at 12:42 #54117AnonymousInactiveI use the field value to be displayed at my form that why the response is also so long. Maybe I just don’t know how to do it better or different 🙂
-
AuthorPosts
- The forum ‘How do I …’ is closed to new topics and replies.