• Resolved jasonjonesbuild

    (@jasonjonesbuild)


    Hi. I’ve been trying to implement dynamic dropdown custom options with the filter you’ve provided:
    add_filter( ‘cf7sg_dynamic_dropdown_custom_options’,’dynamic_select_000_dynamic_options’,10,3);.

    So far, I haven’t been able to make it work.

    Can you help me?

    Here is how I did it:

    I’ve tried it in two different ways:

    First method: Setup Data through hard-code

    
    $data = array(
        "group_label"  => array(
        			"group_optionss" => array(
    				    		"label1" => "value1",
    				    		"label2" => "value2",
    				    		"label3" => "value3",
    				    		)
        			)
      );
    foreach($data as $group_label=>$group_opts){
        $options .= '<optgroup label="'.$group_label.'">';
        foreach($group_opts as $label=>$value){
          $options .= '<option value="'.$value.'">'.$label.'</option>';
        }
        $options .= '</optgroup>';
      }
    return $options;
    

    Second method: Use options directly

    
    $options .= '<optgroup label="group_label">';
    $options .= '<option value="value1">label1</option>';
    $options .= '<option value="value2">label2</option>';
    $options .= '<option value="value3">label3</option>';
    $options .= '</optgroup>';
    return $options;
    

    Honestly, I thought it was gonna work on the second method. Can you help me implement your filter code for dynamic dropdown custom options?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    your code looks fine. The only reason I can think that it’s no working is because the filter function isn’t being called.

    the filter helper code includes 2 checks on the form unique key and the field name, for example,

    if('test-accordion'!==$cf7_key || 'my-list' !== $name){
        return $options;
      }

    hence if either the form key or field name has changed, the function returns an empty set of options.

    can you check that you function is being properly called (write something to your debug log file for example);

    Thread Starter jasonjonesbuild

    (@jasonjonesbuild)

    Thanks for the quick response.

    Yes, I have the filter function set up already. However I dont know if it’s being called. What do I write on the debug log file and where can I see if its being called?

    Plugin Author Aurovrata Venet

    (@aurovrata)

    However I dont know if it’s being called. What do I write on the debug log file and where can I see if its being called?

    you’ll need to read up on debugging in WordPress, and enabling your debug.log file.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    I am marking this as resolved since I have not heard back from you

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

The topic ‘Dynamic Dropdown Custom Options’ is closed to new replies.