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

suredonation_import_batch_complete Action Hook

Overview

The suredonation_import_batch_complete action fires after each batch of a CSV import finishes and the session payload has been persisted. SureDonation Pro uses it to update the progress on its import-history record.

A CSV import is processed in batches so it can run across several requests without timing out, which means this action fires many times over the life of one import.

Hook Signature

do_action( 'suredonation_import_batch_complete', $import_id, $progress );

Parameters

  • $import_id _(string)_ – The import session ID.
  • $progress _(array)_ – The session payload as persisted after this batch, including current_phase, offset, byte_offset, total_rows, created, status, and the per-phase results counters.

Usage

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

function your_custom_function( $import_id, $progress ) {

// Your custom logic here.

}

Example

add_action( 'suredonation_import_batch_complete', 'mysite_track_import_progress', 10, 2 );

function mysite_track_import_progress( $import_id, $progress ) {

$done  = (int) ( $progress['offset'] ?? 0 );

$total = (int) ( $progress['total_rows'] ?? 0 );

if ( $total > 0 ) {

set_transient(

'mysite_import_pct_' . $import_id,

(int) floor( ( $done / $total ) * 100 ),

HOUR_IN_SECONDS

);

}

}

Fires from Import_Runner::run_batch() after a successful batch, and once more from Import_Runner::finish() when the session completes — so the final batch triggers it twice in effect: once for the batch and once as part of completion, immediately before suredonation_import_complete.

It does not fire when a batch fails. On an unexpected error the runner marks the session failed, cleans up the uploaded CSV, and returns without dispatching this action.

Because it runs on every batch, keep the callback cheap. Heavy work here multiplies across the whole import.

Check $progress[‘status’] if you need to distinguish an in-flight batch (running) from the completion pass (complete).

Related Hooks

  • suredonation_import_session_created
  • suredonation_import_complete
  • suredonation_import_givewp_batch_complete
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