• Resolved Robertmurdock

    (@robertmurdock153)


    Hello,

    We are using the country and state fields in the default registration form. We have added the call-back function as per the document guide.

    https://docs.ultimatemember.com/article/1486-how-to-use-choices-callback

    When we register the new user we are facing the below error.

    173.239.214.73:0] PHP Fatal error: Uncaught TypeError: rtrim(): Argument #1 ($string) must be of type string, array given in /nas/content/live/testwebiste/wp-content/plugins/ultimate-member/includes/core/class-fields.php:3321\nStack trace:\n#0 /nas/content/live/testwebiste/wp-content/plugins/ultimate-member/includes/core/class-fields.php(3321): rtrim(Array)\n#1 /nas/content/live/testwebiste/wp-content/plugins/ultimate-member/includes/core/class-fields.php(4191): um\core\Fields->edit_field(‘state_today’, Array)\n#2 /nas/content/live/testwebiste/wp-content/plugins/ultimate-member/includes/core/um-actions-register.php(626): um\core\Fields->display(‘register’, Array)\n#3 /nas/content/live/testwebiste/wp-includes/class-wp-hook.php(308): um_add_register_fields(Array)\n#4 /nas/content/live/testwebiste/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(”, Array)\n#5 /nas/content/live/testwebiste/wp-includes/plugin.php(517): WP_Hook->do_action(Array)\n#6 /nas/content/live/testwebiste/wp-content/plugins/ultimate-member/templates/register.php(75): do_action(‘um_main_registe…’, Array)\n#7 /nas/content/live/testwebiste/wp-content/plugins/ultimate-member/includes/core/class-shortcodes.php(290): include(‘/nas/content/li…’)\n#8 /nas/content/live/testwebiste/wp-content/plugins/ultimate-member/includes/core/class-shortcodes.php(900): um\core\Shortcodes->load_template(‘register’)\n#9 /nas/content/live/testwebiste/wp-content/plugins/ultimate-member/includes/core/class-shortcodes.php(794): um\core\Shortcodes->template_load(‘register’, Array)\n#10 /nas/content/live/testwebiste/wp-content/plugins/ultimate-member/includes/core/class-shortcodes.php(564): um\core\Shortcodes->load(Array)\n#11 /nas/content/live/testwebiste/wp-includes/shortcodes.php(355): um\core\Shortcodes->ultimatemember(Array, ”, ‘ultimatemember’)\n#12 [internal function

    Country:
    https://share.getcloudapp.com/ApuvZZDA
    https://share.getcloudapp.com/P8u2JJ2l

    State:
    https://share.getcloudapp.com/NQuWyyW8
    https://share.getcloudapp.com/JrupKKeZ


    Can you please help us with this?

    Thanks

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • missveronica

    (@missveronicatv)

    @robertmurdock153

    You can try this code snippet:

    function custom_umwoo_country_list_dropdown() {
    
        $countries = WC()->countries->get_countries();
        return $countries;
    }    
    function custom_umwoo_get_states_dropdown() {
    
        $country_code = sanitize_text_field( $_POST['parent_option'] );
        $valid_states = WC()->countries->get_states( $country_code );
    
        return $valid_states;
    }
    Plugin Support Yurii

    (@yuriinalivaiko)

    Hello @robertmurdock153

    This error appears because you use the wrong way to get states. Fix mistakes in your code:

    • use a proper way to get countries array: WC()->countries->get_countries()
    • use a proper way to get states array: WC()->countries->get_states( $cc )

    Try this code:

    function custom_umwoo_country_list_dropdown() {
    	$countries = WC()->countries->get_countries();
    	return $countries;
    }
    function getStates() {
    	if ( ! empty( $_POST['parent_option'] )&& is_string( $_POST['parent_option'] ) ) {
    		$cc     = sanitize_text_field( $_POST['parent_option'] );
    		$states = WC()->countries->get_states( $cc );
    	}
    	return empty( $states ) ? array() : $states;
    }

    Regards

    Plugin Support andrewshu

    (@andrewshu)

    Hi @robertmurdock153

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. 🙂

    Regards

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Dynamic Population fields cause error’ is closed to new replies.