How to Fix WooCommerce Scheduled Sales That Aren’t Updating
It’s time for yet another fix to a frustrating WooCommerce problem.
A client wanted to setup some one day sales for products in their WooCommerce store. So they went into each product and set a scheduled sale. Here’s an example:
They saved their changed products and waited patiently for midnight to strike on the start date of their sale for the new pricing to become available to their customers.
Midnight came. Nothing happened.
They waited until the morning just in case it was some weird time zone issue. Still nothing happened. The products were all listed at their regular prices.
Frustrated, they logged back in to delete their sale and enter it again just as they had done the day before. Then they saved the products a second time. Magically, their sale prices were now running and everything was working as they wanted.
Of course, what was the point of scheduling the sale if you ultimately had to manual update each product on the sale’s day to get results? To make matters worse, some days the sale prices weren’t being removed from the front end of the site even after the scheduled stop date had come and gone.
I went down a handful of rabbit holes thanks to some bad advice people with similar problems received on a variety of WooCommerce forums and ticket systems. A lot of people blamed other plugins or caching as the culprit for broken scheduled sales but that ended up being a dead end for me.
It eventually became clear this was a problem with WP Cron and WooCommerce’s scheduled tasks. In particular, I had to make some adjustments to the recurrence rate of the woocommerce_scheduled_sales cron event. This event is what triggers the actual pricing changes to the products with scheduled sales.
The best way to examine your sites WP Cron events is by using the excellently named WP Crontrol plugin. This beautiful piece of software lets you see exactly what scheduled events your WordPress install are set to run as well as what time and how often they execute.
Imagine my surprise when I learned the settings for woocommerce_scheduled_sales were telling it to run only once per day at exactly 11 PM.
The flaw here is pretty obvious. If the scheduled sale dates are set to go off at midnight they are never going to execute properly if the event that triggers them is executing itself an hour too early each day.
I changed the event’s recurrence to “Once Hourly” and made sure the next run was set an hour from my edit.
After forcing WP Crontrol to execute the task manually the sale prices on all products immediately began showing correctly.
Why does this happen?
There have been several issues with this client’s WooCommerce install ever since a version rollback from the initial 3.0 release was made. I’m not sure if that’s the culprit as many people have experienced the same issue and have reported it on various tech support boards and forums around the web (and few seem to have found the solution).
WP Cron is generally derided as a poor attempt at running scheduled tasks so maybe the base issue lies there. It depends on visitors to your site to actually initiate the execution of the events while a traditional cron job just runs on the server and fires off when you tell it exactly without waiting for an unrelated website visitor to initiate the call.
In the end, the actual fix is very simple even if the cause isn’t so apparent. Hopefully, if you are experiencing a similar problem with your scheduled sales in WooCommerce this post will help you get your troubles sorted out.
Looking for more help with WooCommerce?
Check out our latest plugin: Remove WooCommerce Features.
With this plugin you can remove and disable dozens of unwanted features that WooCommerce, and your store’s theme, have enabled by default. Turn off specific checkout fields, remove related product listings, hide quantity buttons and much more.