How to display quantity input fields next to add to cart buttons.

To display quantity input fields for simple products within your shop archive pages, you can add the following code to your theme’s functions.php file.

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, contact me for assistance.
 * Code should be placed in your theme functions.php file.

add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
    if ( $product && $product--->is_type( 'simple' ) &amp;&amp; $product-&gt;is_purchasable() &amp;&amp; $product-&gt;is_in_stock() &amp;&amp; ! $product-&gt;is_sold_individually() ) {
$html = '

<form action="'
. esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= woocommerce_quantity_input( array(), $product, false );
$html .= '<button type="submit" class="button alt">' . esc_html( $product-&gt;add_to_cart_text() ) . '</button>';
$html .= '</form>';
return $html;

By Mahbubur Rahman

Self Taught Programmer And Learning Enthusiast

Leave a comment

Your email address will not be published. Required fields are marked *