title: WooCommerce - Custom stock status and variable products
body: <p>On our site, we're using custom stock statuses for our products. We use the below code to achieve that, and it works, but there are some issues on variable products, where it changes back to the default status.</p>
  
  <p>We want to use it on variable products, to display a main stock status for the whole product, but when we select our custom stock status, it will suddenly change it back to the standard stock status after some time. It saves the setting when we update the product, but it will eventually change it back after some time.</p>
  
  <p>Here is our code, which is placed in our functions.php file. Hope you can help or point me in the right direction:</p>
  
  <pre><code>function add_custom_stock_type() {
      ?&gt;
      &lt;script type="text/javascript"&gt;
      jQuery(function(){
          jQuery('._stock_status_field').not('.custom-stock-status').remove();
      });
      &lt;/script&gt;
  &lt;?php   
  
      woocommerce_wp_select( array( 'id' =&gt; '_stock_status', 'wrapper_class' =&gt; 'custom-stock-status', 'label' =&gt; __( 'Stock status', 'woocommerce' ), 'options' =&gt; array(
          'instock' =&gt; __( 'På lager/fjernlager', 'woocommerce' ),
          'bestillingsvare' =&gt; __( 'Bestillingsvare', 'woocommerce' ), // The new option !!!
          'outofstock' =&gt; __( 'Ikke på lager', 'woocommerce' ),
      ), 'desc_tip' =&gt; true, 'description' =&gt; __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ) ) );
  }
  add_action('woocommerce_product_options_stock_status', 'add_custom_stock_type');
  
  function save_custom_stock_status( $product_id ) {
      update_post_meta( $product_id, '_stock_status', wc_clean( $_POST['_stock_status'] ) );
  }
  add_action('woocommerce_process_product_meta', 'save_custom_stock_status',99,1);
  
  function woo_add_custom_general_fields_save_two( $post_id ){
      // Select
      $woocommerce_select = $_POST['_stock_status'];
      if( !empty( $woocommerce_select ) )
          update_post_meta( $post_id, '_stock_status', esc_attr( $woocommerce_select ) );
      else
      update_post_meta( $post_id, '_stock_status', '' );
      }
  
  function woocommerce_get_custom_availability( $data, $product ) {
      switch( $product-&gt;stock_status ) {
          case 'instock':
              $data = array( 'availability' =&gt; __( 'På lager/fjernlager', 'woocommerce' ), 'class' =&gt; 'in-stock' );
          break;
          case 'bestillingsvare':
              $data = array( 'availability' =&gt; __( 'Bestillingsvare', 'woocommerce' ), 'class' =&gt; 'bestillings-vare' );
          break;
          case 'outofstock':
              $data = array( 'availability' =&gt; __( 'Ikke på lager', 'woocommerce' ), 'class' =&gt; 'out-of-stock' );
          break;
      }
      return $data;
  }
  add_action('woocommerce_get_availability', 'woocommerce_get_custom_availability', 10, 2);
  </code></pre>