Last active
September 5, 2019 09:52
-
-
Save vyskoczilova/5325c96bf1b4154fd8ec95e153208d25 to your computer and use it in GitHub Desktop.
WooCommerce: délka telefonního čísla
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
<?php // nekopírujte tento řádek | |
/** | |
* @snippet WooCommerce: Minimální délka telefonního čísla | |
* @author Karolína Vyskočilová (https://kybernaut.cz) | |
* @testedwith WordPress 5.2 & WooCommmerce 3.7.0 | |
*/ | |
// ------------------- | |
function my_theme_validate_phone( $fields, $errors ){ | |
// Mild phone check, min 9 numbers | |
if ( ! preg_match('/^[+]?[0-9. -]{9,}$/', $fields['billing_phone']) && !empty( $fields['billing_phone'] ) ) { | |
$errors->add( 'validation', __( '<strong>Telefonní číslo</strong> není platné.', 'my-theme' ) ); | |
} | |
} | |
add_action( 'woocommerce_after_checkout_validation', 'my_theme_validate_phone', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment