Support

Home Forums Event Espresso Premium URGENT: Getting primary registrant email from within custom shortcode Reply To: URGENT: Getting primary registrant email from within custom shortcode

Reply To: URGENT: Getting primary registrant email from within custom shortcode

Author Replies
Tony # Posted on April 26, 2018 at 4:03 am

Ok, you need something like this:

https://gist.github.com/Pebblo/dc950fde4e8bfd5a70c6d6fc5e2ac9c7

$extra_data is now formatted differently from when I first created that gist so it’ll need updating, the reason that’s not causing issues for other users is $data should now always be an instanceof EE_event for event based shortcodes, meaning the code that uses extra_data in that example is not used. Your trying to pull registration/attendee based info from the event shortcodes so it needs the data from extra_data (technically this is the ‘correct’ way to do this as event shortcodes should be solely on the event itself, this is not, but that’s up to you).

The way I would have done this is to add the shortcode to either the EE_Primary_Registration_Details_Shortcodes or EE_Recipient_Details_Shortcodes, both of which have the EE_Registration object passed to them which can be used to pull the primary registrant (or just check if the current registration is the primary) and the event, but that’s something for you to dig into if you wish.

Also be careful with your conditionals, in the code you linked to:

$event = $extra_data instanceof EE_Event ? $data : null;

Check if $extra_data is an EE_Event, then if it is, assign $data (which has nothing to do with what we just checked for) to $event? You want to be checking what $data is, not $extra_data.

Similar problem here:

$aee = $extra_data instanceof EE_Messages_Addressee ? $data : NULL;

If $extra_data is an EE_Messages_Address object, set $data (which is likely an EE_Event) to $eea?

But anyway, the Gist I linked to above will return the primary_att_email, a quick example:

Shortcode: http://take.ms/UugKN
Parsed: http://take.ms/xoWJN

Do NOT follow this link or you will be banned from the site!