Support

Home Forums Event Espresso Premium Creating Google Calendar in confirmation email

Creating Google Calendar in confirmation email

Posted: April 19, 2021 at 5:32 pm


trainadesign

April 19, 2021 at 5:32 pm

Hello,

I’m trying to create a google calendar shortcode that adds an event to the google calendar, similar to the existing iCal one, but i’m hitting a roadblock, can you help?

I followed directions from here:
https://eventespresso.com/wiki/messages-system-how-to-add-custom-message-shortcodes/

i have a function that registers the shortcode and a parser, But I’m not sure how to pull the event title and time data/information.

and i’m using this link:
https://stackoverflow.com/questions/10488831/link-to-add-to-google-calendar


Tony

  • Support Staff

April 20, 2021 at 2:41 am

Hi there,

i have a function that registers the shortcode and a parser, But I’m not sure how to pull the event title and time data/information.

It depends on the library you are registering with as to what data will be available and where within the code it will be.

Can you post a Gist or Pastebin with your code in so I can take a look?


trainadesign

April 20, 2021 at 10:38 am

https://gist.github.com/johnpdang/302b330960e2a189851f78673ea3329c

I think i’m in the EE_Datetime library, which should i be in to get access to the event title?


Tony

  • Support Staff

April 20, 2021 at 2:59 pm

You’re in the EE_Datetime_Shortcodes library and $data is an instance of EE_Datetime.

You can pull various related objects using our model system, if you haven’t read the docs I recommend taking a look here:

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

As it helps you to follow what and how you can get various data.

For your current question, as you have an EE_Datetime you can do something like:

$event = $data->event();
if( $event instanceof EE_Event ) {
    //Use $event for various info here.
    echo $event->name();
}

The above is how you can echo th event title, $event is an EE_Event and will have various method available relating to the event itself you can use for more info.

I’m curious why you are using a dynamic shortcode for this?

The _* at the end of your shortcode indicates (within other shortcodes in the message system) that it has parameters you can pass, however, your code isn’t parsing any additional parameters so unless you plan on adding those later you could just use [GOOGLE_CAL_LINK].


trainadesign

April 20, 2021 at 5:07 pm

thanks so much, that worked great!

do you know how i would change the date format to be compatible with google calendar?

i’m currently using:
$data->get(DTT_EVT_start);

which outputs:
April 20, 2021 3:40 pm

but i’d like it to be:
20210420T224000Z


Tony

  • Support Staff

April 21, 2021 at 4:27 am

That’s they same format used in the iCal, which it does like this:

date(EED_Ical::iCal_datetime_format, $datetime->start());

Which is basically the same as:

date('Ymd\THis\Z', $data->start());


trainadesign

April 21, 2021 at 10:33 am

worked perfectly, thanks again!


Tony

  • Support Staff

April 21, 2021 at 11:10 am

You’re most welcome.

The support post ‘Creating Google Calendar in confirmation email’ 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