Skip to content

Instantly share code, notes, and snippets.

@rickalday
Last active December 19, 2025 19:01
Show Gist options
  • Select an option

  • Save rickalday/598a20177b3c7c756dbc4ca854897d77 to your computer and use it in GitHub Desktop.

Select an option

Save rickalday/598a20177b3c7c756dbc4ca854897d77 to your computer and use it in GitHub Desktop.
Add a PDF tag that outputs the donation leve description
<?php
use Give\ValueObjects\Money;
use Give\Donations\Models\Donation;
function give_add_donation_level_pdf_tag( $template_content, $args ) {
// during testing, uncomment the next line to see a full printed array of the possible args that you can query
//var_dump("<pre>".print_r($args,true)."</pre>");
$level_label = '';
$currency = give_get_option('currency');
$form_id = give_get_payment_form_id( $args['donation_id'] );
$donation_id = $args['donation_id'];
$options = give()->form_meta->get_meta($form_id, '_give_donation_levels', true) ?? [];
$donation = Donation::find($donation_id);
foreach ( $options as $option ) {
if (isset($option['_give_amount'], $option['_give_text'])) {
if (Money::of($option['_give_amount'], $currency )->getMinorAmount() == $donation->amount->getAmount()) {
$level_label = $option['_give_text'];
}
}
}
$template_content = str_replace( '{donation_level}', $level_label , $template_content );
return $template_content;
}
add_filter( 'give_pdf_compiled_template_content', 'give_add_donation_level_pdf_tag', 999, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment