Hi there,
Yes it’s possible to add your own field types. The first step is to create a custom form field template into your theme. Read here how to create custom templates https://docs.wpusermanager.com/article/87-templates-customization
Once you’ve understood how it works, you can use the existing dropdown field template file for your custom dropdowns https://github.com/WPUserManager/wp-user-manager/blob/master/templates/form-fields/dropdown-field.php of course you’d need to modify it to accept optgroups.
Once you’ve created your new field type, give the file a name ( eg: dropdowngroups-field.php ) and place it into your theme’s wpum templates folder, under the subfolder “form-fields”.
Now, you’ll need to register your custom field within the registration form fields. To do that, you can use this snippet ( add it to your theme’s functions.php file )
function wpum_my_new_field( $fields ) {
$fields['my_field'] = array(
'label' => 'My field',
'type' => 'dropdowngroups',
'description' => 'Description',
'options' => [],
'required' => true,
'priority' => 9999,
);
return $fields;
}
add_filter( 'wpum_get_registration_fields', 'wpum_my_new_field' );
As you can see, I’ve set the type parameter to the name of the form field template file you’ve created, in the example is called ‘dropdowngroups’. These need to match with the file name.
You can now use the “options” parameter to load a custom array that matches the code of your custom field type.
Once you’ve created the field, you need to save the data. To save your data, you’ll need to hook into this action https://github.com/WPUserManager/wp-user-manager/blob/master/includes/wpum-forms/class-wpum-form-registration.php#L443
The action provides access to the user id and all the $values submitted through the form. So you can do everything you want with the data submitted through that field.
Hope this helps!