Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Last active August 9, 2018 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/5ea4bf3e1b683fac4e21671da783a1a3 to your computer and use it in GitHub Desktop.
Save joshfeck/5ea4bf3e1b683fac4e21671da783a1a3 to your computer and use it in GitHub Desktop.
Add the date and time range to a url param from the Calendar. The filter hook isn't present within the tooltip, so this only adds to the calendar item.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_filter(
'FHEE__EE_Datetime_In_Calendar__to_array_for_json__url',
'my_custom_calendar_url_params',
10,
3
);
function my_custom_calendar_url_params($url, $event, $obj) {
$value = '';
$datetime = $obj->datetime();
if($datetime instanceOf EE_Datetime) {
$value .= $datetime->date_and_time_range('Y_m_d', 'H_i', '-', '_');
$url = add_query_arg('datetime', $value, $event->get_permalink());
}
return $url;
};
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
// This is an example that shows how to use the datetime parameter from the calendar to style a specific ticket related to a specific datetime
add_action('wp_enqueue_scripts', 'my_add_inline_script_ts_from_cal_param', 20);
function my_add_inline_script_ts_from_cal_param() {
$custom_js = '
jQuery(document).ready(function($){
var urlParams = new URLSearchParams(window.location.search);
if(urlParams.has("datetime")){
var dParam = urlParams.get("datetime");
var styles = {
"background-color" : "#d1d1f9",
"transition" : "background-color 5000ms"
};
$(".ee-ticket-datetimes-" + dParam).css( styles );
}
});';
wp_add_inline_script('ticket_selector', $custom_js);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment