I'm using the latest version of WooCommerce, but I want to have the quantity input replaced with a drop down menu.
I found this code online which works in Chrome, but in Firefox the shopping cart shows a quantity of "0". The totals display correctly for the quantity that was chosen, but the drop down menu shows quantity "0".
Any ideas what's wrong?
if ( ! function_exists( 'woocommerce_quantity_input' ) ) {
function woocommerce_quantity_input( $args = array(), $product = null, $echo = true ) {
if ( is_null( $product ) )
$product = $GLOBALS['product'];
if ( ! $product->is_in_stock() ) return;
$defaults = array(
'input_name' => 'quantity',
'input_value' => '1',
'max_value' => apply_filters( 'woocommerce_quantity_input_max', '', $product ),
'min_value' => apply_filters( 'woocommerce_quantity_input_min', '', $product ),
'step' => apply_filters( 'woocommerce_quantity_input_step', '1', $product ),
'style' => apply_filters( 'woocommerce_quantity_style', 'margin-bottom: 10px;', $product )
);
if ( ! empty( $defaults['min_value'] ) )
$min = $defaults['min_value'];
else $min = 0;
if ( ! empty( $defaults['max_value'] ) )
$max = $defaults['max_value'];
else $max = 30;
if ( ! empty( $defaults['step'] ) )
$step = $defaults['step'];
else $step = 1;
$options = '';
for ( $count = $min; $count <= $max; $count = $count+$step ) {
$selected = $count === $args['input_value'] ? ' selected' : '';
$options .= '<option value="' . $count . '"'.$selected.'>' . $count . '</option>';
}
$args = apply_filters( 'woocommerce_quantity_input_args', wp_parse_args( $args, $defaults ), $product );
echo '<div class="quantity_select"><select name="' . esc_attr( $args['input_name'] ) . '" title="' . _x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) . '" class="qty">' . $options . '</select></div>';
ob_start();
if ( $echo ) {
echo ob_get_clean();
} else {
return ob_get_clean();
}
}
}
https://wordpress.org/plugins/woocommerce/