How to replace the WordPress Cron with a Real Cron job (for batching / combined orders)?

If you have encountered an issue, where you have orders stuck in the “Pending” state and the batching / combined orders mode is turned on, then this guide will help you.

Because WordPress has to work on all sort of different platforms, OS’s and configurations, it can’t trust that there will be a cronjob service on the server that can handle scheduled tasks. A “cron” is simply a scheduled task.

This is why WordPress developers have created a workaround – the wp-cron.php file in your main WordPress folder is executed every time someone loads a page. It then checks if there’s a scheduled task to be done and executes it if necessary.

However, in some cases, this file may become target of a DOS attack, or caching plugins can interfere with its execution which can cause either a lot of server load or the scheduled tasks may not execute properly and timely. This is why, you can substitute this constant file execution with a real cron job.

First, you need to disable the script to be executed every time someone loads one of your pages. To do this, open the wp-config.php file in your main WordPress folder and add the following line before the “/* That’s all, stop editing! Happy blogging. */” line:

define('DISABLE_WP_CRON', true);

Once you do that, you need to setup a real cron job and execute the wp-cron.php file with it. You don’t want to trigger it too often – 30 minutes should be fine for most of the websites. To do this, login to your cPanel and go to the Cron jobs tool located in the Advanced section.

Then, add the following command to be executed every 30 minutes:

wget -q -O - >/dev/null 2>&1

You need to replace with your actual domain name. The Cron jobs tool has some of the most common schedules preset, so you can just select Every 30 minutes from the minutes drop-down and place a “*” symbol in the others.

Otherwise, if you can’t set this up by your own, please, contact us or your hosting company support and ask them to set this Cron job for you.

In addition to the above, we also recommend you to update the “Hold Stock” value in your store. To do this go to WooCommerce > Product > Inventory. Set the hold time to 20 minutes.