Using Float Quantity in Order Menu

I am trying to allow the usage of decimal quantities in the admin panel.

I had added the following code:

remove_filter( 'woocommerce_stock_amount', 'intval' );
add_filter( 'woocommerce_stock_amount', 'floatval' );

But when I edit the order and try to change the quantity to decimals, after hitting update order, nothing happens and the following error comes in the console:

An invalid form control with name='order_item_qty[328]' is not focusable.

(328 is the item I Tried to edit)

Any solutions for this?

1 answer

  • answered 2021-05-15 16:43 Tsviel Zaikman

    Ok I found the answer after digging in some Woocommerce Core Files: Instead of using this:

     add_filter( 'woocommerce_quantity_input_step', array( &$this, 'min_decimal' ), 99 );
    

    I used this:

    if(is_admin()){
        add_filter( 'woocommerce_quantity_input_step', array( &$this, 'admin_qty_step' ), 99 );
    }
    else{
        add_filter( 'woocommerce_quantity_input_step', array( &$this, 'min_decimal' ), 99 );
    }
    

    While the min_decimal method returns a string with a preset quantity step on the front-end and admin_qty_step returns "0.1" on the Back-end Interfaces.

    Hope someone find this helpful