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

MethodDescriptionReturns
new Whanda(config?)core Create instanceWhanda

Config: { currency, locale, whatsappNumber, shipping, paymentMethods, deliveryMethods, currencies, regions, storeName }

Products

MethodDescriptionReturns
setProducts(products)core Replace catalogvoid
getProducts(filter?)conv Products with filtersObject[]
getProduct(id)conv Product by IDObject|null
getPrice(id)conv Product pricenumber
getStock(id)conv Product stocknumber
getCategories()conv Unique categoriesstring[]
search(query)conv Search by name/categoryObject[]
getRelatedProducts(id)conv Related productsObject[]
getUpsells(id)conv Upsells (more expensive)Object[]
getCrossSells(id)conv Cross-sells (complementary)Object[]

Filters: { category, minPrice, maxPrice, search, sort, order, limit }

Cart

MethodDescriptionReturns
getCart()conv Cart copyObject[]
addItem(id, qty?)core Add to cartPromise<void>
clearCart()conv Empty cartvoid
removeCartItem(id)conv Remove itemvoid
updateQuantity(id, qty)conv Update quantityvoid
hasCartItem(id)conv Check if in cartboolean
getCartItemCount()conv Total itemsnumber

Pricing

MethodDescriptionReturns
getSubtotal()conv Cart subtotalnumber
getShippingCost()conv Calculated shippingnumber
getDiscountAmount()conv Discount amountnumber
getTotal()conv Total (never negative)number
calculate()conv Full breakdownObject
formatPrice(amount)conv Format with currencystring

Coupons

MethodDescriptionReturns
addCoupon(coupon)core Register couponvoid
getCoupons()conv All couponsObject[]
applyCoupon(code)conv Apply active couponObject
removeCoupon()conv Remove active couponvoid
validateCoupon(code)conv Check if existsboolean
getActiveCoupon()conv Active coupon or nullObject|null

Shipping

MethodDescriptionReturns
setFixedShipping(value)conv Fixed shippingvoid
setFreeShippingFrom(n)conv Free from nvoid
setPerItemShipping(value)conv Per-item costvoid
getShippingCost()conv Calculated costnumber
isFreeShipping()conv Free shipping?boolean

Customer

MethodDescriptionReturns
setCustomerName(name)conv Customer namevoid
setCustomerAddress(addr)conv Addressvoid
setCustomerNotes(notes)conv Additional notesvoid
getCustomer()conv Data copyObject

Checkout

MethodDescriptionReturns
setPaymentMethod(m)conv Set paymentvoid
setDeliveryMethod(m)conv Set deliveryvoid
validateCheckout()core Validate required datatrue
createOrder(meta?)core Create orderPromise<Object>

Orders

MethodDescriptionReturns
getOrder(id)conv Order by IDObject|null
getLastOrder()conv Last orderObject|null
listOrders()conv All ordersObject[]
updateOrderStatus(id, s)conv Update statusObject
cancelOrder(id)conv Cancel and removeObject

Valid statuses: pending, confirmed, shipped, delivered, cancelled

WhatsApp

MethodDescriptionReturns
setWhatsAppNumber(n)core Set numbervoid
sendToWhatsApp(order)core Generate wa.me linkPromise<string>
generateMessage(order)core Generate messagePromise<string>
registerWhatsAppTemplate(id, fn)conv Register templatevoid
getShareCatalogUrl(opts?)conv Share catalog URLstring
getThankYouHtml(opts?)conv Thank-you page HTMLstring

Multi-Currency

MethodDescriptionReturns
setCurrency(code)core Set active currencyvoid
getCurrency()conv Active currencystring
getExchangeRate(code)conv Exchange ratenumber
convertPrice(basePrice)conv Convert pricenumber

Config: { currencies: { USD: 1, DOP: 56.5, EUR: 0.92 } }

Multi-Region

MethodDescriptionReturns
setRegion(code)core Set active regionvoid
getRegion()conv Active regionstring|null
getTax(productId?)conv Tax ratenumber
getTaxName()conv Tax namestring

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.

