Skip to content

Instantly share code, notes, and snippets.

@Musilda
Created October 5, 2019 08:26
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 Musilda/2e8e730ab795b87b2e2ee0d658c05f30 to your computer and use it in GitHub Desktop.
Save Musilda/2e8e730ab795b87b2e2ee0d658c05f30 to your computer and use it in GitHub Desktop.
<?php
// Delete all failed orders custom action
add_action( 'musilda_delete_failed_orders', 'musilda_delete_all_failed_orders' );
// This function will run once the 'musilda_delete_failed_orders' is called
function musilda_delete_all_failed_orders() {
$args = array(
'status' => 'failed',
);
$orders = wc_get_orders( $args );
foreach( $orders as $order ){
$order_id = $order->get_id();
wp_delete_post( $order_id, true );
}
}
// Make sure this event hasn't been scheduled
if( !wp_next_scheduled( 'musilda_delete_failed_orders' ) ) {
// Schedule the event
wp_schedule_event( time(), 'daily', 'musilda_delete_failed_orders' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment