WooCommerce: Send Email to Admin Every 3 Hours (Cron Job)

This snippet consists of many WooCommerce tasks: setting up a “WordPress Cron Job” (i.e. schedule a hook that runs on a specific time interval), getting the WooCommerce completed orders from the database, and finally sending a simple email to the store admin.

Complex, but as usual you can simply copy/paste and re-adapt it to your unique specifications. For example, I’m using it to send a survey email to each customer who has placed an order. There are thousands of applications, so this is just the start. Enjoy!

Setting up custom Cron Jobs in WooCommerce / WordPress

Snippet (PHP): Set up a Cron Job to Send WooCommerce Completed Orders to Admin Every 3 Hours

As I wrote in the introduction, there are 3 distinct code sections: the one where I create and schedule the cron job every 3 hours, the one where I query the database for completed orders in the last 3 hours, and the one where I generate the email.

To view and debug cron jobs in WordPress, I use “Advanced Cron Manager” from WordPress.org: https://wordpress.org/plugins/advanced-cron-manager/. Please note cron jobs won’t run unless there is frequent website traffic – otherwise it is advised to set them up via your hosting cPanel.