DOCS

Shipping methods element

/

Shipping methods element

Learn how to easily display international shipping methods and landed costs with the Shipping Methods elements.

The Shipping Methods allows you to specify item details and get a breakdown of the total cost of the item(s), including duties, taxes, fees, and shipping. Shipping rates will be pulled from your Zonos account, including any customizations you have set up.

Zonos landed cost element example

1

Import the Zonos SDK

React
Vanilla JavaScript

First, install the Zonos Elements package in your React project. This will automatically add the Zonos SDK as a peer dependency, and includes TypeScript typings out of the box for a better developer experience.

Terminal

1
npm install --save @zonos/zonos-elements-react
2

Configure the Zonos SDK

React
Vanilla JavaScript

Once the Zonos Elements package is installed, you can configure the Zonos SDK in your React project. You need to have a Zonos account and API key to use Elements on your site.

The Elements React library exposes a ZonosProvider component that you can use to configure the Zonos SDK. You can wrap your entire application in the ZonosProvider component, or you can wrap only the components that use the Zonos SDK. We recommend storing your Zonos API key in an environment variable and passing it to the ZonosProvider component as a prop for security reasons.

App.js

1
2
3
4
5
6
7
import { ZonosProvider } from '@zonos/zonos-elements-react';

export const App = () => (
  <ZonosProvider config={{ apiKey: process.env.REACT_APP_ZONOS_API_KEY }}>
    {/* The rest of app goes here */}
  </ZonosProvider>
);
3

Create a Shipping Methods element

React
Vanilla JavaScript

To create a Shipping Methods element, use the ShippingMethods component from the Zonos Elements React library. You will need to pass in an array of items, which will be used in the calculation and display of the landed cost. If you're using multiple Elements together, it's up to you how you want to handle keeping the items in sync between the different Elements.

JavaScript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { ShippingMethods } from '@zonos/zonos-elements-react';

export const YourComponent = () => (
  <div>
    {/* The rest of your component goes here */}
    <ShippingMethods
      items={[
        {
          id: '123',
          name: 'Test Product',
          price: 100,
          currencyCode: 'USD',
          quantity: 1,
          imageUrl: 'https://example.com/image.jpg',
          url: 'https://example.com/product',
        },
      ]}
    />
    {/* The rest of your component goes here */}
  </div>
);

Zonos landed cost element example

Was this page helpful?


© 2023 Zonoszonos.com