<?php | |
/** | |
* 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' ) && $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; | |
} |
This comment has been minimized.
This comment has been minimized.
Found a gist that enables AJAX with a quantity picker: https://gist.github.com/claudiosmweb/5114131 |
This comment has been minimized.
This comment has been minimized.
@fegul: I just branched this gist with something similar to the one you link (didn't know it existed!), but I also have a gist for doing this with hooks so that you can use the standard templates. Read my blog post, WooCommerce add to cart with quantity and AJAX for more details. |
This comment has been minimized.
This comment has been minimized.
Is there a way to remove the functionality that makes the user jump to the top of the screen after adding an item to the cart and instead replacing it with the /loop/add-to-cart.php functionality where a message (View cart ->) appears below the button? |
This comment has been minimized.
This comment has been minimized.
Is there an update to this available for version 2.1.0 of add-to-cart |
This comment has been minimized.
This comment has been minimized.
Updated for 2.5. |
This comment has been minimized.
This comment has been minimized.
Please i need help on adding quantity selector to my pages on wordpress but not just getting it to show up. the url is marigoldsignatureng.com/ftd. I would like the quantity selector to show before the add to cart |
This comment has been minimized.
This comment has been minimized.
Hi, |
This comment has been minimized.
This comment has been minimized.
Thank you. It works great I've found, except when you select '0' in the quantity amount, it still adds one item to the basket. How would you add this to the conditional clause? |
This comment has been minimized.
I used this override snippet but I think there is a newer version of the original template that checks if a product is purchasable. I only ask because it's caused some drastic style changes on my site. Is there a less intrusive way to link the quantity picker with the add to cart button?