add_filter( 'gform_pre_render_3', 'populate_checkbox_vendor' );
add_filter( 'gform_pre_validation_3', 'populate_checkbox_vendor' );
add_filter( 'gform_pre_submission_filter_3', 'populate_checkbox_vendor' );
add_filter( 'gform_admin_pre_render_3', 'populate_checkbox_vendor' );
function populate_checkbox_vendor( $form ) {
foreach( $form['fields'] as &$field ) {
//NOTE: replace 3 with your checkbox field id
$field_id = 39;
if ( $field->id != $field_id ) {
continue;
}
$terms = get_terms(
array(
'taxonomy' => 'vendor-category',
'hide_empty' => false,
)
);
$input_id = 1;
if ( ! empty( $terms ) && is_array( $terms ) ) {
foreach ( $terms as $term ) {
if ( $input_id % 10 == 0 ) {
$input_id++;
}
$choices[] = array( 'text' => $term->name, 'value' => $term->name ); //$term->term_id
$inputs[] = array( 'label' => $term->name, 'id' => "{$field_id}.{$input_id}" );
$input_id++;
}
}
$field->choices = $choices;
$field->inputs = $inputs;
}
return $form;
}
Jagdish Sarma Asked question January 18, 2024