|
/ Documentation /Developer Hooks & Events/ suredonation_receipt_html Filter Hook

suredonation_receipt_html Filter Hook

Overview

The suredonation_receipt_html filter allows developers to modify the HTML used to generate SureDonation donation receipt PDFs.

The filter runs immediately before the generated HTML is passed to the mPDF PDF engine. You can use it to customize the receipt layout, add additional information, or modify the existing receipt content.

When to Use This Filter

Use this filter when you need to customize the content or appearance of donation receipts.

For example, you can use it to:

  • Add a custom footer.
  • Add organization information.
  • Add a thank-you message.
  • Modify receipt content.
  • Add custom HTML elements.
  • Customize the receipt layout and styling.

Filter Signature

apply_filters(  'suredonation_receipt_html',  $html, $donation, $donor);

Parameters

ParameterTypeDescription
$htmlstringThe receipt HTML generated by SureDonation.
$donationarrayThe donation record associated with the receipt.
$donorarray|nullThe donor record. Returns null when no donor is associated with the donation.

Return Value

Return the modified receipt HTML as a string.

The returned HTML is passed to the PDF engine and used to generate the final donation receipt.

Basic Usage

Use add_filter() to register your callback.

add_filter( 'suredonation_receipt_html',  'your_custom_function', 10,  3 );

function your_custom_function( $html, $donation, $donor ) {

    // Modify the receipt HTML here.

    return $html;

}

Example: Add a Custom Footer

The following example adds a thank-you message to the bottom of the receipt.

add_filter(  'suredonation_receipt_html', 'mysite_add_receipt_footer', 10, 3);

function mysite_add_receipt_footer( $html, $donation, $donor ) {

    $footer = '<p style="text-align:center;">Thank you for supporting our mission.</p>';

    return str_replace(

        '</body>',

        $footer . '</body>',

        $html

    );

}

Example: Add Donation Information

You can use the $donation and $donor parameters to add additional information to the receipt.

add_filter( 'suredonation_receipt_html',   'mysite_add_receipt_note', 10, 3);

function mysite_add_receipt_note( $html, $donation, $donor ) {

    $note = '<p style="text-align:center;">Donation received successfully.</p>';

    return str_replace(

        '</body>',

        $note . '</body>',

        $html

    );

}

Receipt Generation Flow

The filter is part of the receipt generation process:

  1. SureDonation prepares the donation receipt data.
  2. SureDonation generates the receipt HTML.
  3. The suredonation_receipt_html filter is applied.
  4. Your callback can modify the generated HTML.
  5. The filtered HTML is passed to mPDF.
  6. mPDF generates the donation receipt PDF.

Security Considerations

Important: The filtered HTML is passed directly to mPDF’s WriteHTML() method.

mPDF can process HTML elements such as <img> tags and may load resources referenced through file:// URIs or external resources.

Only add trusted and properly escaped content to the receipt HTML.

Avoid inserting untrusted user input directly into the HTML.

For example, when adding dynamic text, sanitize or escape the value before inserting it into the receipt.

$name = isset( $donor['name'] )

    ? esc_html( $donor['name'] )

    : '';

$note = '<p>Thank you, ' . $name . '.</p>';

Related Hooks

  • suredonation_email_smart_tags: Filters the smart tags available for SureDonation email content.
Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top