title: Multi Select fields in Woocommerce backend
body: <p>I am trying to create 4 multi-select options at Woocommerce product variations. </p>
  
  <p>For example: I am selling trees and want to display the season the tree is available. So we have 4 seasons (spring, summer, autumn, winter), Some trees are available in two or tree seasons.</p>
  
  <p>I added this code to my functions.php, but it won't save the selected options. When i save the option and reload the page the options are blank again. </p>
  
  <p>And I was also wondering how to show the selected options on the single product page (frontend) as icon.</p>
  
  <p>For now the function with the options works at the product variations. Please see this screenshot <em>(product variation with multi select options)</em>:</p>
  
  <p><a href="https://i.stack.imgur.com/33R78.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/33R78.png" alt="image product variation with multi select options"></a></p>
  
  <p>My code:</p>
  
  <pre><code>// Add Variation Settings
  add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 );
  
  /**
   * Create custom field type
   *
  */
  function woocommerce_wp_select_multiple( $field ) {
      global $thepostid, $post, $woocommerce;
  
      $thepostid              = empty( $thepostid ) ? $post-&gt;ID : $thepostid;
      $field['class']         = isset( $field['class'] ) ? $field['class'] : 'select short';
      $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
      $field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
      $field['value']         = isset( $field['value'] ) ? $field['value'] : ( get_post_meta( $thepostid, $field['id'], true ) ? get_post_meta( $thepostid, $field['id'], true ) : array() );
  
      echo '&lt;p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"&gt;&lt;label for="' . esc_attr( $field['id'] ) . '"&gt;' . wp_kses_post( $field['label'] ) . '&lt;/label&gt;&lt;select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['name'] ) . '" class="' . esc_attr( $field['class'] ) . '" multiple="multiple"&gt;';
  
      foreach ( $field['options'] as $key =&gt; $value ) {
  
          echo '&lt;option value="' . esc_attr( $key ) . '" ' . ( in_array( $key, $field['value'] ) ? 'selected="selected"' : '' ) . '&gt;' . esc_html( $value ) . '&lt;/option&gt;';
  
      }
  
      echo '&lt;/select&gt; ';
  
      if ( ! empty( $field['description'] ) ) {
  
          if ( isset( $field['desc_tip'] ) &amp;&amp; false !== $field['desc_tip'] ) {
              echo '&lt;img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()-&gt;plugin_url() ) . '/assets/images/help.png" height="16" width="16" /&gt;';
          } else {
              echo '&lt;span class="description"&gt;' . wp_kses_post( $field['description'] ) . '&lt;/span&gt;';
          }
  
      }
      echo '&lt;/p&gt;';
  }
  
  
  /**
   * Create new fields for variations
   *
  */
  function variation_settings_fields( $loop, $variation_data, $variation ) {
  
      woocommerce_wp_select_multiple( array(
          'id' =&gt; 'season_' . $variation-&gt;ID,
          'class' =&gt; 'season',
          'label' =&gt; __('Season', 'woocommerce'),
          'value' =&gt; get_post_meta( $variation-&gt;ID, '_season', true ),
          'options' =&gt; array(
              'spring' =&gt; 'Spring',
              'summer' =&gt; 'Summer',
              'autumn' =&gt; 'Autumn',
              'winter' =&gt; 'Winter',
          ))
      );
  }
  
  add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 );
  function save_variation_settings_fields( $post_id ) {
  
      $select = $_POST["season_$post_id"];
      if( ! empty( $select ) ) {
          update_post_meta( $post_id, '_season', esc_attr( $select ) );
      }
  }   
  </code></pre>