Hi @logaen,
It would go in your functions.php
in your theme or child theme, or a custom plugin file.
Here’s a fully example with what you’ve said above:
/* Add the field */
add_filter('post_age_gate_custom_fields', 'my_custom_fields', 10, 1);
function my_custom_fields($fields)
{
$fields .= sprintf('<label>codice fiscale</label><br /> <input type="text" name="ag_field_codice_fiscale" value="%s" />', age_gate_set_value('ag_field_codice_fiscale'));
$fields .= age_gate_error('ag_field_codice_fiscale');
return $fields;
}
/* validate the field */
add_filter('age_gate_validation', 'my_validation_rules', 10, 1);
function my_validation_rules($rules)
{
return array_merge($rules, [
'ag_field_codice_fiscale' => 'required|min_len,16,max_len,16|alpha_numeric'
]);
}
/* Set the field display name */
add_filter('age_gate_field_names', 'my_field_names', 10, 1);
function my_field_names($names)
{
return array_merge($names, [
'ag_field_codice_fiscale' => "codice fiscale"
]);
}
/* We need to set a message for the alpha_numeric rule */
add_filter('age_gate_validation_messages', 'my_error_messages');
function my_error_messages($messages)
{
return array_merge($messages, [
'validate_alpha_numeric' => 'The {field} field can only contain alpha numeric characters',
]);
}
Thanks
Phil