Keep Completed Background Tasks for 7 Days
Shortens how long WooCommerce's Action Scheduler keeps finished tasks from 31 days to 7, which keeps its database tables small on busy stores.
Opens WPIDE on
Code
$wpide_as_retention_days = 7; // Days to keep completed actions.
add_filter( 'action_scheduler_retention_period', function () use ( $wpide_as_retention_days ) {
return $wpide_as_retention_days * DAY_IN_SECONDS;
} );
Notes
Only completed and cancelled actions are cleared, gradually by Action Scheduler itself, and pending tasks are never touched.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.