calculateAdditionalFees( )


Calculates additional fees to include in the cart and checkout pages.

The calculateAdditionalFees function calculates additional fees to appear in the cart and checkout pages of a store's site. The function is automatically called by Wix when the cart totals are calculated, or when an action is performed in the cart and/or checkout pages. For example, when an item is added to the cart, or when a shipping location is specified.

Where to find calculateAdditionalFees()

When you add the Additional Fees service plugin, a folder is automatically added to your site. Use the .js file in the folder to write the code to calculate any additional fees to add to the cart or checkout.

For more information on calculating your additional fees, see Velo Tutorial: eCommerce Additional Fees Service Plugin.

Method Declaration
Copy
function calculateAdditionalFees(
  options: Options,
  context: Context,
): Promise<CalculateAdditionalFeesResponse>;
Method Parameters
optionsOptionsRequired

Options for line items and shipping options.


contextContextRequired

Metadata about the request.

Returns
Return Type:Promise<CalculateAdditionalFeesResponse>
Calculate additional fees for an order

This example calculates the additional fees for packaging fragile items from a store. If more than 5 fragile items are added to the cart, the fragile packaging is free.

JavaScript
import wixSiteBackend from "wix-site-backend"; export const calculateAdditionalFees = async (options) => { let additionalFees = []; const feePrice = calculateWrappingFee(options.lineItems); const currency = await wixSiteBackend.generalInfo.getPaymentCurrency(); if (feePrice) { additionalFees.push({ code: "fragile-packaging", name: "Fragile Packaging", price: String(feePrice), taxDetails: { taxable: true, }, }); } return { currency, additionalFees, }; }; // Check if an item is fragile. function isFragile(item) { const productName = item.productName.toLowerCase(); return productName.includes("glass") || productName.includes("ceramic"); } // Charge per fragile item. // Give away free packaging when ordering at least 5 items. function calculateWrappingFee(lineItems) { const minItemsForFreeWrapping = 5; let numFragileItems = 0; lineItems.forEach((item) => { if (isFragile(item)) { numFragileItems += item.quantity; } }); const shouldChargeFee = numFragileItems < minItemsForFreeWrapping; const price = shouldChargeFee ? numFragileItems : 0; return price; }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?