Skip to content

Instantly share code, notes, and snippets.

@vyskoczilova
Last active September 5, 2019 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vyskoczilova/5325c96bf1b4154fd8ec95e153208d25 to your computer and use it in GitHub Desktop.
Save vyskoczilova/5325c96bf1b4154fd8ec95e153208d25 to your computer and use it in GitHub Desktop.
WooCommerce: délka telefonního čísla
<?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