Skip to main content

WordPress Cron & Scheduled Tasks

WordPress uses a pseudo-cron system that relies on site visits to trigger scheduled tasks. WooCommerce Appointments uses WooCommerce's ActionScheduler (built on WordPress cron) to handle time-sensitive operations like email reminders and follow-ups.

How WordPress Cron Works

WordPress cron is not a true cron system. Instead:

  1. Pseudo-cron: Tasks are scheduled but only run when someone visits your site
  2. Page load trigger: Each page load checks if any scheduled tasks are due
  3. Background execution: Tasks run in the background after the page loads

The Problem

WordPress cron is unreliable by default because:

  • Tasks only run when someone visits your site
  • Low-traffic sites may miss scheduled tasks
  • High-traffic sites may experience delays
  • Tasks can be skipped if no one visits during the scheduled time

WooCommerce ActionScheduler

WooCommerce Appointments uses ActionScheduler, a more robust scheduling system built on WordPress cron that:

  • Stores scheduled tasks in the database
  • Provides better error handling and retry logic
  • Allows viewing and managing scheduled tasks
  • Still relies on WordPress cron to execute tasks

How Appointments Plugin Uses ActionScheduler

The plugin schedules several types of tasks:

Appointment Reminders

  • Scheduled X hours/days before the appointment start time
  • Configured in WooCommerce → Settings → Emails → Appointment Reminder
  • Action: wc-appointment-reminder

Appointment Completion

  • Scheduled at the appointment end time
  • Marks appointments as complete automatically
  • Action: wc-appointment-complete

Follow-up Emails

  • Scheduled X hours/days after the appointment end time
  • Configured in WooCommerce → Settings → Emails → Appointment Follow-up
  • Action: wc-appointment-follow-up

Daily Cleanup

  • Removes old in-cart appointments
  • Cleans up expired availability rules
  • Runs once per day
  • Action: woocommerce_appointments_daily_cleanup

Inactive Cart Removal

  • Removes appointments left in cart after the hold period
  • Action: wc-appointment-remove-inactive-cart

Making Cron Reliable

To ensure scheduled tasks run on time, you need to set up a real cron job that triggers WordPress cron independently of site visits.

Set up a system cron job that runs every minute (or every 5 minutes) to trigger WordPress cron:

For cPanel/Shared Hosting

  1. Log into your hosting control panel (cPanel, Plesk, etc.)
  2. Navigate to Cron Jobs or Scheduled Tasks
  3. Add a new cron job with these settings:
    • Frequency: Every minute (* * * * *)
    • Command:
      /usr/bin/php -q /path/to/your/site/wp-cron.php
    • Or using wget:
      wget -q -O - https://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
    • Or using curl:
      curl -s https://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

For VPS/Dedicated Server (Linux)

  1. SSH into your server
  2. Edit the crontab:
    crontab -e
  3. Add this line (runs every minute):
    * * * * * /usr/bin/php -q /path/to/your/site/wp-cron.php
    Or using wget:
    * * * * * wget -q -O - https://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

Finding Your Site Path

The path to wp-cron.php is typically:

/home/username/public_html/wp-cron.php

or

/var/www/html/wp-cron.php

Replace username and adjust the path based on your hosting setup.

Option 2: Disable WordPress Cron (Advanced)

If you're using a real cron job, you can disable WordPress's pseudo-cron to prevent duplicate executions:

  1. Add this to your wp-config.php file (before the "That's all, stop editing!" line):
    define('DISABLE_WP_CRON', true);
  2. Set up the server-level cron job as described in Option 1
warning

Only disable WordPress cron if you've set up a real cron job. Otherwise, scheduled tasks will never run.

Option 3: Using a Plugin

Several plugins can help manage WordPress cron:

  • WP Crontrol: View and manage cron events
  • Advanced Cron Manager: More advanced cron management
  • Action Scheduler: View ActionScheduler tasks (comes with WooCommerce)

These plugins help you monitor cron but don't make it more reliable—you still need a real cron job.

Verifying Cron is Working

Check ActionScheduler Status

  1. Install the Action Scheduler plugin (if not already installed with WooCommerce)
  2. Go to Tools → Scheduled Actions in WordPress admin
  3. Look for tasks like:
    • wc-appointment-reminder
    • wc-appointment-follow-up
    • woocommerce_appointments_daily_cleanup

Check Cron Execution

  1. Install WP Crontrol plugin
  2. Go to Tools → Cron Events
  3. Verify that wp_schedule_event and action_scheduler_run_queue are running regularly

Test Email Reminders

  1. Create a test appointment scheduled for tomorrow
  2. Set reminder time to "1 hour" before appointment
  3. Wait and verify the reminder email is sent exactly 1 hour before

Troubleshooting

Reminders Not Sending

  1. Check cron is running: Verify your server cron job is active
  2. Check email settings: Ensure reminder emails are enabled in WooCommerce settings
  3. Check ActionScheduler: View scheduled actions to see if reminders are queued
  4. Check server logs: Look for PHP errors that might prevent execution

Tasks Running Late

  • Low traffic: If your site has low traffic, tasks may be delayed until someone visits
  • Solution: Set up a real cron job (see Option 1 above)

Duplicate Tasks

  • Multiple cron triggers: If both WordPress cron and server cron are active, tasks might run twice
  • Solution: Disable WordPress cron (DISABLE_WP_CRON) and use only server cron

Best Practices

  1. Always use a real cron job for production sites
  2. Monitor scheduled tasks regularly using Action Scheduler
  3. Test email reminders after setting up cron
  4. Keep backups of your cron configuration
  5. Document your cron setup for your team

Summary

  • WordPress cron is unreliable by default (requires site visits)
  • WooCommerce Appointments uses ActionScheduler for better task management
  • Set up a real server cron job to ensure tasks run on time
  • Monitor scheduled tasks using Action Scheduler or WP Crontrol
  • Test your setup to verify reminders and follow-ups work correctly

For appointment-based businesses, reliable cron is essential to ensure customers receive timely reminders and follow-up communications.