|
/ Documentation /Developer Hooks & Events/ suredonation_donation_created Action Hook

suredonation_donation_created Action Hook

Overview

The suredonation_donation_created action fires immediately after a new donation row has been successfully inserted into the database. It signals that a donation record now exists, regardless of its payment status — making it the right place to hook logging, syncing, or bookkeeping that should happen for every new donation.

Hook Signature

do_action( 'suredonation_donation_created', $donation_id, $payload );

Parameters

$donation_id _(int)_ – The newly created donation’s ID.

$payload _(array)_ – A curated, integration-safe copy of the donation (built by Donations::get_integration_payload()). Internal/PII columns such as ip_address, user_agent, referer_url and the raw donation_data are deliberately excluded. Available keys:

id _(int)_, campaign_id _(int)_, form_id _(int)_, donor_id _(int)_

donor_name _(string)_, donor_email _(string)_, donor_phone _(string)_, donor_comment _(string)_

amount _(float)_, fees_covered _(float)_, refunded_amount _(float)_, currency _(string)_

gateway _(string)_, payment_status _(string)_, payment_mode _(string)_, donation_type _(string)_

transaction_id _(string)_, subscription_id _(string)_, subscription_status _(string)_

is_anonymous _(bool)_, created_at _(string)_, updated_at _(string)_

  > When is_anonymous is truthy, donor_name, donor_email, donor_phone and donor_comment are returned as empty strings.

Usage

add_action( 'suredonation_donation_created', 'your_custom_function', 10, 2 );

function your_custom_function( $donation_id, $payload ) {

    // Your custom logic here.

}

Example

add_action( 'suredonation_donation_created', 'mysite_log_new_donation', 10, 2 );

function mysite_log_new_donation( $donation_id, $payload ) {

    error_log( sprintf(

        'New SureDonation #%d: %s %.2f via %s (status: %s)',

        $donation_id,

        $payload['currency'],

        $payload['amount'],

        $payload['gateway'],

        $payload['payment_status']

    ) );

}

Fires inside Donations::add() only when the database insert succeeds.

Does not fire for records created by the migration/import tool (skipped when import_source is set on the incoming data).

Related Hooks

  • suredonation_new_donation
  • suredonation_donation_completed
  • suredonation_donation_status_changed
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