How to Deny Checkout if User Has Pending Orders in WooCommerce

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 cash flow problem in your business.

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. however, you can increase that number to more than ‘1’  just change the number from ‘0’ to any other number in the 26th line of code for example.

if ( $count > 0 ) {


if ( $count > 1 ) {

in order to deny checkout after 2 pending orders.

Where to add this code?

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.

You may also interested in How to Add Free SSL in WooCommerce with Let’s Encrypt

Leave a Comment