Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce decimal quantity

can you help me to find a way for use decimal value like 3.56 for quantity in woocommerce ?

in calculate price quantity number convert to Integers value but i need price calculate with Values that the user has inputed

i am working with woocommerce 2.2.8

like image 981
Diba Avatar asked Dec 11 '14 07:12

Diba


1 Answers

You have to add some functions, for some of the hooks i WooCommerce.

// Add min value to the quantity field (default = 1)
add_filter('woocommerce_quantity_input_min', 'min_decimal');
function min_decimal($val) {
    return 0.1;
}

// Add step value to the quantity field (default = 1)
add_filter('woocommerce_quantity_input_step', 'nsk_allow_decimal');
function nsk_allow_decimal($val) {
    return 0.1;
}

// Removes the WooCommerce filter, that is validating the quantity to be an int
remove_filter('woocommerce_stock_amount', 'intval');

// Add a filter, that validates the quantity to be a float
add_filter('woocommerce_stock_amount', 'floatval');

I have written a tutorial, for this functionality, with some extra fixes an explanation at: http://codeontrack.com/use-decimal-in-quantity-fields-in-woocommerce-wordpress/

like image 140
mschadegg Avatar answered Nov 23 '22 22:11

mschadegg