wordpress - 在 woocomerce 中为 billing_phone 添加验证
问题描述
我目前有 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;
}
}
}
}
解决方案
推荐阅读
- powershell - 为什么我的代码在循环之外时没有在“break”之后执行?
- javascript - 使用后退按钮后获取检查值
- webrtc - Gstreamer:到 VP8/webm 录制的 RTP 流不会产生可搜索的文件
- ios - 尝试为 iOS 编译 - Visual Studio for Mac - iPad Pro 12.9 inch (2017) 并选择正确的模拟器进行测试
- javascript - 如何使用 JavaScript 在对象数组中查找值?
- r - R markdown:减少pdf输出文档中两个图之间的空间
- math - 这种编码有名称吗?(位表示从最高到最低有效除以 2)
- vb.net - 从 Access 数据库 vb.net 中删除记录
- c++ - 如何在 C++ 中对两个复杂矩阵求和?
- asp.net-mvc - 如何在没有往返的情况下删除项目