Created
October 5, 2019 08:26
-
-
Save Musilda/2e8e730ab795b87b2e2ee0d658c05f30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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