Where can I find the add to cart handler for quantity field?
-
Respected sir/madam,
I have added a feature for displaying quantity selectors on the shop/archive pages and also using the WPC product quantity plugin. After selecting the quantity, when I add to the cart using ajax then it adds only 1 item in the cart irrespective of any other qty. I have written a custom js add to cart handler and need to attach it with Fly cart add to cart handler.
My code is as the following.
/** * Add quantity field on the shop page. */ function bhutatva_shop_page_add_quantity_field() { /** @var WC_Product $product */ $product = wc_get_product( get_the_ID() ); if ( ! $product->is_sold_individually() && 'variable' != $product->get_type() && $product->is_purchasable() ) { woocommerce_quantity_input( array( 'min_value' => 1, 'max_value' => $product->backorders_allowed() ? '' : $product->get_stock_quantity() ) ); } } add_action( 'woocommerce_after_shop_loop_item', 'bhutatva_shop_page_add_quantity_field', 12 ); /** * Add required JavaScript. */ function bhutatva_shop_page_quantity_add_to_cart_handler() { wc_enqueue_js( ' $(".woocommerce .products").on("click", ".quantity input", function() { return false; }); $(".woocommerce .products").on("change input", ".quantity .qty", function() { var add_to_cart_button = $(this).parents( ".product" ).find(".add_to_cart_button"); // For AJAX add-to-cart actions add_to_cart_button.data("quantity", $(this).val()); // For non-AJAX add-to-cart actions add_to_cart_button.attr("href", "?add-to-cart=" + add_to_cart_button.attr("data-product_id") + "&quantity=" + $(this).val()); }); // Trigger on Enter press $(".woocommerce .products").on("keypress", ".quantity .qty", function(e) { if ((e.which||e.keyCode) === 13) { $( this ).parents(".product").find(".add_to_cart_button").trigger("click"); } }); ' ); } add_action( 'init', 'bhutatva_shop_page_quantity_add_to_cart_handler' );
Please let me know what needs to change so that the selected qty gets reflected in the fly cart. Let me know in case of queries. Have a nice day.
Regards & Thanks
IndianoThe page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Where can I find the add to cart handler for quantity field?’ is closed to new replies.