How do I make the quantity dropdown work right in cart page?
-
Since I don’t know how to disable the quantity hover. I’m going to use the dropdown quantity. I have the code but the quantity dropdown doesn’t update the right number in the cart page. Do you know why? For example if I my quantity is 3, it will say 1 in my cart page. Also when I choose my quantity 3, and then I click the “add to cart button” , it will say “Please choose product options” because I didn’t choose a size. The quantity start from 1 again, it doesn’t stay the same what I chose before. Also this have to work in mobile too. Can you help me with that? Thanks
// override the quantity input with a dropdown
function woocommerce_quantity_input() {
global $product;
global $post;
global $prod_quant_default;$prod_quant_default = 1; // <———– Default Amount
$category_ID = ’26’; // <———– Case Category$terms = get_the_terms( $post->ID, ‘product_cat’ );
foreach ($terms as $term) {
$product_cat_id = $term->term_id;
break;
}// Sets QTY for Cases (Cat 26)
if ($product_cat_id == $category_ID){
$prod_quant_default = 1;
//break;
}$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’, ‘float:left; margin-right:10px;’, $product )
);
if ( ! empty( $defaults[‘min_value’] ) )
$min = $defaults[‘min_value’];
else $min = 1;if ( ! empty( $defaults[‘max_value’] ) )
$max = $defaults[‘max_value’];
else $max = 10;if ( ! empty( $defaults[‘step’] ) )
$step = $defaults[‘step’];
else $step = 1;$options = ”;
for ( $count = $min; $count <= $max; $count = $count+$step ) {
global $prod_quant_default;
if ($count == $prod_quant_default) {
$selected = ‘ selected=”selected” ‘;
}
else {
$selected = null;
}$options .= ‘<option’ . $selected . ‘ value=”‘ . $count . ‘”>’ . $count . ‘</option>’;
}
echo ‘<div class=”quantity_select” style=”‘ . $defaults[‘style’] . ‘”><select name=”‘ . esc_attr( $defaults[‘input_name’] ) . ‘” title=”‘ . _x( ‘Qty’, ‘Product quantity input tooltip’, ‘woocommerce’ ) . ‘” class=”qty”>’ . $options . ‘</select></div>’;}
- The topic ‘How do I make the quantity dropdown work right in cart page?’ is closed to new replies.