更新-使用帐单电子邮件添加了客人。
以下非常简单的挂钩函数将检查当前客户是否有任何“暂停”BACS 订单,如果是这种情况,如果当前订单使用 BACS 付款方式,它将显示避免结账的错误消息:
add_action( 'woocommerce_checkout_process', 'action_wc_checkout_process_callback' );
function action_wc_checkout_process_callback() {
if( is_user_logged_in() ) {
// Get customer "on-hold" orders
$orders = (array) wc_get_orders(['limit' => - 1, 'customer_id' => get_current_user_id(),
'status' => 'on-hold', 'return' => 'ids']);
} elseif ( isset($_POST['billing_email']) && ! empty($_POST['billing_email']) ) {
// Get customer "on-hold" orders
$orders = (array) wc_get_orders(['limit' => - 1, 'customer' => sanitize_email($_POST['billing_email']), 'status' => 'on-hold', 'return' => 'ids']);
}
// Check if the current customer has any "on-hold" BACS order and if current order is using BACS as payment method
if ( isset($orders) && count($orders) > 0 && isset($_POST['payment_method']) && $_POST['payment_method'] === 'bacs' ) {
// Display an error notice (and avoid checkout)
wc_add_notice( __( "You have already one order awaiting payment and you can have only one at the time.", "woocommerce" ), 'error' );
}
}
代码位于活动子主题(或活动主题)的 functions.php 文件中。测试和工作。