Display cells as dropdown

This tutorial is for developers.

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

Example:

display-cells-as-dropdown

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);
}

Do you need help?

You can receive instant help in the live chat during business hours, or you can contact us and we will help you via email.