Skip to content
Docs
Get RestroPress

Filter

rpress_is_zip_valid

Updated
On this page

Filters whether a ZIP / postal code is valid for the given country.

Called at the end of the card ZIP validation. The default is true when the country has no pattern defined or the code matches the built-in pattern for that country, and false otherwise. Use it to add rules for countries that have no built-in pattern or to relax existing ones.

Parameters#

ParameterTypeDescription
$retboolResult of the built-in validation.
$zipstring|intThe ZIP / postal code entered.
$country_codestringUpper-case two-letter country code.

Return value#

bool. True if the code is valid.

Example#

function my_validate_irish_eircode( $valid, $zip, $country_code ) {
	if ( 'IE' === $country_code ) {
		return (bool) preg_match( '/^[A-Z0-9]{3}\s?[A-Z0-9]{4}$/i', $zip );
	}
	return $valid;
}
add_filter( 'rpress_is_zip_valid', 'my_validate_irish_eircode', 10, 3 );

Notes#

The function returns false early, without running this filter, when the ZIP or country code is empty.

Source#

Applied in:

  • includes/process-purchase.php (line 1162), in rpress_purchase_form_validate_cc_zip()
Was this page helpful?