我目前有 wordpress/woocommerce 和billing_phone valiation 功能(如下提供),可在 Checkout 中使用。
我需要与寄存器中的前端相同的检查。
我的注册表是自定义的,我以注册的形式添加billing_phone。
add_action('woocommerce_checkout_process', 'user_validate_billing_phone');
function user_validate_billing_phone() {
if ( isset( $_POST['billing_phone'] ) && !empty( $_POST['billing_phone'] ) ) {
if ( !preg_match('/^05[0-9]{8}$/D', str_replace(' ', '', $_POST['billing_phone'] ) ) ) {
// Error: Billing Phone Number is Invalid.
wc_add_notice(__('رقم الجوال غير صحيح', 'woocommerce'));
}
$existing_billing_phone = get_users( 'meta_value=' . str_replace(' ', '', $_POST['billing_phone'] ) );
$current_user = wp_get_current_user();
if ( !empty( $existing_billing_phone ) ) {
if ( $current_user->billing_phone != str_replace(' ', '', $_POST['billing_phone'] ) ) {
// Error: Billing Phone Number Already Exists.
wc_add_notice(__('رقم الجوال مستخدم لحساب اخر', 'woocommerce'));
}
else {
return;
}
}
}
}