• I’ve just started working with WordPress and i’m still trying to figure out how some things work. During the developing process i’ve found the necessity of populating an select option (dropdown field) with values that can only be found on an specific wp table (wp_usermeta).
    It should work like this:
    The user has some extra information registered on wp_usermeta on the registration process, they are son_1, son_2. What I wanna do is: when the user select an product, he must define who is the product for (son_1 and son_2) and that information will be necessary to register the purchase itself.
    I’m using the plugin wc_fields_factory to add that select option field to my product page and i’d like to change the plugin to show information from the table instead of default values.
    I’d like to change the funcionality of the plugin instead of creating the field manually in order to use the other functions that that plugin has.
    If some of you could help me with that, i’d be really thankful.
    I couldn’t find much information about it on internet in general.
    Thanks a lot lot

    I’m using wordpress 4.9.3 and woocommerce plugin, with storefront template.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor sarkparanjothi

    (@sarkparanjothi)

    Hi,
    Open wcff-builder.php ( path – plugins/wc-fields-factory/includes/wcff-builder.php )
    paste following line $choices = apply_filters( "wcff_select_option_before_rendering", $choices, $_meta["name"] ); to line number 1108 before that foreach.

    And add following lines of code in your theme function.php

    add_filter( "wcff_select_option_before_rendering", "option_before_render_callback", 10, 2 );
    
    function option_before_render_callback( $option, $field_name ){
    	/* 'user_id' -should give a user ID  */
    	/* 'meta_key' - should give a user meta key  */
    	$metas = get_user_meta( "user_id", "meta_key", false );
    	/* 'select_option' - name of the option field  */
    	if( $field_name == "select_option" ){
    		$option = array();
    		for( $i = 0; $i < sizeof( $metas ); $i++ ){
    			$option[] = $metas[$i]."|".$metas[$i];
    		}
    	}
    	return $option;
    }

    Please rate and review our plugin.

    Thanks.

    Thread Starter luizarusso1

    (@luizarusso1)

    Great, it works perfectly!
    Thanks a lot again!!

    kal123

    (@kal123)

    I will use the above, but would like to prevent son_1 from being selected twice by the user as an attendee name for both tickets.

    Basically, all select choices must be unique.

    Where/how can I best do this validation?

    Thread Starter luizarusso1

    (@luizarusso1)

    is it possible to load it selected once there’s only one option available in the select option?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘select option populated with DB table values’ is closed to new replies.