> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# Method name: getShippingRates(options: Options, context: Context)

# Method package: wixEcom

# Method menu location: wixEcom --> EcomShippingRates --> getShippingRates

# Method Link: https://dev.wix.com/docs/velo/events-service-plugins/e-commerce/service-plugins/ecom-shipping-rates/get-shipping-rates.md

# Method Description:

Retrieves shipping rates provided by a custom shipping rates plugin.

This function is automatically called by Wix eCommerce to retrieve the shipping rates provided by your plugin.
This happens when actions are performed on the cart/checkout entities/pages and/or when there is a change to any property in the `options` parameter. For example, when an item is added to the cart.

> **Notes:**
+ Every time `getShippingRates()` is called, the response is cached. This cache is valid for 10 minutes and is used until a change is made to any property in the `options` parameter, at which point the cache is refreshed.
+ If your plugin fails to respond within 10 seconds, the call will purposefully fail to ensure a smooth user experience. We recommend optimizing your logic: calls to external APIs take longer and are outside our control; use fewer wixData actions when possible.

### Where to find `getShippingRates()`
When you [add the Shipping Rates service plugin](https://dev.wix.com/docs/develop-websites/articles/code-tutorials/wix-e-commerce-stores/e-commerce-shipping-rates-custom-extension.md#step-1-create-a-new-shipping-rates-extension), 
a folder is automatically added to your site. Use the `.js` file in the folder to write your custom shipping rates code. 

For more information on customizing your shipping rate options, see [Tutorial: Shipping Rates Service Plugin](https://dev.wix.com/docs/develop-websites/articles/code-tutorials/wix-e-commerce-stores/e-commerce-shipping-rates-custom-extension.md#my-extension-namejs).



# Method Code Examples:

*** Note: do not assume any prop names or enum values other than the ones in the example.

## Example of a `shippingRates` return value

```javascript
export const getShippingRates = (options) => {

  return {
    "shippingRates": [{
      "code": "usps-international",
      "title": "USPS - International",
      "logistics": {
        "deliveryTime": "2-5 days"
      },
      "cost": {
        "price": "15",
        "currency": "USD",
        "additionalCharges": [{
          "price": "10",
          "type": "HANDLING_FEE",
          "details": "Handling fee of $5 applied for fragile items."
        }]
      }
    }]
  };
};
```

## Return shipping rates based on quantity of items in a cart

```javascript
export const getShippingRates = (options) => {
  return getShippingRatesByQuantity(options)
}

// Tally the quantity of all items
function calculateTotalCartQuantity(lineItems) {
  return lineItems.reduce((acc, lineItem) => acc += lineItem.quantity, 0);
}

// Return shipping rates based on the calculated items' quantity
function getShippingRatesByQuantity(options) {
  const cartQuantity = calculateTotalCartQuantity(options.lineItems);

  if (cartQuantity >= 3) {
    return {
      shippingRates: [{
        code: 'quantity_more_3',
        title: 'Quantity > 3',
        logistics: {
          deliveryTime: '3-5 Days'
        },
        cost: {
          price: '10.00',
          // Currency value is taken from provided options object
          currency: "USD"
        }
      }]
    };
  };

  // If cartQuantity is less than 3, the following shipping rate is returned
  return {
    shippingRates: [{
      code: 'quantity_more_1',
      title: '1 Item',
      logistics: {
        deliveryTime: '3-5 Days'
      },
      cost: {
        price: '20.00',
        currency: "USD"
      }
    }]
  };
};
```

---