Change Add to Cart Function

I know this is a front-end development question, but when using the shopify plugin, clicking the add to cart button brings the user directly to the checkout page, rather than just adding the product to the cart. Any guidance as to which algolia file this function is set in?

As you can see in algolia_instant_search_product.hogan.liquid, the add to cart button is just a link.
You can simply add an event handler on the .ais-hit--cart elements to override its behavior. :slight_smile:

    <p class="ais-hit--cart">
      [[# can_order ]]
        <a class="ais-hit--cart-button" href="/cart/[[ objectID ]]:1">
          Add to cart
      [[/ can_order ]]
      [[^ can_order ]]
        <span class="ais-hit--cart-button ais-hit--cart-button__disabled">
          Out of stock
      [[/ can_order ]]

Because this is rerendered with every search, you’ll need to either:

  • bind it to the main instantsearch element and use event delegation
  • call your event handler on every render using'render', function () { /* Your event handler here */ })