How to use choices callback feature

Overview


For Ultimate Member 2.1+, please see this documentation.

This doc provides information on how to set up the choices callback feature and display different values or array of values depending on the choice of the user.

Custom function

Please add the following custom function to your child theme's functions.php file. Then add " custom_umwoo_country_list_dropdown" in your custom country dropdown Choices Callback value.

function custom_umwoo_country_list_dropdown() {
	$coutries = array( "FR" => "France", "ES" => "Spain" );
		return $coutries;
        }

Create a new dropdown field e.g. City or States and add your callback function to the Choices callback field.

Here is a function that you can add in your functions.php file to get the states for France(FR) & Spain (ES) & if you select any of these countries from the country field, states automatically show up.

function getStates() {
//get the value from the 'parent' field, sent via the AJAX post.
$choice = $_POST['parent_option'];

//Depending on the value of $choice, return a different array.
switch($choice) {
case "FR":
$states = array(
"Paris" =>"Paris",
"Marseille" => "Marseille",
"Lyon" => "Lyon"
);
break;
case "ES":
$states = array(
"Madrid"=>"Madrid",
"Barcelona"=>"Barcelona"
);
break;
default:
//code to do something if other options are not selected (throw an error, or set $cities to a default array)
$states = array("no state");

}
return $states;

}

*Note: You can’t choose UM predefined country field for the above example, create a new dropdown for your country list as stated above.