Skip to content

Instantly share code, notes, and snippets.

@jywarren
Last active May 23, 2019 21:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jywarren/97e5c9a056429c7d74f9e93c9a0e5041 to your computer and use it in GitHub Desktop.
Save jywarren/97e5c9a056429c7d74f9e93c9a0e5041 to your computer and use it in GitHub Desktop.

Wrap in:

<div style="margin:20px 0;">
</div>

Add:

      function loadScript() {
        if (!window.hasOwnProperty('shopify')) {
        shopify = true;
        var script = document.createElement('script');
        script.async = true;
        script.src = scriptURL;
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
        script.onload = ShopifyBuyInit;
        }
      }

Then remove these sections:

        "@media (min-width: 601px)": {
          "margin-left": "-20px"
        }

Full code -- replace 499905232924 with the product ID:

<div style="margin:20px 0;">
<div id='product-component-ab665e9d252'></div>
    <script type="text/javascript">
    /*<![CDATA[*/

    (function () {
      var scriptURL = 'https://sdks.shopifycdn.com/buy-button/latest/buy-button-storefront.min.js';
      if (window.ShopifyBuy) {
        if (window.ShopifyBuy.UI) {
          ShopifyBuyInit();
        } else {
          loadScript();
        }
      } else {
        loadScript();
      }


      function loadScript() {
        if (!window.hasOwnProperty('shopify')) {
        shopify = true;
        var script = document.createElement('script');
        script.async = true;
        script.src = scriptURL;
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
        script.onload = ShopifyBuyInit;
        }
      }

      function ShopifyBuyInit() {
        var client = ShopifyBuy.buildClient({
          domain: 'publiclab.myshopify.com',
          storefrontAccessToken: 'ea3cc579c4c8dfc19b1de781173fc46e',
        });

        ShopifyBuy.UI.onReady(client).then(function (ui) {
          ui.createComponent('product', {
            id: [499905232924],
            node: document.getElementById('product-component-ab665e9d252'),
            moneyFormat: '%24%7B%7Bamount%7D%7D',
            options: {
  "product": {
    "variantId": "all",
    "contents": {
      "imgWithCarousel": false,
      "variantTitle": false,
      "description": false,
      "buttonWithQuantity": false,
      "quantity": false
    },
    "styles": {
      "product": {},
      "compareAt": {
        "font-size": "12px"
      }
    }
  },
  "cart": {
    "contents": {
      "button": true
    },
    "styles": {
      "footer": {
        "background-color": "#ffffff"
      }
    }
  },
  "modalProduct": {
    "contents": {
      "img": false,
      "imgWithCarousel": true,
      "variantTitle": false,
      "buttonWithQuantity": true,
      "button": false,
      "quantity": false
    },
    "styles": {
      "product": {}
    }
  },
  "productSet": {
    "styles": {
      "products": {}
    }
  }
}
          });
        });
      }
    })();
    /*]]>*/
    </script>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment