How to Customize Ultimate Member select options

Get access to all plugins for $99 with our All Access Lifetime Suite!

Ultimate Member comes with a few predefined select options for some of the fields. In most cases, these options are enough. However, if you need to customize these options here’s a quick tip on how to customize Ultimate Member select options.

Firstly, you will need to use custom code, so we need to first find a place for the code. If you are using a child-theme then you can the code there. If not, you can create a custom plugin to store these.

 

Adding an extra country to select options

function um_add_extra_countries( $countries = array() ) {
	// Add new countries as options
	$countries['CW'] = __( 'Curacao' );
	$countries['BQ'] = __( 'Bonaire' );

	// Re-arrange array by key.
	ksort( $countries );

	// Return the countries.
	return $countries;	
}
add_filter( 'um_countries_predefined_field_options', 'um_add_extra_countries', 12, 1 );

You can also do something similar to the languages options with the following code

Adding an extra language to select options

function um_add_extra_languages( $languages = array() ) {
	// Add new languages as options
	$languages['pt'] = __( 'Patoi' );

	// Re-arrange array by key.
	ksort( $languages );

	// Return the languages.
	return $languages;
}
add_filter( 'um_languages_predefined_field_options', 'um_add_extra_languages', 12, 1 );

The end result will give you an option as seen in this image
Customize Ultimate Member options shown

Removing a country from Ultimate Member select options

If you would like to remove a country via the code, you can do the following

function um_add_extra_countries( $countries = array() ) {
	// Unset the option from the array
	unset( $countries['AX'] );

	// Return the countries.
	return $countries;	
}
add_filter( 'um_countries_predefined_field_options', 'um_add_extra_countries', 12, 1 );

Looking for a list of keys for the countries and languages, check out the Ultimate Member github class.

The snippets above helps you to customize Ultimate Member select options in the cases where they are predefined. You can also update them via the field settings in UM Forms but with the code, you only have to update them once.

Do you need help with your WordPress site?

Check out our WordPress Services and get the help fast.