Skip Navigation

[Resolved] form email notification %%DATE_TIME%% placeholder returning wrong format.

This support ticket is created 4 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Jamal 4 years, 5 months ago.

Assisted by: Jamal.

Author
Posts
#1994491

I wanted to send the current time in the text of the email notification for the user data.
Unfortunately, the placeholder %%DATE_TIME%% does not work as I wanted.
It outputs the date as Y-m-d H: i: s format and not as j.m.Y H: i: s (which I have preset in the WordPress settings) in the e-mail.

#1994527

I had already found this problem in a post several years old, but I didn't know the ID yet.

Hopefully it won't take as many years to get fixed.

#1994539

I have escalated this bug to our 2nd Tier for another evaluation, and I'll share the workaround again here for other users to benefit from.

add_filter('cred_body_notification_codes', 'my_date_time_format', 999, 3); 
function my_date_time_format($defaultPlaceHolders,$form_id,$post_id) {
  if($form_id == 14) {
    $new_datetime = date("d.m.Y H:i:s", strtotime($defaultPlaceHolders['%%DATE_TIME%%']));
    $defaultPlaceHolders['%%DATE_TIME%%'] = $new_datetime;
    
    return $defaultPlaceHolders;
  } 
}

I'll get back to you as soon as we have any feedback.

#1996051

Hello again, our 2nd Tier has escalated this bug to the developers to be fixed in an upcoming release. He also improved the custom code solution that I shared to make it work for all forms, and to make it take the date_time format from the system instead of hardcoding it:

add_filter( 'cred_subject_notification_codes', 'ts_date_placeholder' );
add_filter( 'cred_body_notification_codes', 'ts_date_placeholder' );
function ts_date_placeholder( $placeholders ){

    $date_format = get_option( 'date_format' );
    $time_format = get_option( 'time_format' );

    $now = date( $date_format.' '.$time_format, current_time( 'timestamp' ) );

    $placeholders['%%DATE_TIME%%'] = $now;

    return $placeholders;
}