deny checkout if user has pending orders woocommerce

Deny Checkout if User Has Pending Orders

Does it happen with you all the time that customers place an order but don’t pay for the order – i.e, Order received (unpaid).

This is more painful if you are a wholesaler and allow customers to pay cash on delivery(COD) or via cheque but never receive any payment which can cause a cash flow problem in your business.

What does Pending Order means in WooCommerce?

Pending order means that order has been created by the user, but the payment hasn’t been received yet.

For example, it could mean the user has reached the PayPal screen, but not proceeded. In rare circumstances, it may mean that PayPal was not able to communicate back to your website to say payment has been processed, so you should check your PayPal account / PayPal emails too.

You can read more about order status on woocommerce docomentation.

How to  deny checkout until they pay for the previous orders

It’s easy, add below  PHP code in your theme fuction.php file.

Above code will deny check out if the user has one pending order.

owever, you can increase the number pending order to more than ‘1’  by changing the number from ‘0’ to any other number in the 26th line of code for example.

replace

if ( $count > 0 ) {

with

if ( $count > 1 ) {

Keep in mind that in most of proggraming including php counting starts from 0 instead of 1

You can place PHP snippets at the bottom of your functions.php file, We recommend to use child them so you will not lose any changes when updating your theme  –

Did this snippet work?

Please let us know in the comments if snippet worked as expected. We would be happy to revise the code if you report otherwise or in case you need more assistance.

3 Comments

  1. Thank you so much for this useful code.
    I activate the Digits plugin in my website and by default the customer ID is them phone number (phone number is required instead of email address).
    Would you please tell me how can I change this code for this situation?
    Thanks a lot

    • Hello Mohammad, I never used the Digits plugin and quick Google search indicate it’s a premium plugin, I can’t look into its code. The best way is to get in touch with the plugin developer.

Leave a Reply

Your email address will not be published. Required fields are marked *