Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save webdados/7bde72832a1274f147ac35b9db477bd5 to your computer and use it in GitHub Desktop.
Save webdados/7bde72832a1274f147ac35b9db477bd5 to your computer and use it in GitHub Desktop.
Using the swcbcf_validate_callback_{location}_{field-slug} filter to validate fields on the "Simple Custom Fields for WooCommerce Blocks Checkout" plugin
<?php
// Filter name: swcbcf_validate_callback_{location}_{field-slug}
// {location} can be contact, address or order
// {field-slug} is the field slug
// In this example we're validating a field that needs to be at least 5 chars long
add_filter( 'swcbcf_validate_callback_' . 'order' . '_' . 'how-did-you-get-to-know', function( $return, $value, $field ) {
if ( strlen( trim( $value ) ) < 5 ) {
return 'This field needs to be at least 5 characters long';
}
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment