• Resolved juanmanuelsanch

    (@juanmanuelsanch)


    Hello ! I need to make the date format for the emails custom, I didnt see any lables like dd/MM/yy

    So it would be something like 02/Decemeber/2022 that way there is no formatting errors when interpreting the dates in the email

    Is there a way to do it?
    Thanks !

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @juanmanuelsanch ,

    Date format can be selected in the Datepicker field, like here: https://monosnap.com/file/Olp0boPvubhG8IhPTFmn51YdrmZQiy

    kind regards,
    Kasia

    Thread Starter juanmanuelsanch

    (@juanmanuelsanch)

    Hi Kasia,

    Thats true but none of the formats seems to write the date as I described it above as 02/December/2022

    Thanks for the help

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @juanmanuelsanch,

    I suppose you want to display with the name of the month ie “December” instead of numerals like 11,12. By default, the plugin only displays the month in number format.

    I’m checking with our developer to see if there is any workaround regarding this.

    Will keep you posted once we get further feedback.

    Kind Regards,

    Nithin

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @juanmanuelsanch,

    Could you please try this snippet and see whether it helps?

    <?php
    
    add_filter( 'forminator_custom_form_mail_admin_message', 'wpmudev_show_formatted_date', 10, 5 );
    function wpmudev_show_formatted_date( $message, $custom_form, $data, $entry, $cls ) {
      	if ( $custom_form->id == 1138 ) { //Please change the form ID here
    		preg_match_all('/\d{2}\/\d{2}\/\d{4}/', $message, $matches);
    		foreach ( $matches as $date ) {
    			if ( ! empty( $date ) ) {
    				foreach ( $date as $key => $val ) {
    					$message = str_replace( $val, date( 'd/M/Y', strtotime( $val ) ), $message ) ;
    				} 
    			}
    		}
    	}
    	return $message;
    }
    

    You’ll have to replace the number 1138 in the above code to your form ID. Suppose the form ID is 123 the the line will change to:

    	if ( $custom_form->id == 123 ) { 

    I gave a quick test and can confirm the above code work. You can apply the above code as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Please do let us know how that goes.

    Best Regards,

    Nithin

    Thread Starter juanmanuelsanch

    (@juanmanuelsanch)

    Hello ! First of happy christmas ! The code doesn’t work. I get the following date in the mail

    Fecha: 01/Jan/1970

    Thanks !

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @juanmanuelsanch,

    Merry Christmas. Hope you are doing good today.

    I suppose you meant the month isn’t in full text? If yes, please update the following line in the previous code shared ie:

    $message = str_replace( $val, date( 'd/M/Y', strtotime( $val ) ), $message ) ;
    

    You’ll have to update ‘d/M/Y’ with ‘d/F/Y’. That’s it’ll be like the following:

    $message = str_replace( $val, date( 'd/F/Y', strtotime( $val ) ), $message ) ;

    I hope this helps. Have a great day ahead.

    Best Regards,

    Nithin

    Thread Starter juanmanuelsanch

    (@juanmanuelsanch)

    Hello Nithin ! Happy New Year !

    Doesn’t work because the format Im using in the form is d/m/y so for example, that code will return for today 01/03/2023 (third of january 2023) which is 03/01/2023 in d/m/y format a result of 01/March/2023 because its depending on the formatted input instead of a global non formatted one.

    Hope this helps and that it could be included as a feature in the future. Since date format can vary a lot depending on where you are located.

    Best regards and have a great year.

    Thread Starter juanmanuelsanch

    (@juanmanuelsanch)

    add_filter( 'forminator_custom_form_mail_admin_message', 'wpmudev_show_formatted_date', 10, 5 );
    function wpmudev_show_formatted_date( $message, $custom_form, $data, $entry, $cls ) {
    if ( $custom_form->id == 3344 ) { //Please change the form ID here
    preg_match_all('/\d{2}\/\d{2}\/\d{4}/', $message, $matches);
    foreach ( $matches as $date ) {
    if ( ! empty( $date ) ) {
    foreach ( $date as $key => $val ) {
    $date_formats = array( 'd/m/Y', 'Y-m-d', 'm-d-Y', 'd.m.Y' ); // Add more date formats if necessary
    $date_obj = null;
    foreach ( $date_formats as $format ) {
    $date_obj = DateTime::createFromFormat( $format, $val );
    if ( $date_obj ) {
    break;
    }
    }
    if ( $date_obj ) {
    $timestamp = $date_obj->getTimestamp();
    $locale = get_locale(); // Get the WordPress locale
    setlocale( LC_TIME, $locale ); // Set the locale to the WordPress locale
    $global_date = strftime( '%d/%B/%Y', $timestamp );
    $message = str_replace( $val, $global_date, $message ) ;
    }
    }
    }
    }
    }
    return $message;
    }

    with some help of GPT I got a code that works with several input formats and will give you the desired one. I would be nice to have all the available formats for the confirmation emails, so in case you are using a confirmation languages you can adapt to your needs.

    This will work for me for now. Thanks !

    Plugin Support Zafer – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @juanmanuelsanch,

    We are happy to hear that the issue has been resolved and marking this ticket accordingly.
    Please let us know in case you need further help.

    Kind regards,
    Zafer

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Custom date format in emails’ is closed to new replies.