Last active
July 22, 2025 18:36
-
-
Save rickalday/a795a1e2735c8ec49f0b31a91903c972 to your computer and use it in GitHub Desktop.
Add {company_or_name} tag for PDF Receipts.
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 | |
/** | |
* Add {company_or_name} tag to GiveWP PDF Receipts using the give_pdf_compiled_template_content filter. | |
* Outputs the Company name if provided, otherwise outputs donor's full name. | |
*/ | |
add_filter( 'give_pdf_compiled_template_content', function( $template_content, $args ) { | |
//var_dump("<pre>".print_r($args,true)."</pre>"); | |
// | |
// Make sure payment ID is available. | |
$payment_id = ! empty( $args['donation_id'] ) ? absint( $args['donation_id'] ) : 0; | |
if ( ! $payment_id ) { | |
return $template_content; | |
} | |
// Get Company Name, if any. | |
$company = $args['payment_meta']['_give_donation_company']; | |
// Get donor name as fallback. | |
$donor_name = trim( $args['payment_meta']['_give_donor_billing_first_name'] . ' ' . $args['payment_meta']['_give_donor_billing_last_name'] ); | |
// Set replacement value. | |
$replacement = ! empty( $company ) ? esc_html( $company ) : esc_html( $donor_name ); | |
// Replace the tag in the template content. | |
$template_content = str_replace( '{company_or_name}', $replacement, $template_content ); | |
return $template_content; | |
}, 999, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment