Skip to content

Instantly share code, notes, and snippets.

@stackdumper
Last active May 27, 2021 07:53
Show Gist options
  • Save stackdumper/1211ce7d285d9f14160a110918910bda to your computer and use it in GitHub Desktop.
Save stackdumper/1211ce7d285d9f14160a110918910bda to your computer and use it in GitHub Desktop.
if (window.location.pathname == "/cart") {
fetch("/cart.js")
.then((res) => res.json())
.then((t) => JSON.stringify(t.items.map((t) => [t.product_title, t.id, t.quantity])))
.then(JSON.stringify)
.then(btoa)
.then((qcCartId) => {
console.log("QC CART ID", qcCartId);
var checkoutButton = document.querySelector("input[name=checkout]");
checkoutButton.setAttribute("name", "quickCheckout");
checkoutButton.setAttribute("type", "button");
checkoutButton.addEventListener("click", () => {
console.log("quick checkout!");
window.location.href = `http://localhost:8081/${qcCartId}`;
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment