Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wbcomdev/1553e512d4ee4a5c27a2b7e6685d0f2f to your computer and use it in GitHub Desktop.

Select an option

Save wbcomdev/1553e512d4ee4a5c27a2b7e6685d0f2f to your computer and use it in GitHub Desktop.
/**
* Override loop template and show quantities next to add to cart buttons.
*/
function wb_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 = '<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->add_to_cart_text() ) . '</button>';
$html .= '</form>';
}
return $html;
}
add_filter( 'woocommerce_loop_add_to_cart_link', 'wb_quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment