How to know order completed on WooCommerce

Recently, one of my customers wanted to automatically mark an order on WordPress as completed one day after the order.

As you may know, cron-job process in WordPress does not working like cron-jobs in PHP. If you have low amount of visitors, the first visit triggers it. Additionally, some cache plugins may prevent this but our topic is not directly related with this.

In WordPress, you can trigger any function that you want to run by adding “woocommerce_thankyou” action when an order is completed. Well, is this the best solution?

WooCommerce Thank You Page Problem Scenarios

Some payment gateways open a thank you page, place a button on this page and open the payment page as a new page or in pop-up. For example, Redsys. Then, when payment is received, they show a “payment successful” page. On bottom-right part of the page, a small button exists and if your customer doesn’t click on it, your function will not work.

It is the same on Paypal. During payment process with Paypal, if the user closes the page right after he/she completes payment, the page is not displayed.

Cash on Delivery and Money Orders

With cash on delivery and money orders, on the other hand, you can trust woocommerce_thankyou page.

add_action( 'woocommerce_thankyou','wf_recieve_order', 10, 1 );

Payment Gateways With Instant Payments

For Paypal and some credit card payment gateways, we will use payment completed hook. This way, no matter what happens, our function will run if payment is completed.

add_action( 'woocommerce_payment_complete','wf_recieve_order', 10, 2 );

It is really necessary to be careful about delicate matters like payment, otherwise you may encounter serious problems.

Leave a Comment