Skip to content

Input quantity #567

Answered by crftwrk
RobertCrx asked this question in Q&A
Sep 11, 2023 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

functions.php:

/**
 * Show quantities next to add to cart buttons in loop
 */
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' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
    $html = wc_get_template_html( 'single-product/add-to-cart/simple.php' );
  }
  return $html;
}

You need of course some additional CSS to fix the layout.

Solved?

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by RobertCrx
Comment options

You must be logged in to vote
1 reply
@crftwrk
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants