WooCommerce Change Product Quantity Input to Dropdown

Friday, January 17, 2014 10:18 AM By Admin , In

Use following code to change default quantity input boxes into dropdown select options.

Method:

  1. Copy code to your functions.php.

/* Change Product Quantity Input to Dropdown */
function woocommerce_quantity_input() {
 global $product;
  
 $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 = 20;
  
 if (!empty($defaults['step']))
  $step = $defaults['step'];
  else $step = 1;
  
 $options = '';
 for($count = $min;$count <= $max;$count = $count+$step){
  $options .= '';
 }
 
 echo '
'; }

4 comments:

Unknown said...

Hello, I am adding any quantity in cart but only 1 is added to cart. why?

April 25, 2015 at 3:18 AM
Unknown said...

Hello, I am adding any quantity in cart but only 1 is added to cart. why?

April 25, 2015 at 3:19 AM
Bhavesh Kavad said...

Thank you for sharing excellent information. Your website is very cool. Fully useful your blog post... Online shopping site in Ahmedabad

June 27, 2018 at 11:18 PM
Unknown said...

Hi,

I am using your script on details page it is working but when I can the cart page. It is showing 1 in drop down but price is calculated correctly.

Any suggestions?

May 20, 2019 at 5:03 AM

Post a Comment