Skip to content

Instantly share code, notes, and snippets.

@rickalday
Last active June 9, 2022 17:29
Show Gist options
  • Save rickalday/efa19beb7c7ccaa6bb58d55166012ecc to your computer and use it in GitHub Desktop.
Save rickalday/efa19beb7c7ccaa6bb58d55166012ecc to your computer and use it in GitHub Desktop.
Changes the 'Receipt-' prefix of the pdf receipt filename. You can include additional information from the donation too.
function my_give_pdf_receipt_filename_changer() {
// Define required variables.
$newname = 'Test-';
$get_data = give_clean( filter_input_array( INPUT_GET ) );
$donation_id = give_get_donation_id_by_key( $get_data['_give_hash'] );
$payment_meta = give_get_payment_meta( $donation_id );
/* Possible values
$payment_meta[_give_donation_company];
$payment_meta[_give_payment_total];
$payment_meta[_give_payment_currency];
$payment_meta[_give_payment_gateway];
$payment_meta[_give_payment_form_id];
$payment_meta[_give_payment_price_id];
$payment_meta[_give_payment_donor_title_prefix];
$payment_meta[_give_payment_donor_email];
$payment_meta[_give_payment_donor_ip];
$payment_meta[_give_payment_purchase_key];
$payment_meta[_give_payment_mode];
$payment_meta[form_title];
$payment_meta[email];
$payment_meta[form_id];
$payment_meta[user_info][first_name];
$payment_meta[user_info][last_name];
$payment_meta[user_info][email];
$payment_meta[user_info][id];
$payment_meta[user_info][address];
*/
//Use any value from the array in the next line
$newname .= $payment_meta[user_info][first_name];
//Will outuput something like Test-John-123.pdf
return $newname;
}
// If you use the Custom PDF Builder Option use the 'give_custom_pdf_receipt_filename_prefix' filter in the next line instead
add_filter( 'give_pdf_receipt_filename_prefix', 'my_give_pdf_receipt_filename_changer' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment