Created
April 11, 2018 16:27
-
-
Save swoboda/aae2c48aeda05677b029ae17fad884d0 to your computer and use it in GitHub Desktop.
Custom URL Validation for WooCommerce Flexible Checkout Fields
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 | |
// Do NOT include the opening php tag | |
/** | |
* Function to validate the URL | |
* | |
*/ | |
function wpdesk_fcf_validate_url( $field_label, $value ) { | |
if ( filter_var( $value, FILTER_VALIDATE_URL ) == false ) { | |
wc_add_notice( sprintf( '%s is not a valid URL.', '<strong>' . $field_label . '</strong>' ), 'error' ); | |
} | |
} | |
add_filter( 'flexible_checkout_fields_custom_validation', 'wpdesk_fcf_custom_validation_url' ); | |
/** | |
* Add custom URL validation | |
* | |
*/ | |
function wpdesk_fcf_custom_validation_url( $custom_validation ) { | |
$custom_validation['url'] = array( | |
'label' => 'URL', | |
'callback' => 'wpdesk_fcf_validate_url' | |
); | |
return $custom_validation; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment