Same shape as the drawer: POST to the cart, then re-read it to update the UI. Now it's a grid of buttons, but each one does the same three steps.
fetch("/cart/add.js", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id: id, quantity: 1 }),
})
.then(function (r) { return r.json(); })
.then(function () { return refresh(); }) // re-read the cart, update the count
.then(function () { /* confirm on the button */ });
With many buttons, each handler must add its own product. Read the variant id from that button's data-variant-id inside the handler.
After the cart updates, set the button to read `Added` (and add the `is-added` class) so the shopper sees it worked.