WooCommerce checks whether users have outstanding orders
WooCommerce is a very popular WordPress mall plug-in. In actual use, after submitting an order, the same user may not complete the payment operation for some reason, and then submit a new order again.
If you want to avoid this problem, you can check whether the current user (determined by the email address) has outstanding orders. If there are, prompt him to log in to the account to complete the payment, as shown in the following figure:

The complete code for implementation is as follows:
/ * *
* @ snippet Deny Checkout to User With Pending Orders | WooCommerce
* @ how-to Get CustomizeWoo.com FREE
* @ sourcecode https://businessbloomer.com/?p=55387
* @ author Rodolfo Melogli
* @ testedwith WooCommerce 3.0.5
, /
Add_action ('woocommerce_after_checkout_validation',' bbloomer_deny_checkout_user_pending_orders')
Function bbloomer_deny_checkout_user_pending_orders ($posted) {
Global $woocommerce
$checkout_email = $posted ['billing_email']
$user = get_user_by ('email', $checkout_email)
If (! Empty ($user)) {
$customer_orders = get_posts (array (
'numberposts' = >-1
'meta_key' = >'_ customer_user'
'meta_value' = > $user- > ID
'post_type' = >' shop_order', / / WP order article type
'post_status' = >' wc-pending' / / get orders that have not been paid
))
Foreach ($customer_orders as $customer_order) {
$count++
}
If ($count > 0) {
Wc_add_notice ('Sorry, please pay your pending orders first by logging into your account',' error')
}
}
}
First get the user ID through the mailbox, and then check whether the user has outstanding orders. If there are, an error prompt will be returned.
Article from: businessbloomer.com/? p=55387, compiled by WordPress University.