Enable decimal product quantities in WooCommerce

add_action( 'init', 'wpcb_float_stock_amount', PHP_INT_MAX );
if ( ! function_exists( 'wpcb_float_stock_amount' ) ) {
	/**
	 * wpcb_float_stock_amount.
	 */
	function wpcb_float_stock_amount() {
		remove_filter( 'woocommerce_stock_amount', 'intval' );
		add_filter(    'woocommerce_stock_amount', 'floatval' );
	}
}
add_filter( 'woocommerce_quantity_input_step', 'wpcb_set_quantity_input_step', PHP_INT_MAX, 2 );
if ( ! function_exists( 'wpcb_set_quantity_input_step' ) ) {
	/**
	 * wpcb_set_quantity_input_step.
	 */
	function wpcb_set_quantity_input_step( $qty, $product ) {
		return 0.01;
	}
}

No comments yet.

Leave a Reply