简体   繁体   中英

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.

  • With 05
  • Accept 10 numbers

Validate phone number in woocommerce checkout page

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' ); } }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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