Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Polish postcode custom validation for Flexible Checkout Field
<?php
/**
* Validate polish postcode.
*
* @param string $field_label .
* @param string $value .
*/
function wpdesk_is_polish_postcode( $field_label, $value ) {
if ( ! ( (bool) preg_match( '/^([0-9]{2})-([0-9]{3})$/', $value ) ) ) {
wc_add_notice( sprintf( '%s nie jest poprawnym kodem pocztowym!', '<strong>' . $field_label . '</strong>' ), 'error' );
}
}
/**
* Add custom FCF validation.
*
* @param array $custom_validation .
*
* @return array
*/
function wpdesk_polish_postcode_custom_validation( $custom_validation ) {
$custom_validation['is_polish_postcode'] = array(
'label' => 'Polski kod pocztowy',
'callback' => 'wpdesk_is_polish_postcode',
);
return $custom_validation;
}
add_filter( 'flexible_checkout_fields_custom_validation', 'wpdesk_polish_postcode_custom_validation' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment