WooCommerce Change Product Quantity Input to Dropdown
Use following code to change default quantity input boxes into dropdown select options.
Method:
- 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:
Hello, I am adding any quantity in cart but only 1 is added to cart. why?
Hello, I am adding any quantity in cart but only 1 is added to cart. why?
Thank you for sharing excellent information. Your website is very cool. Fully useful your blog post... Online shopping site in Ahmedabad
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?
Post a Comment