Add Quantity field next to add to cart button

This topic has 2 replies, 2 voices, and was last updated 3 years, 9 months ago ago by Olga Barlow

  • Avatar: Kyle
    Kyle
    Participant
    June 10, 2020 at 17:41

    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;
    }
    Please, contact administrator
    for this information.
    1 Answer
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    June 11, 2020 at 21:52

    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

  • Viewing 2 results - 1 through 2 (of 2 total)

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

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.