Merge pull request #19951 from woocommerce/update/19745

Eircode validation and formatting
This commit is contained in:
Claudiu Lodromanean 2018-05-31 20:31:46 +01:00 committed by GitHub
commit 07bad6975f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -673,8 +673,16 @@ class WC_Checkout {
$data[ $key ] = wc_format_postcode( $data[ $key ], $country );
if ( '' !== $data[ $key ] && ! WC_Validation::is_postcode( $data[ $key ], $country ) ) {
/* translators: %s: field name */
$errors->add( 'validation', sprintf( __( '%s is not a valid postcode / ZIP.', 'woocommerce' ), '<strong>' . esc_html( $field_label ) . '</strong>' ) );
switch ( $country ) {
case 'IE':
/* translators: %1$s: field name, %2$s finder.eircode.ie URL */
$postcode_validation_notice = sprintf( __( '%1$s is not a valid. You can look up the correct Eircode <a target="_blank" href="%2$s">here</a>.', 'woocommerce' ), '<strong>' . esc_html( $field_label ) . '</strong>', 'https://finder.eircode.ie' );
break;
default:
/* translators: %s: field name */
$postcode_validation_notice = sprintf( __( '%s is not a valid postcode / ZIP.', 'woocommerce' ), '<strong>' . esc_html( $field_label ) . '</strong>' );
}
$errors->add( 'validation', apply_filters( 'woocommerce_checkout_postcode_validation_notice', $postcode_validation_notice, $country, $data[ $key ] ) );
}
}

View File

@ -69,6 +69,9 @@ class WC_Validation {
case 'GB':
$valid = self::is_gb_postcode( $postcode );
break;
case 'IE':
$valid = (bool) preg_match( '/([AC-FHKNPRTV-Y]\d{2}|D6W)[0-9AC-FHKNPRTV-Y]{4}/', wc_normalize_postcode( $postcode ) );
break;
case 'JP':
$valid = (bool) preg_match( '/^([0-9]{3})([-])([0-9]{4})$/', $postcode );
break;

View File

@ -900,6 +900,9 @@ function wc_format_postcode( $postcode, $country ) {
case 'GB':
$postcode = trim( substr_replace( $postcode, ' ', -3, 0 ) );
break;
case 'IE':
$postcode = trim( substr_replace( $postcode, ' ', 3, 0 ) );
break;
case 'BR':
case 'PL':
$postcode = substr_replace( $postcode, '-', -3, 0 );