• Resolved pxforti

    (@pxforti)


    Using latest version of WooCommerce with ajax add to cart enabled

    When on a category page, I add a product to the cart. Ajax adds the product and then the cart page is reloaded and I am at the top of the page.

    It is possible to add a product to carty and stay in the same position on the category page? If a page has a lot of products and I add one from near the bottom, I have to scroll all the way back down to add a product near the bottom.

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    It is possible to add a product to carty and stay in the same position on the category page?

    Please go to WooCommerce > Settings > Products > General, and uncheck Redirect to the cart page after successful addition – this should allow your customers to stay on the same category page without reloading.

    Link to image: https://snipboard.io/KwPjJW.jpg

    Thread Starter pxforti

    (@pxforti)

    Thanks. But my problem is not a redirect to cart page. My problem is that if ajax add to cart is on, then when on a category page and I click add to cart, the product is added and the cart page reloads to the top of the page rather than where I was ON the cart page.

    I want the cart page to reload to where I was on the cart page; eg at the bottom of a 36 product cart page.

    Plugin Support Shohan Hossain Nabil – a11n

    (@sohanhossain)

    Hello @pxforti,

    Thank you for getting back to us. I did some testing on my test sites but I couldn’t reproduce the behavior you mentioned above. The issue seems to exist on your site only.

    This kind of problem is usually caused by a conflict with your theme or with another plugin.
    ?
    The best way to determine this is to:

    • Temporarily switch your theme to Storefront
    • Disable all plugins except for WooCommerce
    • Repeat the action that is causing the problem

    If you’re not seeing the same problem after completing the conflict test, then you know the problem was with the plugins and/or theme you deactivated. To figure out which plugin is causing the problem, reactivate your other plugins one by one, testing after each, until you find the one causing conflict. You can find a more detailed explanation on how to do a conflict test here.

    Thanks.

    Thread Starter pxforti

    (@pxforti)

    Hi Thanks for the answer. You are correct: I added code to my theme functions.php that added product quantity inputs to the category/ products list page.

    I got this code from the WooCommerce website: https://woocommerce-b2b.com/blog/add-quantity-input-in-products-list/

    Unfortunately, it is this code that causes the page to reload after clicking the add to cart button on a product category page. Is there any way to keep this code AND prevent the page from reloading?

    This is the code that adds the quantity function to the product category page:
    ====================

    /**
     * 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;
    }

    Thanks

    Mirko P.

    (@rainfallnixfig)

    Hi @pxforti,

    Glad to hear you figured out that your custom code is causing the page to reload. Since this is more of a development issue you’ll want to consult a web developer that may assist you in fixing it. We’d recommend getting in touch with experts listed at https://woocommerce.com/customizations/.

    I’ll go ahead and close the thread now as it’s not related to the default functions of core WooCommerce. If you have more questions please open a new topic.

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘stop page scrolling to top after add to cart on category page’ is closed to new replies.