Skip to content

Instantly share code, notes, and snippets.

@grola
Created February 8, 2018 09:29
Show Gist options
  • Save grola/37da10fa228fcecab0df85a24c7b68d0 to your computer and use it in GitHub Desktop.
Save grola/37da10fa228fcecab0df85a24c7b68d0 to your computer and use it in GitHub Desktop.
Flexible Checkout Fields - custom validation method
<?php // do not copy this line if already opened <?php tag
function example_function_is_integer( $field_label, $value ) {
if ( ! ( (is_numeric($value) ? intval($value) == $value : false) ) ) {
wc_add_notice( sprintf( '%s is not integer!', '<strong>' . $field_label . '</strong>' ), 'error' );
}
}
add_filter( 'flexible_checkout_fields_custom_validation', 'example_flexible_checkout_fields_custom_validation' );
function example_flexible_checkout_fields_custom_validation( $custom_validation ) {
$custom_validation['is_integer'] = array(
'label' => 'Is integer',
'callback' => 'example_function_is_integer'
);
return $custom_validation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment