Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MasterHans/00a709b6ca03ea5609eea243dc9c98b5 to your computer and use it in GitHub Desktop.
Save MasterHans/00a709b6ca03ea5609eea243dc9c98b5 to your computer and use it in GitHub Desktop.
woocomerce - add validation on checkout field blur - out of input in JS
add_action( 'wp_footer', 'ybc_javascript_validation' );
function ybc_javascript_validation(){
if( !is_checkout() ) return;
?> <script>jQuery(function($){
$('body').on('blur change', '#billing_birthday', function(){
// alert($(this).val());
var formRow = $(this).parents('.form-row');
// if( /\d/.test( $(this).val() ) ) {
formRow.addClass('woocommerce-invalid');
// } else {
// formRow.addClass('woocommerce-validated');
// }
});
});</script> <?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment