Created
December 17, 2021 00:21
-
-
Save Kodzhesyan/3f4bec080e949401d21b8134a7b023c9 to your computer and use it in GitHub Desktop.
Custom validation for Billing Phone checkout field - WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Custom validation for Billing Phone checkout field | |
add_action('woocommerce_checkout_process', 'custom_validate_billing_phone'); | |
function custom_validate_billing_phone() { | |
$is_correct = preg_match('/^[0-9]{10}$/', $_POST['billing_phone']); | |
if ( $_POST['billing_phone'] && !$is_correct) { | |
wc_add_notice( __( 'Напишите правильно свой номер телефона.<strong>Он должен состоять только из 10 цифр</strong>. Например: <strong>0990603439</strong>' ), 'error' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment