Last active
April 17, 2020 15:33
-
-
Save rickalday/dd724492bbb4eda548b9ac4fe010cb03 to your computer and use it in GitHub Desktop.
GiveWP Add Email Tag for Donor Last Name
This file contains 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
function givewp_get_donor_last_name() { | |
give_add_email_tag( | |
array( | |
'tag' => 'lastname', // The tag name. | |
'desc' => __( 'The last name of the donor.', 'give' ), | |
'func' => 'givewp_get_donor_last_name_tag', // Callback to function below. | |
'context' => 'donation', // This tag can be for both admin and donor notifications. | |
'is_admin' => false, // default is false. This is here to simply display it as an option. | |
) | |
); | |
} | |
add_action( 'give_add_email_tags', 'givewp_get_donor_last_name' ); | |
function givewp_get_donor_last_name_tag( $tag_args ) { | |
$donor_info = array(); | |
$lastname = ''; | |
switch ( true ) { | |
case give_check_variable( $tag_args, 'isset', 0, 'payment_id' ): | |
$donor_info = give_get_payment_meta_user_info( $tag_args['payment_id'] ); | |
$lastname = $donor_info['last_name']; | |
break; | |
case give_check_variable( $tag_args, 'isset', 0, 'user_id' ): | |
$lastname = Give()->donor_meta->get_meta( | |
Give()->donors->get_column_by( 'id', 'user_id', $tag_args['user_id'] ), | |
'_give_donor_last_name', | |
true | |
); | |
break; | |
/** | |
* Get Donor First Name from donor id | |
* | |
* @since 2.0 | |
*/ | |
case give_check_variable( $tag_args, 'isset', 0, 'donor_id' ): | |
$lastname = Give()->donor_meta->get_meta( $tag_args['donor_id'], '_give_donor_last_name', true ); | |
break; | |
} | |
return $lastname; | |
} | |
// Only add this function if you want to add the tag to PDF receipts | |
function give_add_lastname_pdf_tag( $template_content, $args ) { | |
$lastname = isset( $args['payment_meta']['_give_donor_billing_last_name'] ) ? $args['payment_meta']['_give_donor_billing_last_name'] : ''; | |
$template_content = str_replace( '{lastname}', $lastname, $template_content ); | |
return $template_content; | |
} | |
add_filter( 'give_pdf_compiled_template_content', 'give_add_lastname_pdf_tag', 999, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment