Get started with shopify-buy CDN

MIT licensed

Shopify Buy: library for custom, frictionless buying, enabling in-page product purchase.

Tags:
  • shopping
  • cart
  • shopify

Stable version

Copied!

How to start using shopify-buy CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with shopify-buy CDN - cdnhub.io</title>
  <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
  <script src="https://cdn.cdnhub.io/shopify-buy/2.21.1/shopify-buy.umd.min.js"></script>
</head>
<body>
  <button id="buy-button">Buy Now</button>
  <script>
    const shopify = {
      storefrontAccessToken: 'your_storefront_access_token',
      apiVersion: 2021_04,
      shopName: 'your_shop_name'
    };

    const buyButton = document.getElementById('buy-button');

    shopify.initCheckoutSession().then((checkoutSession) => {
      buyButton.addEventListener('click', async () => {
        const lineItems = [{
          title: 'Product 1',
          variantId: 'variant_id_1',
          quantity: 1
        }];

        const session = await shopify.checkout.createSession({
          checkoutSessionId: checkoutSession.id,
          lineItems
        });

        window.location = session.url;
      });
    }).catch((error) => {
      console.error(error);
    });
  </script>
</body>
</html>

All versions