Prevent the checkout process if the customer has pending payments
Sometimes customers might leave some orders unpaid, perhaps from their card being declined, payment processing errors and many other reasons. You have the ability as a WooCommerce based store owner to prevent them from placing additional orders until they settle their outstanding ones. This can prevent your order queue from being cluttered and minimize illegitimate orders.
Install and activate a child theme
The first step on our process here is to create and install a child theme. If you are using one of our themes you can easily grab its child theme from our downloads section. If not, you can read our beginner’s guide on child themes to create your own. This step is essential in order to preserve our changes throughout theme updates.
Blocking checkout if outstanding payments are found
To add our check for pending payments we will use the woocommerce_checkout_process hook and use it to look for pending payment orders on the customer’s history.
Let’s break things down a bit. We start by getting the current user to find out which customer is making the order. If the current user exists, i.e. it is a returning customer we get all their pending orders using wc_get_orders and if we find any we create a WooCommerce notice which informs the customer that they have pending payments under their user account, the notice prompts the customer to take care of these pending payments and provides them with links to both their my account page and to each order’s payment URL directly. This way they can sort the payments out and be able to place new ones on the store.
Wrapping up
With this simple snippet we managed to prevent any users with outstanding payments from placing additional ones until they take care of their balance. Did you find this tutorial useful? Please let us know in the comments below.
6 responses to “Prevent the checkout process if the customer has pending payments”
Re-ordering protection without paying for the previous one is a good idea! Unfortunately this snippet doesn’t work. Where can be an error? Maybe because of the woocommerce update?
Hello.
I have just tested the plugin and it seems to be working fine, as long as there is an order with the “Pending payment” status, the checkout process will not continue. You can include orders which are On Hold in the process by changing line 8 to
'status' => array( 'wc-pending', 'wc-on-hold' ),
for a broader application of the rule.Hi,
Code not display true.
Best regards.
Hello.
Could you please let us know exactly what issue did you face with the guide?
Thank you.
Hello
Would it be possible to suspend the purchase process if the customer has a pending payment of an amount equal to or greater than a certain amount?
Hello Alexander.
It should be possible. In the foreach loop in lines 16-18 you could get the price of each pending order, compare it to a preset amount and if it satisfies your condition only then add it to the blocking orders.