Documentation
Complete API reference. Tags: [core] essential, [conv] convenience, [plugin] requires plugin.
Installation
No npm required. Just copy the files from dist/ to your project.
<!-- Core (~26KB) -->
<script src="whanda.min.js"></script>
<!-- Optional plugins (~4KB) -->
<script src="whanda-plugins.min.js"></script>
ES Module
import { Whanda } from "./whanda.esm.min.js";
import { initPlugins } from "./whanda.esm.min.js";
initPlugins(Whanda);
Quick start
const w = new Whanda({ whatsappNumber: "1234567890" });
w.setProducts([
{ id: "1", name: "T-Shirt", price: 1200, stock: 25, category: "Clothing", image: "tshirt.jpg" }
]);
await w.addItem("1");
w.setCustomerName("Juan");
w.setCustomerAddress("123 Main St");
w.setPaymentMethod("Cash");
w.setDeliveryMethod("Home Delivery");
const order = await w.createOrder();
const link = await w.sendToWhatsApp(order);
window.open(link, "_blank");
Quick start with AI
Generate a complete store by pasting a prompt into ChatGPT, Claude, Cursor, or any AI agent.
Step 1: Download the files above (whanda.min.js + whanda-plugins.min.js)
Step 2: Copy the prompt below and paste it into your AI agent
Using whanda.min.js and whanda-plugins.min.js,
create a [TYPE] store in a single HTML file.
IMPORTANT:
- No npm. No import statements.
- Copy whanda.min.js and whanda-plugins.min.js
to the same directory as the HTML.
Flow: Catalog → Cart → WhatsApp → Manual close
Requirements:
1. <script src="whanda.min.js">
2. new Whanda({ whatsappNumber: "NUM" })
3. w.setProducts([...])
4. await w.addItem(id)
5. w.setCustomerName() / setCustomerAddress()
6. const order = await w.createOrder()
7. window.open(await w.sendToWhatsApp(order))
8. Responsive design with Tailwind CSS
Constructor
| Method | Description | Returns |
|---|---|---|
new Whanda(config?) | core Create instance | Whanda |
Config: { currency, locale, whatsappNumber, shipping, paymentMethods, deliveryMethods, currencies, regions, storeName }
Products
| Method | Description | Returns |
|---|---|---|
setProducts(products) | core Replace catalog | void |
getProducts(filter?) | conv Products with filters | Object[] |
getProduct(id) | conv Product by ID | Object|null |
getPrice(id) | conv Product price | number |
getStock(id) | conv Product stock | number |
getCategories() | conv Unique categories | string[] |
search(query) | conv Search by name/category | Object[] |
getRelatedProducts(id) | conv Related products | Object[] |
getUpsells(id) | conv Upsells (more expensive) | Object[] |
getCrossSells(id) | conv Cross-sells (complementary) | Object[] |
Filters: { category, minPrice, maxPrice, search, sort, order, limit }
Cart
| Method | Description | Returns |
|---|---|---|
getCart() | conv Cart copy | Object[] |
addItem(id, qty?) | core Add to cart | Promise<void> |
clearCart() | conv Empty cart | void |
removeCartItem(id) | conv Remove item | void |
updateQuantity(id, qty) | conv Update quantity | void |
hasCartItem(id) | conv Check if in cart | boolean |
getCartItemCount() | conv Total items | number |
Pricing
| Method | Description | Returns |
|---|---|---|
getSubtotal() | conv Cart subtotal | number |
getShippingCost() | conv Calculated shipping | number |
getDiscountAmount() | conv Discount amount | number |
getTotal() | conv Total (never negative) | number |
calculate() | conv Full breakdown | Object |
formatPrice(amount) | conv Format with currency | string |
Coupons
| Method | Description | Returns |
|---|---|---|
addCoupon(coupon) | core Register coupon | void |
getCoupons() | conv All coupons | Object[] |
applyCoupon(code) | conv Apply active coupon | Object |
removeCoupon() | conv Remove active coupon | void |
validateCoupon(code) | conv Check if exists | boolean |
getActiveCoupon() | conv Active coupon or null | Object|null |
Shipping
| Method | Description | Returns |
|---|---|---|
setFixedShipping(value) | conv Fixed shipping | void |
setFreeShippingFrom(n) | conv Free from n | void |
setPerItemShipping(value) | conv Per-item cost | void |
getShippingCost() | conv Calculated cost | number |
isFreeShipping() | conv Free shipping? | boolean |
Customer
| Method | Description | Returns |
|---|---|---|
setCustomerName(name) | conv Customer name | void |
setCustomerAddress(addr) | conv Address | void |
setCustomerNotes(notes) | conv Additional notes | void |
getCustomer() | conv Data copy | Object |
Checkout
| Method | Description | Returns |
|---|---|---|
setPaymentMethod(m) | conv Set payment | void |
setDeliveryMethod(m) | conv Set delivery | void |
validateCheckout() | core Validate required data | true |
createOrder(meta?) | core Create order | Promise<Object> |
Orders
| Method | Description | Returns |
|---|---|---|
getOrder(id) | conv Order by ID | Object|null |
getLastOrder() | conv Last order | Object|null |
listOrders() | conv All orders | Object[] |
updateOrderStatus(id, s) | conv Update status | Object |
cancelOrder(id) | conv Cancel and remove | Object |
Valid statuses: pending, confirmed, shipped, delivered, cancelled
| Method | Description | Returns |
|---|---|---|
setWhatsAppNumber(n) | core Set number | void |
sendToWhatsApp(order) | core Generate wa.me link | Promise<string> |
generateMessage(order) | core Generate message | Promise<string> |
registerWhatsAppTemplate(id, fn) | conv Register template | void |
getShareCatalogUrl(opts?) | conv Share catalog URL | string |
getThankYouHtml(opts?) | conv Thank-you page HTML | string |
Multi-Currency
| Method | Description | Returns |
|---|---|---|
setCurrency(code) | core Set active currency | void |
getCurrency() | conv Active currency | string |
getExchangeRate(code) | conv Exchange rate | number |
convertPrice(basePrice) | conv Convert price | number |
Config: { currencies: { USD: 1, DOP: 56.5, EUR: 0.92 } }
Multi-Region
| Method | Description | Returns |
|---|---|---|
setRegion(code) | core Set active region | void |
getRegion() | conv Active region | string|null |
getTax(productId?) | conv Tax rate | number |
getTaxName() | conv Tax name | string |
Config: { regions: { DO: { tax: { rate: 0.18, name: "ITBIS" }, shipping: { flat: 150, freeFrom: 2000 }, currency: "DOP" } } }
Hooks
Use w.on("hook", fn) to register and w.off("hook", fn) to unsubscribe.
| Hook | Payload | Fires when |
|---|---|---|
beforeAddToCart | { productId, quantity } | Before adding item |
afterAddToCart | cart items | After adding item |
afterCartChange | cart items | After any cart change |
beforeCheckout | meta | Before creating order |
afterCheckout | order | After creating order |
beforeWhatsAppSend | order | Before generating link |
onRemoveItem | { productId, cart } | Removing item from cart |
onCartEmpty | { cart } | Emptying the cart |
Hooks can abort by returning { abort: true, message: "..." }
Security
| Method | Description | Returns |
|---|---|---|
_sanitizeString(str) | int Escape HTML entities | string |
_sanitizeObject(obj) | int Recursively sanitize | Object |
_sanitizeString() escapes < > " ' & to prevent XSS.
Scalability
| Method | Description | Returns |
|---|---|---|
loadFromSources(sources) | core Load from multiple sources | Promise<Object[]> |
cacheProducts(ttl?) | conv Cache to localStorage | void |
getProductsPaginated(p, sz) | conv Paginated products | Object |
createProductIterator(b?) | conv Lazy loading iterator | Object |
Persistence
| Method | Description | Returns |
|---|---|---|
save() | int Serialize to JSON | string |
load(json) | int Restore from JSON | void |
reset() | conv Clear state | void |
Seasons
Requires whanda-plugins.min.js
| Method | Description | Returns |
|---|---|---|
createSeason(config) | Create season | void |
getSeasons() | All seasons | Object[] |
getActiveSeason() | Active season by date | Object|null |
isInSeason(productId) | In season? | boolean |
Config: { id, name, start, end, type, discount, products, couponCode }
Urgency
Requires whanda-plugins.min.js
| Method | Description | Returns |
|---|---|---|
setProductUrgency(id, cfg) | Set urgency | void |
getUrgency(id) | Urgency data | Object|null |
getLowStockProducts() | Low stock products | Object[] |
Config: { lowStock, countdown, badge }
Bundles
Requires whanda-plugins.min.js
| Method | Description | Returns |
|---|---|---|
createBundle(config) | Create bundle | void |
getBundles() | All bundles | Object[] |
addBundle(id, qty?) | Add bundle to cart | Promise<void> |
deleteBundle(id) | Delete bundle | void |
Config: { id, name, products, type, discount }. Products: ["id1", "id2"] or [{ productId: "id1", quantity: 1 }]
Downsells
Requires whanda-plugins.min.js
| Method | Description | Returns |
|---|---|---|
setDownsell(config) | Set downsell | void |
getDownsell() | Current config | Object|null |
clearDownsell() | Remove downsell | void |
Config: { trigger, type, value, message, alternativeProductId }
CRO (Headless)
Requires whanda-plugins.min.js
CRO is headless — provides data, you render the UI.
| Method | Description | Returns |
|---|---|---|
setCRO(config) | Configure CRO | void |
getCROData() | All CRO data | Object |
trackProductView(id) | Track product view | void |
getRecentlyViewed() | Recently viewed | Object[] |
checkFreeShippingProgress() | Shipping progress | Object |
Config: { freeShippingBar, freeShippingGoal, lowStockAlert, recentlyViewed, socialProof, exitIntent, exitMessage, exitDiscount }
Google Sheets Adapter
Requires whanda-sheets.js
| Function | Description | Returns |
|---|---|---|
loadFromSheets(w, opts) | Load from Sheets | Promise<Object[]> |
parseCSV(text) | Parse CSV to products | Object[] |
buildGoogleSheetsCsvUrl(url) | Convert URL to CSV export | string |
Options: sheetUrl (public sheet) or proxyUrl (serverless proxy, recommended for production).
Extensions
Requires whanda-extensions.min.js
| Method | Description | Returns |
|---|---|---|
exportOrders() | Export orders as CSV | string |
Error Codes
Core
| Code | Message |
|---|---|
| W001 | search() requires a search text |
| W002 | Product not found |
| W003 | Quantity must be a positive integer |
| W004 | Insufficient stock |
| W018 | Cart is empty |
| W019 | Customer name is required |
| W020 | Customer address is required |
| W021 | Payment method is required |
| W022 | Delivery method is required |
| W025 | WhatsApp number not configured |
| W035 | setProducts() requires an array |
| W039 | Hook cancelled |
| W040 | Invalid JSON in load() |
Plugins
| Code | Message |
|---|---|
| W100 | Bundle requires id, name, and products |
| W101 | Bundle not found |
| W102 | Season requires id, name, start, and end |
| W103 | Downsell requires a positive numeric discount |
| W104 | Urgency requires at least one of: lowStock, deadline, or badge |
| W105 | Season dates must be valid |
| W106 | Element with that ID already exists |