Last active
June 2, 2025 17:33
-
-
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
This file contains hidden or 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 | |
// Filter name: swcbcf_validate_callback_{location}_{field-slug} | |
// {location} can be contact, address or order | |
// {field-slug} is the field slug | |
// This needs to be done at a plugin level, before woocommerce_init priority 10 | |
// 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