↑↓ selectEnter openEsc close

    1. Elbuz
    2. Website chat
    3. How to set up the chat widget on your website

    How to connect your site's cart to the chat: event code, JS and CSS

    4 min readUpdated

    The “Buy”, “Add to wishlist” and “Compare” buttons on Elbuz chat product cards call your JavaScript, so the product lands in your site's cart mid-conversation. Common CMSs get ready-made code from a list.

    When you need this:

    • “Buy” opens the product page — event code adds the product to the cart at once.
    • OpenCart, WooCommerce, Shopify or Horoshop — a “CMS ID” fills in ready-made code.
    • The chat covers another widget's button — custom code hides it on open and restores it on close.
    • Chat window details clash with the site — custom CSS fixes them.

    Where to start: “Setup” tab → “Site” card → “CMS ID”.

    What you can configure

    Ready-made code for your CMS

    On the “Setup” tab, in the “Site” card, choose your platform in “CMS ID”. The app fills in code for that CMS in the six fields of the “Events” tab, and if “Site address” is filled in, also the “Cart link” on the “Links” tab.

    What choosing a CMS fills in
    CMSCartWishlist and comparison
    OpenCartadd and removeyes
    Elbuz CMSadd and removeyes
    WooCommerce (WordPress)add and removeyes, for common wishlist and comparison plugins
    Magento (Adobe Commerce)add and removeyes
    Horoshopadd and removeyes
    Shopifyadd and removeno
    PrestaShop, BigCommerce, Squarespace Commerceno ready-made code — your developer writes itno

    “CMS theme” lists OpenCart themes: OCT ShowCase, OCT Deals, OCT Promo; only themes of the chosen CMS appear. A theme adds to the OpenCart code updates of the cart, wishlist and comparison counters in the site header and opening of the mini cart, and ShowCase and Deals also add code to “Run JS code after closing”.

    The app fills in empty fields silently. If the ready-made code would replace fields you've already filled in, the question “Apply CMS settings?” appears with a list of those fields:

    • “Replace” — put the ready-made code into filled-in fields too;
    • “Fill empty only” — your code stays, the ready-made code goes only into empty fields;
    • “Cancel” — change nothing.

    The “---” option changes nothing.

    The new values appear in the fields but are saved when you close the window or change another field. In a store on Elbuz CMS, the event code is filled in when the widget is connected, so there's nothing to choose. If you chose OpenCart before 15.11.2026, choose the CMS again and click “Replace” — then “Remove from cart” will also work from the chat.

    The “Site” card: site address, CMS ID and theme
    1Site address
    2CMS ID
    3CMS theme
    1. The base of links; with it, choosing a CMS also fills in the cart addresses.
    2. Inserts ready-made event code for your platform.
    3. OpenCart themes; the list has only the themes of the chosen CMS.

    Event code: what each field does

    The “Events” tab has six fields — a pair each for the cart, the wishlist and comparison. The code runs in the shopper's browser, on your site, when they click a button on a product card in the chat.

    Fields on the “Events” tab
    FieldWhen it runsIf the field is empty
    “Add to cart”a click on “Buy” on a product cardthe click opens the product page in a new tab
    “Remove from cart”a second click on a button that's already addedthe second click does nothing
    “Add to wishlist”, “Add to comparison”a click on “Add to wishlist” or “Compare”the button only changes its look; nothing is sent to the site
    “Remove from wishlist”, “Remove from comparison”a second click on these buttonsthe button only changes its look

    A button turns “added” only if the code worked: if the code sends a request to the site, the response must be successful and carry no error flag. Otherwise the shopper sees “Could not add: you may need to choose product options.” and a link to the product. After a successful add, “Go to cart” appears below the product list if a cart link is set.

    The “Events” tab: six code fields for the cart, wishlist and comparison
    1Add to cart
    2Remove from cart
    3Wishlist and comparison
    1. Runs on “Buy”; if empty, the product page opens.
    2. A second click on the added button.
    3. If the fields are empty, the button only changes its look.

    What product data the code gets

    The code receives the productData variable with these fields:

    FieldWhat it holds
    idthe product number in Elbuz
    id_extthe product number in your CMS — what the site's cart expects
    sku, mpnSKU and manufacturer part number
    name, url, image_urlname, product link and photo

    productData has no quantity or price: the ready-made templates add one item. The CMS number (id_ext) comes from the product card, or, if an external source is set on the “Links” tab, from the link to it (source). A product without a CMS number won't get into the site's cart.

    If the catalog has no CMS number or it's different, fill in the “Product ID extraction” card on the “Events” tab: before the cart code runs, the widget opens the product page and takes the number with a CSS selector or a regular expression (“Extraction type”). Without the “Always extract ID from product page, even if id_ext is filled” checkbox, the number is taken from the page only when the catalog has none; with it — always. It works the same as in smart search.

    A site that also has smart search

    If the smart search widget runs on the page, “Buy”, “Add to wishlist” and “Compare” in the chat run the code from the search settings, not the chat's (cart in smart search). Removing a product from the cart works differently: first the chat's “Remove from cart” runs, and after it succeeds, the search's removal code. So on a site with search, set up the cart in search and “Remove from cart” in the chat.

    Custom JS and CSS for the widget

    The “JS, CSS settings” card on the “Setup” tab is for a developer fitting the chat to the site.

    • “Run JS code before opening” — runs every time before the chat window appears. A typical use is hiding another widget's button that covers the chat.
    • “Run JS code after closing” — after the shopper closes the window: bring back what was hidden.
    • “CSS Styles” — added to the page when the chat loads.
    • “JS code” — runs once, when the chat has loaded on the page.

    The chat adds its own code to the open and close code: it hides and restores the Binotel widget if the site has one.

    The “JS, CSS settings” card: code on opening and closing the chat, and styles
    1Code on opening
    2Code after closing
    3CSS styles
    1. Runs every time before the chat window appears.
    2. Brings back what was hidden on opening.
    3. Added to the page together with the chat.

    Scenarios

    A site on OpenCart

    What to set up. “Site address”, “CMS ID” — OpenCart, and “CMS theme” if needed.

    What you get. “Buy” in the chat adds one item to the site's cart, a second click removes it, and “Go to cart” appears below the products.

    A site on a platform without ready-made code

    What to set up. A developer writes a call to the site's cart with productData.id_ext in “Add to cart”.

    What you get. The same as with ready-made code. While the field is empty, “Buy” opens the product page.

    The chat covers the callback button

    What to set up. In “Run JS code before opening” — hide the button; in “Run JS code after closing” — show it.

    What to do when the chat buttons don't work

    What you see and what to do about it
    What you seeWhyWhat to do
    “Buy” opens the product page“Add to cart” is emptyChoose a “CMS ID” or enter code (CMS)
    “Could not add: you may need to choose product options.”The site responded with an error — often the product has no CMS numberCheck the product's CMS number in the product card or set up “Product ID extraction” (data)
    The old event code stayed after choosing a CMS“Fill empty only” or “Cancel” was clicked in the “Apply CMS settings?” questionChoose the CMS again and click “Replace” (CMS)
    You changed the chat's event code, but nothing changed on the siteThe site has smart search, and its code runsEdit the code in the search widget (search)
    Your open or close code doesn't runA syntax error in the codeCheck the code in the browser console (JS)

    FAQ

    Does the chat work without event code?

    Yes. The chat answers and shows products, and “Buy” opens the product page, where the shopper adds it to the cart themselves.

    Can I add two items from the chat?

    The ready-made templates add one item: the product data has no quantity (data). More can be added in the site's cart.

    Why use the site's cart if the AI takes orders in the chat?

    These are two different paths. Checkout in the conversation creates an order in Elbuz, while the site's cart is for shoppers who check out on their own (orders from the chat).

    Do I need chat event code if the site has smart search?

    For “Buy”, the wishlist and comparison — no, the search code runs. Fill in “Remove from cart” in the chat, otherwise products can't be removed from the chat (search).

    Where to find it and who has access

    Menu
    Directories → Categories → “Catalog tools” → “Widget settings - Smart Assistant” → “Events” tab
    CMS, JS and CSS
    the same form, “Setup” tab → “Site” and “JS, CSS settings” cards
    Prepare
    CMS numbers in product cards; for your own platform — a developer

    Related topics

    Was this article helpful?

    Missing a feature? Tell us.

    We will add it for free if other users need it too.

    If only you need it, we will agree on it separately.

    Article contents

    Suggest an improvement

    Try Elbuz free