• I have created set quantities as a variable product attribute and I wanted to know whether it is possible to remove the default product quantity increment input from product and cart pages and change it to a dropdown with the quantities I have set in my product attributes e.g. quantity 100, 250, 500.

    Thanks

    https://wordpress.org/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi there,

    You can override quantity-input.php into your theme. Read this helpful information.

    Then replace the default code with this one.

    <div class="quantity">
    
    	<?php
    
    	// Your predefined prices
    	$predefined_prices = array(100, 250, 500);
    
    	?>
    
    	<select step="<?php echo esc_attr( $step ); ?>" <?php if ( is_numeric( $min_value ) ) : ?>min="<?php echo esc_attr( $min_value ); ?>"<?php endif; ?> <?php if ( is_numeric( $max_value ) ) : ?>max="<?php echo esc_attr( $max_value ); ?>"<?php endif; ?> name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $input_value ); ?>" title="<?php _ex( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) ?>">
    
    		<?php
    
    		foreach($predefined_prices as $price){
    
    			echo '<option value="'.esc_attr($price).'" '.selected( $price, esc_attr( $input_value ) ).'>'.esc_attr($price).'</option>';
    
    		}
    
    		?>
    
    	</select>
    
    </div>

    I’ve tested on my end. It works.

    Let me know how it works for you.

    Hello, I am trying to do something very similar, to have a drop down of quantities in my cart. However, I created an attribute for my quantities for a variable product, and each quantity has a different price that I set in my variations. Is there a way to have the cart to show the quantity-price variation the way I have it on the product page?
    I currently have the quantity input field hidden on my product page since I have it set up as an attribute.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change default quantity input to dropdown variable quantity attribute’ is closed to new replies.