extra stock option in woocommerce

Adding extra stock option in Woocommerce

extra stock option in woocommerce

extra stock option in woocommerce

When you need to add an extra stock option in woocommerce i.e. “request to buy” “on request available” etc.  then simply you need to make a tweak. just add this code in functions.php you are done. simple!

/*adding stock option*/

function add_custom_stock_type() {
    <script type="text/javascript">
    woocommerce_wp_select( array( 'id' => '_stock_status', 'wrapper_class' => 'hide_if_variable custom-stock-status', 'label' => __( 'Stock status', 'woocommerce' ), 'options' => array(
        'instock' => __( 'In stock', 'woocommerce' ),
        'outofstock' => __( 'Out of stock', 'woocommerce' ),
        'onrequest' => __( 'Available to Order', 'woocommerce' ), // 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' => 'in-stock' );
        case 'outofstock':
            $data = array( 'availability' => __( 'Out of stock', 'woocommerce' ), 'class' => 'out-of-stock' );
        case 'onrequest':
            $data = array( 'availability' => __( 'Available to Order', 'woocommerce' ), 'class' => 'on-request' );
    return $data;
add_action('woocommerce_get_availability', 'woocommerce_get_custom_availability', 10, 2);

Please note: It only works on simple products, not on variable products.

Update: this code is not working with latest Woocommerce. Please use this plugin.

7 replies
  1. Faustine Tan
    Faustine Tan says:



    You mentioned to use this plugin. I’ve installed it earlier, but it doesn’t allow me to create new stock statuses I need.

    On Preorder & Call us For Availability.

    I tried to use it earlier with addition of custom stock status, but it didn’t link up to Woocommerce’s stock status system.

    Maybe I’m missing something ?



Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *