Skip to content

Instantly share code, notes, and snippets.

@grola
Created August 1, 2019 10:15
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 grola/b07c66eebdba3a5fc73f8f34f3ecac89 to your computer and use it in GitHub Desktop.
Save grola/b07c66eebdba3a5fc73f8f34f3ecac89 to your computer and use it in GitHub Desktop.
Validate polish postcode
<?php
/**
* Validate polish postcode. "-" is required.
*
* @param bool $valid .
* @param string $postcode .
* @param string $country .
*
* @return bool
*/
function wpdesk_validate_polish_postcode( $valid, $postcode, $country ) {
if ( 'PL' === $country ) {
$valid = (bool) preg_match( '/^([0-9]{2})-([0-9]{3})$/', $postcode );
}
return $valid;
}
add_filter( 'woocommerce_validate_postcode', 'wpdesk_validate_polish_postcode', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment