This topic has 2 replies, 2 voices, and was last updated 4 years, 5 months ago ago by Olga Barlow
I want to add quantity fields next to the add cart buttons on the shop page. When I add the code below it works fine except it removes the AJAX add to cart with check mark feature which I really like because the user stays on the page without refreshing but when I add the following code it refreshes page with a view cart button. Any solutions?
/**
* Override loop template and show quantities next to add to cart buttons
*/
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 = '<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;
}
Hello,
If you check the code that you provided you’ll see that you have form with the post method, so everything works according to the code you used.
In case you want to get q-ty with the Ajax add to cart, please, submit customization request to customization team here. Unfortunately, we are unable to provide support for customizations here under ThemeForest Support Policy.
Regards
The issue related to '‘Add Quantity field next to add to cart button’' has been successfully resolved, and the topic is now closed for further responses