Check Greek postcodes at checkout
For addresses in Greece, the checkout accepts only valid 5-digit postcodes (10000 to 85999, with or without a space).
<?php
add_action(
'woocommerce_after_checkout_validation',
static function ( $data, $errors ) {
foreach ( array( 'billing', 'shipping' ) as $type ) {
if ( 'shipping' === $type && empty( $data['ship_to_different_address'] ) ) {
continue;
}
if ( 'GR' !== ( $data[ $type . '_country' ] ?? '' ) ) {
continue;
}
$postcode = preg_replace( '/\s+/', '', (string) ( $data[ $type . '_postcode' ] ?? '' ) );
if ( '' !== $postcode && ! preg_match( '/^[1-8]\d{4}$/', $postcode ) ) {
$errors->add( 'validation', 'Ο ταχυδρομικός κώδικας πρέπει να έχει 5 ψηφία, π.χ. 57001.' );
}
}
},
10,
2
);
Good to know
For the classic checkout.
In these packs
- Greek e-shop: For shops in Greece: receipt or invoice with a checked VAT number (ΑΦΜ), Greek phone and postcode checks, a cash on delivery fee, and greeklish addresses.