Action uncanny-automator

automator_charitable_donation_made

Fires after a donation is successfully processed by the Charitable integration, providing access to the donation processor object.

add_action( 'automator_charitable_donation_made', $callback, 10, 1 );

Description

Fires after a donation is successfully made through the Charitable plugin. Developers can use this hook to perform custom actions, such as logging donations, sending notifications, or triggering other automations, based on the donation details available via the passed donation ID.


Usage

add_action( 'automator_charitable_donation_made', 'your_function_name', 10, 1 );

Parameters

$processor (mixed)
This parameter contains the Charitable donation processor object, which holds all data related to the donation that was just made.

Examples

// Hook into the automator_charitable_donation_made action to process a donation.
// This function will be executed whenever a donation is successfully made via Charitable.
// It takes the donation ID as an argument.
add_action( 'automator_charitable_donation_made', 'handle_charitable_donation_made', 10, 1 );

/**
 * Handles the processing of a Charitable donation after it's made.
 *
 * @param int $donation_id The ID of the donation that was just made.
 */
function handle_charitable_donation_made( $donation_id ) {
	// Retrieve the donation object using the provided ID.
	$donation = new Charitable_Donation( $donation_id );

	// Check if the donation object was successfully retrieved and is valid.
	if ( ! $donation || ! $donation->exists() ) {
		// If not valid, log an error or return early to prevent further processing.
		error_log( "Automator: Could not retrieve a valid Charitable donation with ID: {$donation_id}." );
		return;
	}

	// Get the donor's user ID. This might be null for anonymous donations.
	$donor_user_id = $donation->get_user_id();

	// Get the donation amount.
	$donation_amount = $donation->get_donation_amount();

	// Example: If the donor is a logged-in user, you might want to add points or update their profile.
	if ( ! is_null( $donor_user_id ) && $donor_user_id > 0 ) {
		// This is a placeholder for actual logic.
		// For example, you could use a function like this:
		// update_user_meta( $donor_user_id, 'total_donation_amount', (float)get_user_meta( $donor_user_id, 'total_donation_amount', true ) + $donation_amount );

		// For this example, we'll just log that a donation was made by a logged-in user.
		$user = get_user_by( 'id', $donor_user_id );
		if ( $user ) {
			error_log( "Automator: Logged-in user '{$user->user_login}' made a donation (ID: {$donation_id}) of {$donation_amount}." );
		}
	} else {
		// Example: If the donation is anonymous, you might want to send a notification to an admin.
		// wp_mail( '[email protected]', 'New Anonymous Donation Received', "An anonymous donation (ID: {$donation_id}) of {$donation_amount} has been received." );
		error_log( "Automator: Anonymous donation (ID: {$donation_id}) of {$donation_amount} made." );
	}

	// Example: If the donation amount exceeds a certain threshold, trigger a special notification.
	if ( $donation_amount >= 100 ) {
		// error_log( "Automator: High-value donation (ID: {$donation_id}) of {$donation_amount} received. Consider special follow-up." );
	}

	// The 'automator_charitable_donation_made' hook is often used by plugins like Automator to
	// create custom triggers. This function demonstrates how you might hook into it to perform
	// additional actions or to log information about the donation.
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/integrations/charitable/class-charitable-integration.php:59
src/integrations/charitable/class-charitable-integration.php:80

public function charitable_frontend_first_page_after_dontation( $processor ) {
		if ( is_a( $processor, 'Charitable_Donation_Processor' ) ) {
			// Trigger our custom action for triggers
			do_action( 'automator_charitable_donation_made', $processor->get_donation_id() );
		}
	}

Internal Usage

Found in src/integrations/charitable/triggers/anon-charitable-made-donation.php:33:

$this->add_action( 'automator_charitable_donation_made', 10, 1 );

Found in src/integrations/charitable/triggers/charitable-user-made-donation.php:32:

$this->add_action( 'automator_charitable_donation_made', 10, 1 );

Found in uncanny-automator-pro/src/integrations/charitable/triggers/anon-charitable-campaign-donation-amount.php:54:

$this->add_action( 'automator_charitable_donation_made', 10, 1 );
Scroll to Top