Created
January 16, 2020 11:52
-
-
Save plugin-republic/c1030eb31231682df5974fef624131be to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Validate a text string to check first character is a letter and 2nd to 7th characters are numeric | |
*/ | |
function prefix_filter_validate_text_string( $passed, $post, $item ) { | |
// Change the field ID as necessary | |
if( isset( $item['field_id'] ) && $item['field_id'] == 4904 ) { | |
$string = $post[$item['id']]; | |
$first_letter = substr( $string, 0, 1 ); | |
$six_letters = substr( $string, 1, 6 ); | |
if( ! ctype_alpha( $first_letter ) ) { | |
$passed = false; | |
wc_add_notice( apply_filters( 'pewc_filter_validation_notice', esc_html( $item['field_label'] ) . __( ' must have a letter as the first character.', 'pewc' ), $item['field_label'], $item ), 'error' ); | |
} | |
if( ! ctype_digit( $six_letters ) ) { | |
$passed = false; | |
wc_add_notice( apply_filters( 'pewc_filter_validation_notice', esc_html( $item['field_label'] ) . __( ' must have numbers as the second to seventh characters.', 'pewc' ), $item['field_label'], $item ), 'error' ); | |
} | |
} | |
return $passed; | |
} | |
add_filter( 'pewc_filter_validate_cart_item_status', 'prefix_filter_validate_text_string', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment