• Resolved ramil0001

    (@ramil0001)


    I find a little problems with performance in woocommerce.
    My button add/remove to cart after click send request to backend vie ajax and return html page.

    To add to the cart I wrote the following code in function.php
    add_filter( 'woocommerce_add_to_cart_redirect', 'my_add_to_cart_redirect' );
    function my_add_to_cart_redirect( $url ) {
        if ( isset( $_REQUEST['add-to-cart'] ) && ! empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) {
            // If get response vie AJAX, return JSON
            $response = array( 'status' => true );
            wp_send_json( $response );
        } else {
           
           
        }
    }
    

    With this code i have next result

    And this solution up speed .



    I want to know how you solve the problem with the speed of adding and removing goods from the basket, what solutions did you use to optimize the speed of the basket as a whole

    Thanks.
Viewing 1 replies (of 1 total)
  • Saif

    (@babylon1999)

    Hello @ramil0001,

    Thank you for reaching out!

    You can change the “Add to Cart” behaviour from refreshing the entire page to using AJAX by navigating to WooCommerce > Settings > Products.


    Link to image: https://d.pr/i/jTgVVp

    Although, on my test site, the response is the same page I added the product from not “Home Page”, which is expected. :?)

    You can check this guide for general suggestions on how to speed up your site’s store.

    If you see other unusual behaviours when adding products to cart, then please try switching to the default Storefront theme to confirm whether this is a theme-related issue
    Hope this helps!

Viewing 1 replies (of 1 total)
  • The topic ‘ajax response add to cart and remove / return html code page’ is closed to new replies.