Filter

Add Options to Toolset Checkboxes Field

This is an unofficial filter, not documented, but works, whereas the documented does not.

It allows you to programmatically populate a Toolset Types Checkboxes Field.

//filter wpcf_fields_{field-type}_meta_data
//$field_options (options array of field)
//$field (whole field array)
add_filter( 'wpcf_fields_checkboxes_meta_data', 'add_options_to_checkboxes', 10, 2 );

function add_options_to_checkboxes($field_options,$field){
	
	//$options array() 
	//key = option unique ID and 
	//value = arrray() of options settings
	//Of course in real life you generate this, maybe using user data, or post data, whatever you want to add as options to your field
	$options = array(

		//array key used as unique ID of each option
		'option_one' => array( 
			'title' => 'Checkbox 2',//The option title
			'set_value' => '1',//value to save if set
			'display'	=> 'db',//value to display if set
			'display_value_not_selected' =>  '',//value to display if not selected custom
			'display_value_selected' => ''//value to display if selected custom
		),

		'option_two' => array( 
			'title' => 'Checkbox 3',
			'set_value' => '1',
			'display'	=> 'db',
			'display_value_not_selected' =>  '',
			'display_value_selected' => ''
		)

	);

	if ($field['name'] == 'My Checkboxes Field') {//Change to your custom field Name (not slug)
		foreach ($options as $key => $value) {
			$option_slug = 'wpcf-fields-checkboxes-option-' . md5($key);
			if (!in_array($option_slug, $field_options['options'])) {
				$field_options['options'][$option_slug] = $value;	
			}	
		}
	}
	return $field_options;
}