No Orders! What?
Yesterday morning I woke up to a text message from our client, saying they don’t see any orders in WooCommerce Analytics. This got me worried about site going down or something bad happening which must have led to no orders being received since we finished work day before. I quickly login and check Orders in WordPress Admin and I am relieved to see that website is working fine and we are getting orders consistently. However we had the problem of that data not being reflected in the WooCommerce Analytics, which just showed 0 orders and 0 revenue for the day.
Management relies on WooCommerce Analytics to keep track on online sales so we needed to fix it quickly. Analytics data can’t be calculated in real-time for performance reasons so it’s handled in background using ‘Action Scheduler’, so I check pending actions at WooCommerce > Status > Scheduled Actions and see thousands of pending actions there. Most of these were Mailchimp actions. Somehow all these actions have piled up and since Analytics Data actions are stuck in the queue, they aren’t being processed and instead are waiting for their turn. Now these thousands of actions won’t be processed normally obviously so I had to process them myself.
Action Scheduler
Action Scheduler is a modern replacement for WP-Cron and has an interface in the WP-Admin, so you can always see which tasks got executed, failed or still pending. If you are a plugin developer and need to execute some actions in background, you should definitely use Action Scheduler instead of WP-Cron and if you are using WP-Cron already, it does make sense to migrate to Action Scheduler as this plugin did.
Solution
Thankfully I have WP-CLI to rescue so the first command I run there is:
> wp action-scheduler run --group="wc-admin-data" --force
This executes all the pending actions for analytics data and now Analytics starts showing correct Order count and revenue.
However this only refreshes the figures till now and doesn’t ensure that it will keep refreshing it automatically every few minutes as it should. I had to get rid of all the pending actions obviously. Ofcourse fast and dirty approach would have been to just delete all the pending actions, but it wasn’t a good idea in my opinion as those actions needed to run. So I decide to run Mailchimp actions as well in WP-CLI so I run:
wp action-scheduler run --hook="MailChimp_WooCommerce_Single_Order" --force
Now I come back to WordPress Admin and check the ‘Scheduled Actions’ again, I can now see the pending actions going down slowly. However it was still going to take a long time. So I decide to run another queue in parallel. Again this is possible because I have access to WP-CLI. I just run the above command again. Now it doubles the speed at which pending actions are being run. I don’t take chance to run more queues at this point of time as it could have overwhelmed the server. I let them run and after a few hours all the pending actions have been executed and Analytics data is being generated automatically as it should.
WP-CLI
WP-CLI or WordPress Command-Line Interface lets you do tasks like updating plugins, installing themes on your terminal so it’s a much faster way to do things which you normally do using WordPress Admin.
What caused this?
Ok so anytime you see lots of pending actions in ‘Scheduled Actions’ tab, you will probably find your analytics isn’t working properly. If you server goes down for sometime or if you migrate the server, that could cause this. However in our case it was a silly reason. We need to connect Mailchimp plugin to our Mailchimp account, this enables us to monitor which mail campaign by marketing team is resulting in orders. We had re-connected the Mailchimp a few days ago after realising that it had got disconnected, but in the meanwhile lots of Mailchimp actions couldn’t run and led to this pile of actions. So something like that can also cause this and may not be that obvious to notice at times.
Hope you found this little post helpful and if you are looking for a reliable, prompt and communicative web-agency to create your next e-commerce website or maintain your existing website, you know who to hire, right?