How to Build a Custom Dashboard Widget for Your Store Admin
A custom dashboard widget on ShopsWired is part of a plugin: declare it in manifest.json, export a fetch(ctx) function that reads store data through the sw.* bridges, and return HTML rendered from a Liquid template. The admin then lists it in the dashboard gallery next to the built-in Revenue and Orders cards, and the merchant drags it onto any dashboard. There is no client SDK and no build step — it is the same server-side JavaScript you already write for routes and hooks.
The built-in widgets cover the numbers every store has. A plugin widget is for the number only your store cares about: the orders a warehouse is behind on, the reviews waiting for approval, the stock a supplier has promised. We'll build the first one — a card that lists paid orders still waiting to ship, oldest first, and flags any that have waited longer than a threshold the merchant sets.
What you need
- A store on a plan that includes building your own plugins. That starts on Pro, which is $99/mo; Starter runs a full store on ready-made themes and plugins, including widgets other developers publish.
- A plugin to put the widget in. If you haven't made one yet, build your first plugin covers the manifest, developer mode and the CLI loop. Everything below is files you add to that plugin.
Step 1: declare the widget in the manifest
A widget is declared twice in manifest.json: a scripts[] entry with "type": "widget" that maps a file to a widget id, and a widgets[] entry that describes the card in the gallery.
{
"scripts": [
{
"path": "widgets/to-ship.js",
"type": "widget",
"widget_id": "to-ship"
}
],
"widgets": [
{
"id": "to-ship",
"name": "Waiting to Ship",
"icon": "📦",
"description": "Paid orders that haven't shipped yet, oldest first.",
"source": {
"type": "internal",
"script": "widgets/to-ship.js"
},
"permissions": ["Reads: orders"],
"config_defs": [
{ "key": "warn_days", "type": "number", "label": "Flag orders older than (days)", "default": 2 }
],
"defaults": {
"width": "1/2",
"rows": 4,
"config": { "warn_days": 2 }
},
"placement": {
"dashboard": true,
"page": { "menu": true, "group": "Fulfillment" }
}
}
]
}A few fields carry more weight than they look:
config_defsis a per-instance settings form, the same shape as pluginsettings. Two copies of this widget on two dashboards can have different thresholds.permissionsis display-only. It tells the merchant what the widget reads; what it can actually read is the plugin's normalsw.*scoping.placement.page.menualso adds the widget to the admin's left sidebar as a full page. A page widget has no dashboard to store per-instance config in, so it falls back todefaults.config.defaults.rowsis the starting height in grid rows of roughly 80px. The merchant can resize it.
Step 2: write fetch(ctx)
The widget script exports fetch(ctx), exactly like a route handler. It runs on the server each time the card renders, with the widget's own state under ctx.widget. Put this in widgets/to-ship.js:
// widgets/to-ship.js
module.exports.fetch = function (ctx) {
const warnDays = (ctx.widget.config && ctx.widget.config.warn_days) || 2;
const dayMs = 24 * 60 * 60 * 1000;
const now = Date.now();
// Paid, not yet shipped. status is indexed, so this filter is cheap.
const page = sw.orders.list({ filters: { status: "processing" }, limit: 100 });
const orders = page.items
.filter(function (o) { return !o.digital_only; })
.map(function (o) {
const age = Math.floor((now - new Date(o.created).getTime()) / dayMs);
return {
number: o.number,
customer: (o.customer && o.customer.name) || "Guest",
total: o.totals.total,
currency: o.currency || ctx.widget.shop.currency,
age_days: age,
late: age >= warnDays
};
});
orders.sort(function (a, b) { return b.age_days - a.age_days; });
return sw.liquid.render("./widgets/to-ship.liquid", {
orders: orders,
late_count: orders.filter(function (o) { return o.late; }).length,
warn_days: warnDays,
more: !!page.cursor
});
};Why it's shaped this way:
- Sorting happens in JavaScript. A
listcall can't filter on one field and sort on a different one —{ filters: { status }, order: "created" }fails. With a single page of results, sorting it yourself is the simple answer. - One page, honestly labelled. We take up to 100 orders and pass
morewhen a cursor comes back, so the card says there are more instead of showing a short list as if it were complete. A store with thousands of unshipped orders needs a different tool, not a bigger widget. - Digital orders are skipped.
digital_onlyis computed from the line items, and an order with nothing to ship doesn't belong on a shipping card. - Totals are formatted in the order's currency. An order carries the currency it was charged in; when it's empty we fall back to the store's, from
ctx.widget.shop.
Step 3: the Liquid template
The admin wraps your output in a body with the sw-widget class, which styles plain HTML to match the admin. Write semantic markup and skip the stylesheet. Put this in widgets/to-ship.liquid:
<header class="sw-row">
<h3>Waiting to ship</h3>
{% if late_count > 0 %}
<strong style="color: var(--sw-danger)">{{ late_count }} over {{ warn_days }} days</strong>
{% endif %}
</header>
{% if orders.size == 0 %}
<p class="sw-muted">Nothing waiting. Every paid order has shipped.</p>
{% else %}
<table>
<tr><th>Order</th><th>Customer</th><th>Total</th><th>Waiting</th></tr>
{% for o in orders %}
<tr>
<td>{{ o.number | escape }}</td>
<td>{{ o.customer | escape }}</td>
<td>{{ o.total | money_in: o.currency }}</td>
<td>{% if o.late %}<strong style="color: var(--sw-danger)">{{ o.age_days }}d</strong>{% else %}{{ o.age_days }}d{% endif %}</td>
</tr>
{% endfor %}
</table>
{% if more %}<p class="sw-muted">Showing the first 100.</p>{% endif %}
{% endif %}Two details. The customer name is whatever the shopper typed, so it goes through | escape, and so does the order number for good measure — Liquid doesn't escape output for you. And the red comes from --sw-danger, one of the admin's design tokens, so the widget keeps matching the admin if its colors change.
That's the whole widget. Push the plugin, open a dashboard, and Waiting to Ship is in the gallery. You don't write a refresh button: the card's hover toolbar has one that re-runs fetch(ctx), and changing the threshold in the config panel reloads the card with the new value.
Taking it further
- Buttons inside the card. The same
fetch(ctx)handles requests from inside the widget. Branch onctx.request.methodandctx.request.path, and call it from the browser withsw.fetch, which prefixes the widget's path and attaches the CSRF token. Don't use a native<form>submit — the widget frame blocks it. - On a record's own page. A
placement.detailentry such as{ "entity": "order", "mode": "tab", "label": "Shipments" }puts the widget on every order's detail page as a tab, andctx.widget.entitytells the script which order it's on."mode": "button"opens it in a modal instead. - Who sees it. Merchants choose which widgets each custom role may open, and a widget left off a role's list is hidden everywhere. A role you didn't plan for can still be given your widget, so gate anything sensitive inside it on
ctx.permissions.
Where widgets fall short
- A widget can't call other sites from the browser. It runs in a sandboxed frame on its own origin, and its browser code can only call back to its own widget endpoint. Reach an outside API from
fetch(ctx)on the server instead. - It has 30 seconds. Someone is waiting for the card, so slow or heavy work — walking every order in a large store, a slow outside API — belongs in a background task that stores its result for the widget to read.
- No native
alert,confirmor form posts. Usesw.toast,await sw.confirmandsw.fetch. Existing browser code that leans on those needs rewriting. - If the built-in cards answer the question, use them. Revenue, orders, average order value, top products and order status are already there. A plugin is code you maintain; write one when the store needs a number the platform doesn't show.
The developer docs carry the full widget reference: every manifest field, the reactive sw-* attributes for interactive cards, the record and file pickers, and record-field editors for custom records. Start with one card that answers one question your team asks every morning — that's usually the widget that stays on the dashboard.