Support

Home Forums Event Espresso Premium EE4 – Create Shortcode to insert it on Email template – With ACF Pro

EE4 – Create Shortcode to insert it on Email template – With ACF Pro

Posted: February 8, 2016 at 9:35 am


JacquesMivi

February 8, 2016 at 9:35 am

Hello,

I have ACF Pro field on events to regsiter specific email for each event.
I wish create a shotcode to get this email, and use it in custom message/mail. In ACF I can use

$email = get_field( "email_event_field", "id-event" );

How can I declare it as a shortcode usable in EE4 custom email ?
Thanks a lot,

How can I c
Is-it possible to create


Tony

  • Support Staff

February 8, 2016 at 9:41 am

Hi there,

Take a look here:

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

That gist outlines how you can add custom shortcodes to the EE4 Messages system.

Your shortcode would be an Event based shortcode, so it would be registered in the same way as [TONYS_EVENT_SHORTCODE] and then parsed further down within the EE_Event_Shortcodes.

Does that help?


JacquesMivi

February 8, 2016 at 12:01 pm

It seems to be the good direction. For the moment I got some bugs just to diplay it. I have creat and activate the plugin. But any new shortcode appears on my email template.
When I manually add rhe shortcode I got this error :

The following shortcodes were found in the "Main Content" field that ARE not valid: [TONYS_EVENT_SHORTCODE]

Have you an idea ?


JacquesMivi

February 8, 2016 at 12:11 pm

Well, it is available in all message shorcods but I can’t use it on email. I’m keep looking.


JacquesMivi

February 8, 2016 at 12:18 pm

I can use it on [EVENT_LIST] part of an email.
But I can’t use it on part “To” of the email. It seems to have a validation before saving the template.


Tony

  • Support Staff

February 9, 2016 at 2:05 pm

Event Espresso already allows you to use specific email addresses for each event by setting the author of the event to the users account and using the [EVENT_AUTHOR_EMAIL]

Event based emails are not available within the TO and FROM sections (as you’ve found above) and those sections are trickier than the others as the data passed to the shortcodes can be for multiple events.

So the you’ll need to loop through and build the correct data you need. Take a look at how the EE_Email_Shortcodes are parsed within the core code and you’ll see something similar with the EVENT_AUTHOR_EMAIL shortcode with how its parsed for the events passed to the shortcode parser for EE_Email_Shortcodes.

EE_Email_Shortcodes is passed the EE_Messages_incoming_data object, take a look at that class within core and you’ll see the properties available for the class.

You’ll want to pull in all of the event ID’s from the EE_Messages_incoming_data object, loop through each event and pull in the meta value using that events ID. Then return a comma-delimited string of email address for the message to use.

Can you not set the Event Author for the event to the user that created the event and then just use the default [EVENT_AUTHOR_EMAIL] shortcode within the messages?


JacquesMivi

February 10, 2016 at 8:57 am

Thanks for your answer. I will try to investigate.

We need another email per event for two reasons.
* Some organizers are just intermediaries for trainers. These trainers are involved in the management of tickets and have to receive notifications.
* To lauch the project we create events for organizers who do not have accounts. So we need to add their email to show that people book directly from our website.

If I understand, you think its to tricky to add custom email from event within the TO message ?


Tony

  • Support Staff

February 11, 2016 at 3:10 am

One way to achieve this is to create custom message templates, assign the email address you wish for the emails to be sent to to those custom templates and select the template within the event.

If I understand, you think its to tricky to add custom email from event within the TO message ?

Tricky in the sense that you don’t know the exact event, or how many events will be passed to the shortcode parser, which means you can’t just do something like this:

$event_email = get_field( "email_event_field", $data->event->ID );

and expect that to be the correct email address.

A single notification can be used for multiple events, so the tricky party is making sure you first have the event(s) to pull the event meta from and also that if there are multiple events select that the shortcode handles that correctly.

As mentioned above take a look within \core\libraries\shortcodes\EE_Email_Shortcodes.lib.php around line 101 you’ll find _get_event_admin_emails()

That does something similar for the event admin emails, your shortcode would be very similar to this, only it would loop through the events and pull the ’email_event_field’ meta value. Then use that value to build a string of email address for the message to be sent to.

The support post ‘EE4 – Create Shortcode to insert it on Email template – With ACF Pro’ 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.

Event Espresso