Support » Plugin: Cart REST API for WooCommerce - CoCart Lite » Incompatibility with Advanced Woo Search PRO

  • Good day,

    We’re having issues with our installation of CoCart Lite; when an AJAX search is performed (Advanced Woo Search PRO) the response results in GUEST user carts being cleared.

    We’ve figured out that this is because the WooCommerce conditional (/includes/class-wc-cart-session.php -> maybe_set_cart_cookies()) succeeds (no headers from the “wp” hook?) and determines that the cart is empty, which results in the following:
    $this->set_cart_cookies( false );

    This then results in CoCart Lite destroying the cart (/includes/class-cocart-session-handler.php -> set_customer_cart_cookie()).

    What can we do to resolve this incompatibility/issue?
    Looking at Chrome dev tools I can see that headers are sent along with the AJAX request, why then is the cart cleared in the “wp” hook?

    Versions:
    Advanced Woo Search PRO: 2.24
    CoCart Lite: 2.9.2
    WooCommerce: 4.8.0
    WordPress: 5.6

    Regards,
    Estian

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Sébastien Dumont

    (@sebd86)

    @divspot Can you share the steps you take so I can replicate this? Because I am not seeing any issues on the frontend that this search plugin is designed for.

    Thread Starter Estian Hough

    (@divspot)

    Hi Sébastien,

    Certainly.

    1. Open https://isabellagarcia.co.za
    2. Add any item (from any page) to your cart (as a guest).
    3. Input a search keyword using the header “search icon”, await an AJAX response.
    4. Refresh the page or open a different page.
    5. Notice that the cart has been cleared.

    If you look at the headers (as is provided with Chrome dev tools) you’ll be able to notice that it sends cookie data in the response that clears the cart.

    Please let me know if you need more information.

    Regards,
    Estian

    Thread Starter Estian Hough

    (@divspot)

    Hi Sébastien, @sebd86

    For some additional information see below.

    I’ve noted also that the AJAX search sends the correct WooCommerce cart data in the headers as it does when adding an item to the cart. I just don’t see what is different between an “add to cart” AJAX request and an AJAX “search” request in terms of the request data?

    What is the purpose of the code in?
    /includes/class-cocart-session-handler.php -> set_customer_cart_cookie())
    When $set = false the following is run:

    // If cookies exists, destroy it.
    			if ( isset( $_COOKIE[ $this->_cookie ] ) ) {
    				$this->cocart_setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), $this->use_httponly() );
    				unset( $_COOKIE[ $this->_cookie ] );
    			}

    This function is a twin of the WooCommerce class-wc-session-handler.php -> set_customer_session_cookie(...) function, yet the WooCommerce function does not delete the cart on $set === false.

    Plugin Author Sébastien Dumont

    (@sebd86)

    Thank you for providing the steps. I was able to replicate the issue.

    The purpose of destroying the cookie is for when a guest customer turns into a registered customer by authenticating. Without destroying the cookie first, the cart does not return correctly for the registered customer when the response returns.

    This should not be affecting guest customers as the cookie is only destroyed first before creating a new one when a customer is authenticated.

    Plugin Author Sébastien Dumont

    (@sebd86)

    I tested the steps locally with the free version of the plugin and there was no issue as a guest customer. The cart did not clear. The problem is with the Pro only so it might be best to ask them for support to find out what the difference is between the two search plugins.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.