• Resolved bt_dev

    (@biotrace)


    Hello, I am trying to enable the callback feature on registration forms for New Zealand & Australia only. The country dropdown is populating correctly but the state field is unclickable and not populating. I have set country as the parent field in the state dropdown form field and ensured the metakeys are correct. Does anyone have some recommendations or a working example of the callback php code for ultimate member 2.10.3?


    // Filter to override country list
    function custom_umwoo_country_list_dropdown() {
    return array(
    "New Zealand" => "New Zealand",
    "Australia" => "Australia",
    );
    }
    add_filter('um_country_list_filter', 'custom_umwoo_country_list_dropdown');

    // Callback for state list based on selected country
    function custom_umwoo_state_choices_callback() {
    $states_by_country = array(
    "New Zealand" => array(
    "Auckland" => "Auckland",
    "Bay of Plenty" => "Bay of Plenty",
    "Canterbury" => "Canterbury",
    "Gisborne" => "Gisborne",
    "Hawke'’'s Bay" => "Hawke'’'s Bay",
    "Manawatu-Wanganui" => "Manawatu-Wanganui",
    "Marlborough" => "Marlborough",
    "Nelson" => "Nelson",
    "Northland" => "Northland",
    "Otago" => "Otago",
    "Southland" => "Southland",
    "Taranaki" => "Taranaki",
    "Tasman" => "Tasman",
    "Waikato" => "Waikato",
    "Wellington" => "Wellington",
    "West Coast" => "West Coast"
    ),
    "Australia" => array(
    "Australian Capital Territory" => "Australian Capital Territory",
    "New South Wales" => "New South Wales",
    "Northern Territory" => "Northern Territory",
    "Queensland" => "Queensland",
    "South Australia" => "South Australia",
    "Tasmania" => "Tasmania",
    "Victoria" => "Victoria",
    "Western Australia" => "Western Australia"
    )
    );

    $country = isset($_POST['parent_option']) ? sanitize_text_field($_POST['parent_option']) : '';

    $states = isset($states_by_country[$country]) ? $states_by_country[$country] : [];

    $response = [];
    foreach ($states as $key => $label) {
    $response[] = array(
    'value' => $key,
    'label' => $label
    );
    }

    wp_send_json_success($response);
    }

    // Register AJAX callbacks for Ultimate Member (for logged-in and not logged-in users)
    add_action('wp_ajax_um_select_options', 'custom_umwoo_state_choices_callback');
    add_action('wp_ajax_nopriv_um_select_options', 'custom_umwoo_state_choices_callback');
    • This topic was modified 1 year, 1 month ago by bt_dev. Reason: added code tags
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘updating Ultimate Membercallback feature’ is closed to new replies.