Skip to content

Instantly share code, notes, and snippets.

@ericnicolaas
Created December 10, 2020 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericnicolaas/62cd6f1d652d86ffab6d5994334a26ab to your computer and use it in GitHub Desktop.
Save ericnicolaas/62cd6f1d652d86ffab6d5994334a26ab to your computer and use it in GitHub Desktop.
Delete all pending donations in a date rnage
<?php
/**
* Adjust the before/after variables to limit the deletion to
* a specific date range. If you want to delete all, set a very
* early $before date (i.e. '2000-01-01').
*/
add_action( 'admin_init', function() {
$after = '2020-11-01';
$before = '2020-11-30';
$query = new Charitable_Donations_Query(
array(
'output' => 'ids',
'status' => array( 'charitable-pending' ),
'number' => -1,
'date_query' => array(
array(
'before' => $before,
'after' => $after,
'inclusive' => true,
)
),
)
);
foreach( $query->get_donations() as $donation ) {
wp_delete_post( $donation->ID );
}
} );
@ericnicolaas
Copy link
Author

To delete recurring donations, you can use the following:

/**
 * Adjust the before/after variables to limit the deletion to 
 * a specific date range. If you want to delete all, set a very 
 * early $before date (i.e. '2000-01-01').
 */
add_action( 'admin_init', function() {
	$after  = '2020-08-01';
	$before = '2020-08-30';
	$query  = new Charitable_Recurring_Donation_Query( 
		array(
			'output'     => 'ids',
			'status'     => array( 'charitable-pending' ),
			'number'     => -1,
			'date_query' => array(
				array(
					'before'        => $before,
					'after'         => $after,
					'inclusive'     => true,
				)
			),
		)
	);
	
	foreach( $query->get_donations() as $donation ) {
		wp_delete_post( $donation->ID );
	}
} );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment