Skip to content

Commit

Permalink
Merge pull request #3704 from WordImpress/issue/3655
Browse files Browse the repository at this point in the history
feat: create template tag to pass the donor comment to email templates #3655
  • Loading branch information
ravinderk committed Sep 21, 2018
2 parents 3de9fae + e89a6b8 commit fc16076
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions includes/admin/emails/abstract-email-notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ public function preview_email_template_tags( $message ) {
),
'admin_email' => give_email_admin_email(),
'offline_mailing_address' => give_email_offline_mailing_address(),
'donor_comment' => $payment_id ? give_email_donor_comment( array( 'payment_id' => $payment_id ) ) : esc_html__( 'Sample Donor Comment', 'give' ),
)
);

Expand Down
34 changes: 34 additions & 0 deletions includes/emails/class-give-email-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,13 @@ function give_setup_email_tags() {
'context' => 'general',
),

array(
'tag' => 'donor_comment',
'desc' => esc_html__( 'The Donor Comment that was submitted with the donation.', 'give' ),
'func' => 'give_email_donor_comment',
'context' => 'donor',
),

);

// Apply give_email_tags filter
Expand Down Expand Up @@ -1611,6 +1618,33 @@ function give_email_offline_mailing_address() {
return $offline_address;
}

/**
* Returns the donor comment for a particular donation.
*
* Email template tag: {donor_comment}
*
* @param array $tag_args Array of arguments for email tags.
*
* @since 2.3.0
*
* @return string
*/
function give_email_donor_comment( $tag_args ) {

// Get the payment ID.
$payment_id = $tag_args['payment_id'];

// Get the comment object for the above payment ID and donor ID.
$comment = give_get_donor_donation_comment( $payment_id, give_get_payment_donor_id( $payment_id ) );

if ( is_array( $comment ) && empty( $comment ) ) {
return '';
}

// Return comment content.
return $comment->comment_content;
}

/**
* This function helps to render meta data with from dynamic meta data email tag.
* Note: meta data email tag must be in given format {meta_*}
Expand Down

0 comments on commit fc16076

Please sign in to comment.