简体   繁体   English

验证 WooCommerce 中的电话号码

[英]Validate phone number in WooCommerce

I would like to add custom validation to the phone number (billing_phone) on the checkout page and the register page.我想在结帐页面和注册页面上为电话号码 (billing_phone) 添加自定义验证。

  • With 05带05
  • Accept 10 numbers接受 10 个号码

Validate phone number in woocommerce checkout page验证 woocommerce 结帐页面中的电话号码

Just Check I hope it works只是检查我希望它有效

 add_filter('woocommerce_process_registration_errors','custom_validate_billing_phone',10, 4 ) add_action( "woocommerce_after_save_address_validation",'custom_validate_billing_phone',1,2); add_action('woocommerce_checkout_process', 'custom_validate_billing_phone'); function custom_validate_billing_phone() { $is_correct = preg_match('/^05[0-9]{8}$/', $_POST['billing_phone']); if ( $_POST['billing_phone'] &&.$is_correct) { wc_add_notice( __( 'The Phone field should be <strong>start 05 and 10 digits</strong>,' ); 'error' ); } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM