Display cells as dropdown

In this tutorial we will show you how to display a text cell as dropdown, so users can select values between a predefined list.


add_action('vg_sheet_editor/editor/before_init', 'wpse_modify_column_settings', 999);

function wpse_modify_column_settings($editor) {		
  // spreadsheet key. For example, "user" for the users spreadsheet, post, page, or a post type key
  $post_type = 'post';
  // column key that you are editing
  $meta_key = '_expiration-date';
  // Options for the dropdown. The array key is saved in the database and the value is displayed as label for the user.
  $options = array(
     'no' => __('Do not allow', 'woocommerce'),
     'notify' => __('Allow, but notify customer', 'woocommerce'),
     'yes' => __('Allow', 'woocommerce'),

  $editor->args['columns']->register_item($meta_key, $post_type, array(
    'formatted' => array(
        'data' => $meta_key, 
        'editor' => 'select',
        'selectOptions' => $options
  ), true);
Close Menu