• WooCommerce by default adds a quantity input box to your product pages where customers can enter quantities, but in my case (I am selling wines) I need to have a dropdown with the options 1,2,3,6,12,18,24,30.

    I have found this code written by GERHARD POTGIETER on his website. Thing is it only let me set the min, max and a step increment. I would have to have 3 steps? 1+1+1, 3+3 and 6+6+6+6+6?

    Can someone help me out here?

    <?php
    // Place the following code in your theme's functions.php file
    // override the quantity input with a 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 .= '<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>';
    }
    ?>
Viewing 1 replies (of 1 total)
  • Thread Starter headvisual

    (@headvisual)

    I tried editing the code. I’ve set min – 1, max – 30, set – 5
    It comes out 1, 6, 11, 16, 21, 26

    If I set the step to 6 it comes out 1>/strong>,7,13,19,25

    I need it to be 1,2,3,6,12,18,24,30 or at least 1,6,12,18,24,30

Viewing 1 replies (of 1 total)
  • The topic ‘WooCommerce Product Quantity Dropdown’ is closed to new replies.