HookPayloadFires when
beforeAddToCart{ productId, quantity }Before adding item
afterAddToCartcart itemsAfter adding item
afterCartChangecart itemsAfter any cart change
beforeCheckoutmetaBefore creating order
afterCheckoutorderAfter creating order
beforeWhatsAppSendorderBefore generating link
onRemoveItem{ productId, cart }Removing item from cart
onCartEmpty{ cart }Emptying the cart

Hooks can abort by returning { abort: true, message: "..." }

Security

MethodDescriptionReturns
_sanitizeString(str)int Escape HTML entitiesstring
_sanitizeObject(obj)int Recursively sanitizeObject

_sanitizeString() escapes < > " ' & to prevent XSS.

Scalability

MethodDescriptionReturns
loadFromSources(sources)core Load from multiple sourcesPromise<Object[]>
cacheProducts(ttl?)conv Cache to localStoragevoid
getProductsPaginated(p, sz)conv Paginated productsObject
createProductIterator(b?)conv Lazy loading iteratorObject

Persistence

MethodDescriptionReturns
save()int Serialize to JSONstring
load(json)int Restore from JSONvoid
reset()conv Clear statevoid

Seasons

Requires whanda-plugins.min.js

MethodDescriptionReturns
createSeason(config)Create seasonvoid
getSeasons()All seasonsObject[]
getActiveSeason()Active season by dateObject|null
isInSeason(productId)In season?boolean

Config: { id, name, start, end, type, discount, products, couponCode }

Urgency

Requires whanda-plugins.min.js

MethodDescriptionReturns
setProductUrgency(id, cfg)Set urgencyvoid
getUrgency(id)Urgency dataObject|null
getLowStockProducts()Low stock productsObject[]

Config: { lowStock, countdown, badge }

Bundles

Requires whanda-plugins.min.js

MethodDescriptionReturns
createBundle(config)Create bundlevoid
getBundles()All bundlesObject[]
addBundle(id, qty?)Add bundle to cartPromise<void>
deleteBundle(id)Delete bundlevoid

Config: { id, name, products, type, discount }. Products: ["id1", "id2"] or [{ productId: "id1", quantity: 1 }]

Downsells

Requires whanda-plugins.min.js

MethodDescriptionReturns
setDownsell(config)Set downsellvoid
getDownsell()Current configObject|null
clearDownsell()Remove downsellvoid

Config: { trigger, type, value, message, alternativeProductId }

CRO (Headless)

Requires whanda-plugins.min.js

CRO is headless — provides data, you render the UI.

MethodDescriptionReturns
setCRO(config)Configure CROvoid
getCROData()All CRO dataObject
trackProductView(id)Track product viewvoid
getRecentlyViewed()Recently viewedObject[]
checkFreeShippingProgress()Shipping progressObject

Config: { freeShippingBar, freeShippingGoal, lowStockAlert, recentlyViewed, socialProof, exitIntent, exitMessage, exitDiscount }

Google Sheets Adapter

Requires whanda-sheets.js

FunctionDescriptionReturns
loadFromSheets(w, opts)Load from SheetsPromise<Object[]>
parseCSV(text)Parse CSV to productsObject[]
buildGoogleSheetsCsvUrl(url)Convert URL to CSV exportstring

Options: sheetUrl (public sheet) or proxyUrl (serverless proxy, recommended for production).

Extensions

Requires whanda-extensions.min.js

MethodDescriptionReturns
exportOrders()Export orders as CSVstring

Error Codes

Core

CodeMessage
W001search() requires a search text
W002Product not found
W003Quantity must be a positive integer
W004Insufficient stock
W018Cart is empty
W019Customer name is required
W020Customer address is required
W021Payment method is required
W022Delivery method is required
W025WhatsApp number not configured
W035setProducts() requires an array
W039Hook cancelled
W040Invalid JSON in load()

Plugins

CodeMessage
W100Bundle requires id, name, and products
W101Bundle not found
W102Season requires id, name, start, and end
W103Downsell requires a positive numeric discount
W104Urgency requires at least one of: lowStock, deadline, or badge
W105Season dates must be valid
W106Element with that ID already exists