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

suredonation_create_donation_data Filter Hook

Overview

The suredonation_create_donation_data filter allows developers to modify the donation data generated during a REST API donation creation request, immediately before the record is inserted into the database.

The filtered array is passed directly to SureDonation’s donation creation process. This makes the hook useful for adding or modifying custom donation data, including fields introduced by an extension.

When to Use This Filter

Use this filter when you need to:

  • Add custom data to a donation record.
  • Modify existing donation fields before insertion.
  • Map additional REST request parameters to donation data.
  • Store information from external sources such as UTM parameters.
  • Extend SureDonation with custom database columns.

Filter Signature

apply_filters( 'suredonation_create_donation_data', $donation_data, $request );

Parameters

ParameterTypeDescription
$donation_dataarrayThe donation record that will be inserted.
$requestWP_REST_RequestThe original REST API request.

Donation Data

The $donation_data array contains fields such as:

KeyDescription
campaign_idID of the campaign associated with the donation.
donor_idID of the donor record.
amountDonation amount.
fees_coveredWhether the donor covered transaction fees.
currencyDonation currency.
gatewayPayment gateway used.
payment_statusCurrent payment status.
payment_modePayment mode, such as test or live.
donor_nameDonor name.
donor_emailDonor email address.
donor_phoneDonor phone number.
is_anonymousWhether the donation is marked anonymous.
donation_typeDonation type.
donor_commentComment provided by the donor.
transaction_idPayment transaction ID.

Return Value

Return the modified donation data array.

return $donation_data;

The returned array is passed directly to the donation insertion process.

Basic Usage

add_filter( 'suredonation_create_donation_data', 'your_custom_function', 10, 2);

function your_custom_function( $donation_data, $request ) {

// Modify the donation data here.

return $donation_data;

}

Example: Store a UTM Source

The following example reads the utm_source parameter from the REST request and stores it in the donor comment.

add_filter( 'suredonation_create_donation_data', 'mysite_tag_source', 10, 2);

function mysite_tag_source( $donation_data, $request ) {

$source = $request->get_param( 'utm_source' );

if ( $source ) {

$donation_data['donor_comment'] =

'Source: ' . sanitize_text_field( $source );

}

return $donation_data;

}

Example: Add a Custom Field

If an extension has added a custom column to the donations table, the filter can be used to populate it.

add_filter( 'suredonation_create_donation_data', 'mysite_add_campaign_source', 10, 2);

function mysite_add_campaign_source( $donation_data, $request ) {

$source = $request->get_param( 'campaign_source' );

if ( $source ) {

$donation_data['campaign_source'] =

sanitize_text_field( $source );

}

return $donation_data;

}

Donation Creation Flow

The filter runs after SureDonation has assembled the donation data but before the record is inserted.

REST create-donation request

          â†“

Validate request

          â†“

Build donation data

          â†“

suredonation_create_donation_data

          â†“

Custom data added or existing data modified

          â†“

Donations::add()

          â†“

Donation stored in database

          â†“

suredonation_donation_created

Data Sanitization

The returned array is passed directly to the donation insertion process.

If you add or modify values, sanitize them before returning the array.

For example:

$source = sanitize_text_field(

$request->get_param( 'utm_source' )

);

Do not store raw user-provided values without appropriate sanitization or validation.

Donations_API::create_donation()

The returned $donation_data array is passed directly to Donations::add().

  • Return an array.
  • Sanitize values obtained from the request.
  • Use valid donation table columns.
  • Avoid modifying payment-related fields unless your integration requires it.
  • Keep the callback lightweight because it runs during donation creation.

Related Hooks

  • suredonation_update_donation_data: Filters donation data before an existing donation is updated through the REST API.
  • suredonation_donation_created: Fires after a new donation has been created.
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