The Scheduled Actions that sit in WooCommerce Action Scheduler can get stuck with thousands of actions piling up, just stuck in a failed, canceled, pending or complete state. This can result in bloated database tables in particular wp_actionscheduler_actions and wp_actionscheduler_logs tables.

Woocommerce Scheduled Actions

Large number of canceled, failed and completed Scheduled Actions

 

Since the states of failed, canceled or complete are already passed, you would be safe to remove them from the wp_actionscheduler_actions table. You can do so in phpMyadmin SQL tab.

Woocommerce Scheduled Actions Database Table

Removing all canceled actions.

 

Just use the state required in the SQL command…

DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'canceled'
DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'failed'
DELETE FROM `wp_actionscheduler_actions` WHERE `status` = 'complete'

For scheduled actions that are pending you can use the same SQL commands as above just change the status to pending, but you would probably leave these to run in time or if they are overdue then run them from within WooCommerce.

 

Woocommerce Scheduled Actions Pending Run

Run pending actions now

 

wp_actionscheduler_logs Table

If the wp_actionscheduler_logs table is bloated, just empty it.

Woocommerce Scheduled Actions Log Table

Empty the log table

 

Completed Actions

Completed actions are normally removed by the Action Scheduler after 30 days by default but there is a filter that can change that setting  –action_scheduler_retention_period, use it like so in functions.php

add_filter( 'action_scheduler_retention_period', 'wpb_action_scheduler_purge' );
/**
 * Change Action Scheduler default purge to 1 week
 */
function wpb_action_scheduler_purge() {
 return WEEK_IN_SECONDS;
}

Leave a Comment