WooCommerce: Resolving WP Cron Issues with Pending Tasks

clock, wrist watch, timepiece, fossil, leather, bronze, chrono, chronograph, stopwatch, noble

In a recent Business Bloomer Club Slack thread, a user reported a situation where WP Cron was disabled for an unknown reason, causing WooCommerce database updates to not run after plugin updates. As a result, the site had accumulated over 1000 pending tasks. The user was seeking guidance on the best course of action to resolve this issue and ensure that the tasks were properly executed.

WP Cron is an essential part of WordPress that handles scheduling various tasks, such as database updates, sending emails, and other time-sensitive actions. WooCommerce, like many plugins, relies on WP Cron to perform routine updates and maintenance tasks. When WP Cron is disabled, tasks scheduled by plugins, including WooCommerce updates, will be left pending, potentially causing issues with the site’s functionality and performance.

Understanding WP Cron and Its Importance

WP Cron is a feature of WordPress that simulates a cron job, which is typically used to automate tasks at regular intervals. However, unlike a real cron job, WP Cron is triggered when someone visits the website, meaning it only runs when there is traffic on the site. This can sometimes lead to delays or missed tasks, especially on low-traffic sites where WP Cron might not trigger frequently enough.

When WP Cron is disabled, tasks such as scheduled posts, plugin updates, and WooCommerce database updates won’t run as expected. In the case of WooCommerce, this could affect important operations such as inventory updates, order status changes, or automatic stock syncing. If the cron jobs are disabled for too long, it could lead to a backlog of tasks, as the user in the thread experienced, with over 1000 pending tasks.

Enabling WP Cron

The first suggested course of action in the thread was to enable WP Cron. This can often be done by simply modifying the WordPress configuration files or adjusting settings in the WordPress dashboard. Enabling WP Cron allows the tasks to be triggered again, and the pending jobs will start running.

Checking wp-config.php

In some cases, WP Cron can be disabled manually via the wp-config.php file, which is located in the root of your WordPress installation. To check whether WP Cron has been disabled, you can look for the following line in the wp-config.php file:

define('DISABLE_WP_CRON', true);

If this line is present and set to true, WP Cron will be disabled. To enable it, simply change the value to false or remove the line entirely.

define('DISABLE_WP_CRON', false);

Using WordPress Dashboard

In some cases, WP Cron might be disabled through plugin settings or server configurations. To check if WP Cron is enabled via the WordPress dashboard, you can install plugins like WP Crontrol, which provide a user-friendly interface to view, manage, and edit cron jobs in WordPress. Once WP Cron is enabled, the tasks should start running automatically.

Using a Real Cron Job

If enabling WP Cron does not resolve the issue or if you want to ensure more reliable execution of scheduled tasks, another option is to set up a real cron job. A real cron job is server-level scheduling, which runs independently of website traffic and can be triggered at specific intervals, ensuring that tasks are completed on time.

A real cron job is more reliable than WP Cron, especially for high-traffic websites or sites with many pending tasks. By setting up a cron job through your hosting control panel, you can bypass the need for website visitors to trigger the cron job and ensure that tasks are processed regularly, regardless of site traffic.

Rodolfo suggested setting up a real cron job via the hosting control panel. This can be done by following the instructions in this Cloudways blog article, which offers detailed steps for configuring a real cron job. Setting up a cron job on the server allows tasks like WooCommerce updates to be processed reliably without waiting for site traffic to trigger WP Cron.

Steps to Set Up a Real Cron Job

  1. Access Hosting Control Panel: Log in to your hosting account’s control panel, such as cPanel or Cloudways. Find the section related to cron jobs.
  2. Create a New Cron Job: In the cron job management section, create a new cron job. You’ll need to define the frequency at which you want the cron job to run (e.g., every 15 minutes).
  3. Set the Command: The command for running the WordPress cron job usually looks like this: wget -q -O - https://yourwebsite.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1 This command tells the server to run the wp-cron.php script at the specified intervals. The -q flag ensures that the process runs quietly without output, and > /dev/null 2>&1 ensures that any errors are discarded.
  4. Test the Cron Job: After setting up the cron job, test it by checking if the scheduled tasks in WordPress begin to run. You can monitor this through plugins like WP Crontrol or by checking the WooCommerce system status to see if the database updates are being applied.

Conclusion

Once WP Cron is enabled or a real cron job is set up, the pending tasks will start running in order from oldest to newest. It’s important to monitor the site closely after enabling cron jobs to ensure that all tasks are processed properly. In the case of over 1000 pending tasks, this could take some time, but once all the tasks have been processed, the site should return to normal operation.

Ensuring that WP Cron is enabled and functioning properly is essential for maintaining the smooth operation of WooCommerce and other WordPress plugins. Setting up a real cron job can further enhance reliability, especially for sites with many scheduled tasks or high traffic.

By following these steps, you can quickly resolve WP Cron issues, manage pending tasks, and keep your WooCommerce store running smoothly.

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Reply

Your email address will not be published. Required fields are marked *