Running heavy tasks on page load slows site. Action Scheduler queues tasks to run in background.
Install: Built into WooCommerce, or install standalone “Action Scheduler” plugin
Schedule Task:
// Schedule single action
as_schedule_single_action(
time() + 3600, // 1 hour from now
'my_custom_hook',
array('user_id' => 123) // Arguments
);
// Schedule recurring action (daily)
as_schedule_recurring_action(
time(),
DAY_IN_SECONDS,
'daily_cleanup_hook'
);
Hook Handler:
add_action('my_custom_hook', function($user_id) {
// Heavy processing here
generate_user_report($user_id);
send_email($user_id);
});
View Queue: Tools → Scheduled Actions
Use Cases: Email sending, report generation, data syncing, cleanup tasks
