Menu

A Simple Shopify Cart Chatbot in 30 Lines of JavaScript
📰

A Simple Shopify Cart Chatbot in 30 Lines of JavaScript

DEV Community: javascript·Aylelite·4 days ago
#oKHKXnfm
#devtojavascript#devto#dev#cart#const
Long article (253 words) — no AI summary yet.
Reading 0:00
15s threshold

A Simple Shopify Cart Chatbot in 30 Lines of JavaScript

Most shoppers don't abandon a cart because of the product. They leave over small doubts about delivery, COD, or a coupon. Here's a tiny bot that answers those on the cart page.

Read the cart

Shopify exposes the live cart as JSON at /cart.js.

javascript

async function describeCart() {

const cart = await (await fetch('/cart.js')).json();

if (!cart.item_count) return 'Your cart is empty.';

const items = cart.items.map(i => ${i.quantity} x ${i.product_title} ).join(', ');

return You have ${items}. Total: ₹${cart.total_price / 100}.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.