field-select.php 817 Bytes
Newer Older
1
<?php
Varun Sridharan's avatar
Varun Sridharan committed
2 3 4 5 6
/**
 * HTML Select Field Template
 *
 * @author  Varun Sridharan
 * @package WooCommerce Quick Donation/Templates/fields
7
 * @version 0.3
Varun Sridharan's avatar
Varun Sridharan committed
8 9
 */
?>
10

Varun Sridharan's avatar
Varun Sridharan committed
11 12
<select id="<?php echo $id; ?>" name="<?php echo $name; ?>" class="<?php echo $class.' '.$attributes;?>">
<?php
13

14
foreach($project_list as $id => $val){
15
    $attr = '';
16 17 18
    if(is_array($val)){
        $field_output .= ' <optgroup label="'.$id.'">';
        foreach($val as $k =>$v){
19 20 21
			$attr = '';
			if($pre_selected == $k){$attr = 'selected';}
            $field_output .= '<option value="'.$k.'" '.$attr.'>'.$v.'</option>';
22 23 24
        }   
        $field_output .= ' </optgroup>';
    } else {
25
		if($pre_selected == $id){$attr = 'selected';}
26
        $field_output .= '<option value="'.$id.'" '.$attr.'>'.$val.'</option>';
27 28 29
    }
    
}
Varun Sridharan's avatar
Varun Sridharan committed
30 31 32
echo $field_output;
?>
</select>