Support

Home Forums Event Espresso Premium Send Ticket Selection to Mailchimp

Send Ticket Selection to Mailchimp

Posted: March 25, 2020 at 6:22 pm


John Lynn

March 25, 2020 at 6:22 pm

I saw this code you can send the ticket date to Mailchimp: https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-mailchimp/tw_eea_mailchimp_start_date.php

Is there a way I can send what ticket type they selected to Mailchimp? Or if it’s easier, the amount of the ticket?

I’m on Event Espresso 4.10.2.p


Tony

  • Support Staff

March 26, 2020 at 4:04 am

Hi John,

Is there a way I can send what ticket type they selected to Mailchimp?

Yes, the filter allows you to add pretty much any details you want to it but we don’t have a snippet that does this already.

May I ask what you mean by ticket type? I’m assuming the ticket name?

Or if it’s easier, the amount of the ticket?

You can add both if needed.

Are you comfortable with PHP?


John Lynn

March 26, 2020 at 10:57 am

Hi Tony,
Great. I really just need any way that I can identify the ticket uniquely in Mailchimp so I can send a different welcome email based on the ticket selected. So, Ticket Name would be fine. Ticket Amount would work (since each ticket price is different in this case).

I’m pretty good with PHP. Happy to add a snippet if you can help out with it.


Tony

  • Support Staff

March 26, 2020 at 2:55 pm

The snippet would be very similar to the one you’ve linked to, only you’d use the EE_Ticket object rather than a EE_Datetime.

Create your mergee var on MialChimp, then these lines would be something like:

$ticket = $registration-> ticket();
if( $ticket instanceof EE_Ticket ) {
    //Do whatever you want with the ticket object here.
    $merge_vars['TICKETNAME'] = $ticket->name();
}

$ticket would be an instance of EE_Ticket above so you can use our model system to pull whatever details you needed:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System


John Lynn

March 26, 2020 at 4:27 pm

Worked like a charm. I created the “TICKETNAME” merge field in Mailchimp. Then I added this code to my functions.php and it passed the ticket name just right.

function tw_eea_mailchimp_start_date( $subscribe_args, $registration, $EVT_ID ) {

	//Check we have a valid EE Registration
	if( $registration instanceof EE_Registration ) {
		
		//Pull the merge_vars array from $subscribe_args.
		$merge_vars = $subscribe_args['merge_vars'];

		$ticket = $registration-> ticket();
		
		if( $ticket instanceof EE_Ticket ) {
			//Do whatever you want with the ticket object here.
			$merge_vars['TICKETNAME'] = $ticket->name();
		}

		//Add the merge vars back into the subscriptions args.
		$subscribe_args['merge_vars'] = $merge_vars;

	}
	
	return $subscribe_args;

}
add_filter('FHEE__EE_MCI_Controller__mci_submit_to_mailchimp__subscribe_args', 'tw_eea_mailchimp_start_date', 10, 3);

In case I want to do price later, can you let me know what the code would be for it? I just need this piece: $merge_vars[‘TICKETPRICE’] = $ticket->price(); Is that right?


Tony

  • Support Staff

March 27, 2020 at 3:38 am

I just need this piece: $merge_vars[‘TICKETPRICE’] = $ticket->price(); Is that right?

Correct.

If you use something like kint debugger and wrap the object in d(); you’ll be able to see all of the available methods on that object.


John Lynn

March 27, 2020 at 12:53 pm

Thanks. I’ll have my development team dive into it once we turn the Mailchimp email into a full receipt. I appreciate you helping me with the immediate need though. I love that I could guess it though 🙂


John Lynn

March 27, 2020 at 1:00 pm

And just for good measure. Here’s the final code I used to push the ticket name and price to Mailchimp:

/* Event Send TicketName to Mailchimp */
function tw_eea_mailchimp_start_date( $subscribe_args, $registration, $EVT_ID ) {

	//Check we have a valid EE Registration
	if( $registration instanceof EE_Registration ) {
		
		//Pull the merge_vars array from $subscribe_args.
		$merge_vars = $subscribe_args['merge_vars'];

		$ticket = $registration-> ticket();
		
		if( $ticket instanceof EE_Ticket ) {
			//Do whatever you want with the ticket object here.
			$merge_vars['TICKETNAME'] = $ticket->name();
			$merge_vars['TICKETPRIC'] = $ticket->price();
		}

		//Add the merge vars back into the subscriptions args.
		$subscribe_args['merge_vars'] = $merge_vars;

	}
	
	return $subscribe_args;

}
add_filter('FHEE__EE_MCI_Controller__mci_submit_to_mailchimp__subscribe_args', 'tw_eea_mailchimp_start_date', 10, 3);

This requires MERGE tags to be created for your list in Mailchimp as follows: TICKETNAME and TICKETPRIC

Note: I had to to TICKETPRIC since there’s a limit on length of a MERGE Tag in Mailchimp.

Works like a charm. Thanks!


Tony

  • Support Staff

March 27, 2020 at 2:20 pm

Great, I’m glad you have a working snippet.

Just a side note, we use TKT as shorthand for ticket, so you could use TKTNAME and TKTPRICE to have consistent naming if preferred.

The support post ‘Send Ticket Selection to Mailchimp’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3 Documentation for Event Espresso 4

Status: closed

Updated by  Tony 3 months, 2 weeks ago ago

Topic Tags

Tagged: 

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!