Add to google calendar link (fetch date and time)
-
Hi,
I am using Tribe events tickets + tickets pro plugins. This code snippet in my woocommerce email-template.php to add Google Calendar, Outlook calendar and Icalendar links.
The links appear correctly in an email but the date and time is obviously not fetched. When I click the +Google calendar link, the date and time data of the event is not loaded correctly in Google Calendar. I need some help with tweaking this code to make it work.
/** ?* Export buttons for Google, Outlook, and iCalendar. ?*/ if (!class_exists('Tribe__Events__Main')) { return; } $event_id = get_post_meta($order->get_id(), '_tribe_event_id', true); $post = get_post($event_id); if (empty($post)) { return; } // Get event time and date $start_date = get_post_meta($event_id, '_EventStartDate', true); $start_time = get_post_meta($event_id, '_EventStartDate', true); $end_date = get_post_meta($event_id, '_EventEndDate', true); $end_time = get_post_meta($event_id, '_EventEndDate', true); // Format the time and date as needed $formatted_start_date = date('Y-m-d', strtotime($start_date)); $formatted_start_time = date('H:i:s', strtotime($start_time)); $formatted_end_date = date('Y-m-d', strtotime($end_date)); $formatted_end_time = date('H:i:s', strtotime($end_time)); $ical_link = add_query_arg( array( 'ical' => '1', 'start_date' => $formatted_start_date, 'start_time' => $formatted_start_time, 'end_date' => $formatted_end_date, 'end_time' => $formatted_end_time ), get_the_permalink($post->ID) ); $google_calendar_link = Tribe__Events__Main::instance()->esc_gcal_url(tribe_get_gcal_link()); $outlook_calendar_link = 'https://outlook.live.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent'; $calendar_links = '<div class="tribe-events-cal-links">'; $calendar_links .= '<a class="tribe-events-gcal tribe-events-button" href="' . $google_calendar_link . '" target="_blank" rel="noopener noreferrer" title="' . esc_attr__('Dodaj v Google koledar', 'the-events-calendar') . '">+ ' . esc_html__('Google koledar', 'the-events-calendar') . '</a> '; $calendar_links .= '<a class="tribe-events-outlook tribe-events-button" href="' . $outlook_calendar_link . '" target="_blank" rel="noopener noreferrer" title="' . esc_attr__('Dodaj v Outlook koledar', 'the-events-calendar') . '">+ ' . esc_html__('Outlook koledar', 'the-events-calendar') . '</a> '; $calendar_links .= '<a class="tribe-events-ical tribe-events-button" href="' . esc_url($ical_link) . '" title="' . esc_attr__('Prenesi .ics file', 'the-events-calendar') . '">+ ' . esc_html__('iCalendar', 'the-events-calendar') . '</a>'; $calendar_links .= '</div><!-- .tribe-events-cal-links -->'; echo '<div style="margin-top: 20px;"></div>'; // Add a space before the calendar links block echo $calendar_links;
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Add to google calendar link (fetch date and time)’ is closed to new replies.