Skip to content

Instantly share code, notes, and snippets.

@grola
Created Aug 1, 2019
Embed
What would you like to do?
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