Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
function pgmb_add_event_fields( $variables, $parent_post_id ) {
$event_start_date = get_post_meta( $parent_post_id, 'WooCommerceEventsDateTimestamp', true );
$event_end_date = get_post_meta( $parent_post_id, 'WooCommerceEventsEndDateTimestamp', true );
if ( ! $event_start_date || !$event_end_date ) {
return $variables;
}
$start_datetime = new \DateTime();
$start_datetime->setTimestamp((int)$event_start_date);
// $start_datetime->setTimezone(wp_timezone());
$end_datetime = new \DateTime();
$end_datetime->setTimestamp((int)$event_end_date);
// $end_datetime->setTimezone(wp_timezone());
$variables['%wc_event_start%'] = $start_datetime->format("Y-m-d H:i:s");
$variables['%wc_event_end%'] = $end_datetime->format("Y-m-d H:i:s");
return $variables;
}
add_filter( 'mbp_placeholder_variables', 'pgmb_add_event_fields', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment