Mobashir
Mobashir

Reputation: 430

shopify js buy sdk not working in wordpress

I want to use shopify js buy sdk with wordpress. I've downloaded the sdk files and follow the steps as described in the documentation

import Client from 'shopify-buy';

const client = Client.buildClient({
  domain: 'your-shop-name.myshopify.com',
  storefrontAccessToken: 'your-storefront-access-token'
});

But It always give an error, which says import declarations may only appear at top level of a module.

So I've keep it at the top and add type="module" at the script tag. then the error is solved, but javascript code within this script is not working...

So, can anyone tell me what can I deo to solve this problem?

Upvotes: 0

Views: 658

Answers (1)

Ucinorn
Ucinorn

Reputation: 718

If you aren't using any of the Node or JS package managers then try using the UMD package available on their documentation page:

<script src="http://sdks.shopifycdn.com/js-buy-sdk/v1/latest/index.umd.min.js"></script>

You can use it like any other js script, it exposes a global window.ShopifyBuy factory.

Then use it like this:

const client = window.ShopifyBuy.buildClient({
  domain: 'your-shop-name.myshopify.com',
  storefrontAccessToken: 'your-storefront-access-token'
});

Upvotes: 2

Related Questions