Title: product quantity drop-down
Last modified: November 24, 2018

---

# product quantity drop-down

 *  Resolved [nicowebmaster](https://wordpress.org/support/users/nicowebmaster/)
 * (@nicowebmaster)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/product-quantity-drop-down/)
 * Hello,
    I added a code to display the quantity produced as a drop-down list, 
   but I had to put a minimum quantity and a max quantity. How to dynamically display
   the quantity max = quantity in stock of the product?
 * My code:
 *     ```
       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 .= '<option 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>';
       }
       ```
   
 * Thanks!
 * Nicolas
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fproduct-quantity-drop-down%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Contributor [Gerhard Potgieter](https://wordpress.org/support/users/kloon/)
 * (@kloon)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/product-quantity-drop-down/#post-10916839)
 * Hi, `$product->get_stock_quantity( 'edit' )` will return the the quantity available
   for the sale for the specific product. So you will need to set `$max` to `$product-
   >get_stock_quantity( 'edit' )`
 *  Thread Starter [nicowebmaster](https://wordpress.org/support/users/nicowebmaster/)
 * (@nicowebmaster)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/product-quantity-drop-down/#post-10916883)
 * Hello,
 * What would be the exact code? I replaced but I have a blank page
 * Thanks
 *  Plugin Contributor [Gerhard Potgieter](https://wordpress.org/support/users/kloon/)
 * (@kloon)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/product-quantity-drop-down/#post-10916888)
 * Try the following, if you have issues then I suggest you hire a developer for
   assistance.
 *     ```
       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 = $product->get_stock_quantity( 'edit' );
         if ( ! empty( $defaults['step'] ) )
           $step = $defaults['step'];
         else $step = 1;
         $options = '';
         for ( $count = $min; $count <= $max; $count = $count+$step ) {
           $options .= '<option 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>';
       }
       ```
   
 *  [wbrubaker.a11n](https://wordpress.org/support/users/wbrubaker/)
 * (@wbrubaker)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/product-quantity-drop-down/#post-10942381)
 * We haven’t heard back from you in a while, so I’m going to mark this as resolved–
   if you have any further questions, you can start a new thread.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘product quantity drop-down’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [dropdown](https://wordpress.org/support/topic-tag/dropdown/)
 * [max](https://wordpress.org/support/topic-tag/max/)
 * [min](https://wordpress.org/support/topic-tag/min/)
 * [product](https://wordpress.org/support/topic-tag/product/)
 * [quantity](https://wordpress.org/support/topic-tag/quantity/)

 * 4 replies
 * 3 participants
 * Last reply from: [wbrubaker.a11n](https://wordpress.org/support/users/wbrubaker/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/product-quantity-drop-down/#post-10942381)
 * Status: resolved