Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Will clear out all the specified completed scheduled actions, 5000 at a time.
<?php // do not copy this line
/**
* Will clear out all the specified completed scheduled actions, 5000 at a time.
*/
function clear_woocommerce_scheduled_actions_20200609() {
global $wpdb;
$limit = 5000;
$actions_table = $wpdb->prefix . 'actionscheduler_actions';
$logs_table = $wpdb->prefix . 'actionscheduler_logs';
$actions_query = sprintf(
"
SELECT action_id
FROM %s
WHERE status = 'complete'
AND hook = 'wc-admin_import_orders'
LIMIT %s
",
$actions_table,
$limit
);
$action_ids = $wpdb->get_col( $actions_query );
$ids = implode( ',', array_map( 'absint', $action_ids ) );
if ( ! empty( $ids ) ) {
$deleted_logs = $wpdb->query( "DELETE FROM $logs_table WHERE action_id IN ($ids)" );
$deleted_actions = $wpdb->query( "DELETE FROM $actions_table WHERE action_id IN ($ids)" );
}
}
add_action( 'action_scheduler_run_queue', 'clear_woocommerce_scheduled_actions_20200609', 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment