Skip to content

Instantly share code, notes, and snippets.

@kaskad88
Last active January 18, 2023 07:08
Show Gist options
  • Save kaskad88/eb35ae49f312d95746b13d3fde25d0f1 to your computer and use it in GitHub Desktop.
Save kaskad88/eb35ae49f312d95746b13d3fde25d0f1 to your computer and use it in GitHub Desktop.
add_filter( 'do_shortcode_tag', function ( $output, $tag, $attr ) {
if ( 'jet_engine' !== $tag ) {
return $output;
}
if ( empty( $attr['component'] ) || 'meta_field' !== $attr['component'] ) {
return $output;
}
$date_keys = array( 'feastday', 'date_field_1', 'date_field_2' ); // date fields list
if ( empty( $attr['field'] ) || ! in_array( $attr['field'], $date_keys ) ) {
return $output;
}
if ( empty( $output ) ) {
return $output;
}
$format = get_option( 'date_format' ); // or set custom date format. Ex.: $format = 'F j, Y';
$output = date_i18n( $format, $output );
return $output;
}, 10, 3 );
@justgkp
Copy link

justgkp commented Dec 25, 2021

thanks for the immediate support. It worked exactly as mentioned. I have another problem, if there are more than one meta_field with date format how will I solve it? Please help me.

@kaskad88
Copy link
Author

Hello @justgkp. I make some changes to the code and now you can set a list of date fields in the Line 11. The changes were on lines 11-13

@codeintopixel
Copy link

Can you share what exactly I have to replace in this code? I have 2 meta-fields(customer-due-date, due-date) which needs to be formatted in mail.

`add_filter( 'do_shortcode_tag', function ( $output, $tag, $attr ) {

if ( 'jet_engine' !== $tag ) {
return $output;
}

if ( empty( $attr['component'] ) || 'meta_field' !== $attr['component'] ) {
return $output;
}

$date_keys = array( 'customer-due-date', 'due-date' ); // date fields list

if ( empty( $attr['field'] ) || ! in_array( $attr['field'], $date_keys ) ) {
return $output;
}

if ( empty( $output ) ) {
return $output;
}

$format = get_option( 'date_format' ); // or set custom date format. Ex.: $format = 'F j, Y';
$output = date_i18n( $format, $output );

return $output;

}, 10, 3 );`

@kaskad88
Copy link
Author

kaskad88 commented Dec 27, 2022

@codeintopixel According to the code, you did everything correctly

@codeintopixel
Copy link

@kaskad88 Currently "Save as timestamp" option is ON for both fields, earlier when option was OFF it was showing correctly in mails.
I have tried and tested after adding this code, still showing in same format. This form is created using JetFormBuilder.

image

@kaskad88
Copy link
Author

@codeintopixel Could you please attach a screen with your email template in JetFormBuilder https://tppr.me/4eT8f

@codeintopixel
Copy link

image

Here you go @kaskad88

@kaskad88
Copy link
Author

@codeintopixel for your case the code is above not needed.

Replace the string %customer-due-date% on %customer-due-date|format_date% in the content field.

@codeintopixel
Copy link

This worked, one typo here though instead of hypen(-) we have to use underscore(_). As this is what macros accepting in form builder. Thank you for your quick responses. 👯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment