I need help solving a problem. I am using Ultimate Member plugin for Birth Date validation. I want to check the year the user input from the Data Selection and check to see if they are 13 years or older. I have tried solving it with hooks but it would not allow custom validation on a Date Picker. Here is my code:
add_action('um_submit_form_errors_hook_student_birthdate','um_custom_validate_birthdate', 999, 1);
function um_custom_validate_birthdate( $args ) {
$birthDate = $args['birth_date'];
//explode the date to get month, day and year
$birthDate = explode("/", $birthDate);
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[1], $birthDate[2], $birthDate[0]))) > date("md")
? ((date("Y") - $birthDate[0]) - 1)
: (date("Y") - $birthDate[0]));
if ( isset( $args['birth_date'] ) && $age < 13 ) {
UM()->form()->add_error( 'birth_date', "You must be atleast 13 years old to create an account." );
}
}