I use the following code to add custom stock options to a Woocommerce eshop.
Unfortunately it doesn’t work for variation products.
It works fine for simple products, how can I make it work for variable products too please ?
Woocommerce 2.7.4

I wonder if i was clear enough.
Thank you in advance.

    // ===================  More stock options ============

    function add_custom_stock_type() {
    ?>
    <script type="text/javascript">
    jQuery(function(){
    jQuery('._stock_status_field').not('.custom-stock-status').remove();
    });
    </script>
    <?php   

 woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
    'instock' => __( 'In stock', 'woocommerce' ),
    'outofstock' => __( 'Out of stock', 'woocommerce' ),
    'onrequest' => __( 'On Request', 'storefront' ), // The new option !!!
    'delay1-3' => __( 'Shipping after 1-3 days', 'storefront' ), // The new option !!!
    'delay2-4' => __( 'Shipping after 2-4 days', 'storefront' ), // The new option !!!
    'delay3-5' => __( 'Shipping after 3-5 days', 'storefront' ), // The new option !!!
    'delay5-10' => __( 'Shipping after 5-10 days', 'storefront' ), // The new option !!!

        ), 'desc_tip' => true, 'description' => __( '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 woocommerce_get_custom_availability( $data, $product ) {
        switch( $product->stock_status ) {
            case 'instock':
                $data = array( 'availability' => __( 'In stock', 'woocommerce' ), 'class' => 'instock-availability-mitsos' );
            break;
            case 'outofstock':
                $data = array( 'availability' => __( 'Out of stock', 'woocommerce' ), 'class' => 'outofstock-availability-mitsos' );
            break;
            case 'onrequest':
                $data = array( 'availability' => __( 'On Request', 'storefront' ), 'class' => 'stock-availability-mitsos' );
            break;
            case 'delay1-3':
                $data = array( 'availability' => __( 'Shipping after 1-3 days', 'storefront' ), 'class' => 'stock-availability-mitsos' );
            break;
            case 'delay2-4':
                $data = array( 'availability' => __( 'Shipping after 2-4 days', 'storefront' ), 'class' => 'stock-availability-mitsos' );
            break;
            case 'delay3-5':
                $data = array( 'availability' => __( 'Shipping after 3-5 days', 'storefront' ), 'class' => 'stock-availability-mitsos' );
            break;
            case 'delay5-10':
                $data = array( 'availability' => __( 'Shipping after 5-10 days', 'storefront' ), 'class' => 'stock-availability-mitsos' );
            break;
        }
        return $data;
    }
    add_action('woocommerce_get_availability', 'woocommerce_get_custom_availability', 10, 2);



    add_filter('woocommerce_product_is_in_stock', 'woocommerce_product_is_in_stock_extra_options' );

    function woocommerce_product_is_in_stock_extra_options( $is_in_stock ) {
        global $product;

        if (!$out_of_stock ) {
            $is_in_stock = true;
        }

        return $is_in_stock;
    }
    // ================================================

Read more here: Extra stock options for Woocommerce variation product


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: