skip to Main Content

I have a WordPress site and I am using a plugin to manage registrations to events (the plugin name is Events Manager Pro).

With this plugin, we are allowed to create placeholders to display various information on events webpages.

I created a placeholder to show the date and time when registrations to an event starts. The name I gave to my placeholder is: #_REGISTRATIONSTARTDATETIME

I use this code in the function.php file of my child theme:

function my_em_registrationstartdatetime_placeholder($replace, $EM_Event, $result){
    if ( $result == '#_REGISTRATIONSTARTDATETIME' ) {
        $ticket_list = "";
        foreach( $EM_Event->get_tickets()->tickets as $EM_Ticket ){
          $ticket_list .= $EM_Ticket->get_datetime('start');
        }
        $replace = $ticket_list;
    }
    return $replace;
}
add_filter('em_event_output_placeholder','my_em_registrationstartdatetime_placeholder',1,3);

My problem is the date and time is output in this format: 2023-01-09 10:00:00

I wish to have the date and time output in this format instead: Monday January 9 at 10h00

Thank you!

My knowledge in PHP is limited. I am sorry, but I am eager to learn. Does anyone know what could be modified in my PHP code to format the date and time?

2

Answers


  1. Chosen as BEST ANSWER

    Thank you. It now works.

    Here is the code I have in my functions.php file :

    function my_em_registrationstartdatetime_placeholder($replace, $EM_Event, $result){
        if ( $result == '#_REGISTRATIONSTARTDATETIME' ) {
            $ticket_list = "";
            foreach( $EM_Event->get_tickets()->tickets as $EM_Ticket ){
              $ticket_list = $EM_Ticket->get_datetime('start');
            }
            $replace = wp_date('l j F at Ghi', wp_strtotime($ticket_list));
        }
        return $replace;
    }
    add_filter('em_event_output_placeholder','my_em_registrationstartdatetime_placeholder',1,3);
    

    In the functions.php file, I also added the code recommended in the link suggested by Moishy : https://mediarealm.com.au/articles/wordpress-timezones-strtotime-date-functions/.


  2. use wp_date function and php date format parameters

    $replace = wp_date('l F j at Ghi', strtotime($ticket_list));
    

    to add a timezone to it, add a DateTimeZone argument to the function. For example:

    $replace = wp_date('l F j at Ghi', strtotime($ticket_list), new DateTimeZone('America/Vancouver'));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search