Created
February 8, 2018 09:29
-
-
Save grola/37da10fa228fcecab0df85a24c7b68d0 to your computer and use it in GitHub Desktop.
Flexible Checkout Fields - custom validation method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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