I have successfully added an additional cost to the cart/checkout using the YouTube tutorial; however, only a flat rate. I'm interested in adding a fee based on a percentage of the subtotal.
Hi Tiffany, A percentage based fee can be calculated using the options that are passed into the calculateAdditionalFees() function. The total price can be aggregated from all the line items and multiplied by the percentage. https://dev.wix.com/docs/velo/api-reference/wix-ecom-v2/service-plugins-spis/ecom-additional-fees/calculate-additional-fees For example:
import wixSiteBackend from "wix-site-backend"; const FEE = 0.3; //30% fee export const calculateAdditionalFees = async (options) => { let additionalFees = []; const currency = await wixSiteBackend.generalInfo.getPaymentCurrency(); const {lineItems} = options; const totalPrice = lineItems.reduce((total, item)=> Number(item.price)*item.quantity, 0); additionalFees.push({ code: "percentage-fee", name: "Percentage Fee", price: String(totalPrice*FEE), taxDetails: { taxable: true, }, }); return { currency, additionalFees, }; };
Note - the above code is untested. Best, Eitan