P粉6137352892023-09-05 13:56:13
Correct code substitutions to use (Update):
It will work smoothly as expected:
add_filter( 'woocommerce_quantity_input_args', 'cart_variation_quantity_input_args', 10, 2 ); function cart_variation_quantity_input_args( $args, $product ){ $product_weight = $product->get_weight(); if( $product_weight > 0 ) { if ( ! is_cart()) { $args['input_value'] = $product_weight; } $args['step'] = $args['min_value'] = $product_weight; } return $args; }
Please make sure you also add (for inventory management):
remove_filter('woocommerce_stock_amount', 'intval'); add_filter('woocommerce_stock_amount', 'floatval');
The code is located in the functions.php file of the active child theme (or active theme). Tested and works.
When loading a page containing a product of 0.5
weight:
Set the correct quantity input on the product and increase in steps of
0.5 (normal steps are also 1) .
On the cart page, everything works as expected with a step size of 0.5
(normal step size is also 1).
Related (for variations): Change input quantity step value based on selected variation weight in WooCommerce