Created
July 11, 2018 07:28
-
-
Save freezvd/0ede99079e5e2e4e2aeb5401d4789a9c to your computer and use it in GitHub Desktop.
WooCommerce: Deny customer checkout if pending order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('woocommerce_before_checkout_form', 'loc_deny_checkout_user_pending_orders'); | |
function loc_deny_checkout_user_pending_orders( $posted ) { | |
global $woocommerce; | |
$customer = wp_get_current_user(); | |
if (!empty($customer)) { | |
$customer_orders = get_posts( | |
array( | |
'numberposts' => -1, | |
'meta_key' => '_customer_user', | |
'meta_value' => $customer->ID, | |
'post_type' => 'shop_order', | |
'post_status' => 'wc-pending' | |
) | |
); | |
if ( count($customer_orders) > 0 ) { | |
wc_add_notice('Hi!<br>We really love the fact that you\'ve come back to our store - it means the world to us.<br>With that said, we cannot (unfortunately) process this order until you have paid your outstanding balance.<br>For more information on how to pay, please go to your account and "Orders".', 'error'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment