Created
August 18, 2026 21:26
-
-
Save rickalday/3a6b52fc1aed275410fb5eb6d08a000c to your computer and use it in GitHub Desktop.
GiveWP time email tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function give_time_email_tag( $email_tags ) { | |
| // Adds an email tag called {time} to output the donation time. | |
| $email_tags[] = array( | |
| 'tag' => 'time', // The tag name. | |
| 'desc' => __( 'This outputs the donation time', 'give' ), // For admins. | |
| 'func' => 'render_time_email_tag', // Callback to function below. | |
| 'context' => 'donation', | |
| ); | |
| return $email_tags; | |
| } | |
| add_filter( 'give_email_tags', 'give_time_email_tag', 999, 1 ); | |
| function render_time_email_tag( $tag_args ) { | |
| $date = get_post_field( 'post_date', $tag_args['payment_id'] ); | |
| if ( empty( $date ) ) { | |
| return ''; | |
| } | |
| try { | |
| $dateTime = new DateTime( $date ); | |
| // Change the format as needed. Output: 15:31:00 | |
| $output = $dateTime->format( 'H:i:s' ); | |
| } catch ( Exception $e ) { | |
| $output = ''; | |
| } | |
| return apply_filters( 'give_email_tag_give_time', $output, $tag_args ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment