Get pluginBuy

Conditional Logic

You can easily configure one field to be displayed depending on the value of another field. Just add show_if parameter.


Conditional meta box in WordPress

In order to create this metabox you can use this code:

add_filter( 'simple_register_metaboxes', 'misha_product_metabox' );
function misha_product_metabox( $metaboxes ) {
	$metaboxes[] = array(
 		'id'	=> 'my_product_metabox',
 		'name'	=> 'Meta Box',
 		'post_type' => array( 'product' ),
 		'fields' => array(
				'id' => 'product_type',
				'label' => 'Product type',
				'type' => 'radio',
				'default' => 'virtual',
				'options' => array(
					'virtual' => 'Virtual',
					'physical' => 'Physical'
				'id' => 'items_in_stock',
				'label' => 'Items in stock',
				'type' => 'number',
				'default' => 1,
				'show_if' => array(
					'id' => 'product_type',
					'value' => 'physical',
	return $metaboxes;

Take a look at this piece:

'show_if' => array(
	'id' => 'product_type', // ID of another field it depends on
	'value' => 'physical', // value of another field
Name Description
id (String) ID of another field the current field depends on. It must be an ID of one of the following field types: checkbox, select or radio.
value (String) Conditional value. If you’re passing a value of a checkbox field, you can use yes and no values.