LogoLogo
Build appsContact API support
Discounts and tips
  • Build apps
  • Site Templates
  • API Reference
  • Changelog
Discounts and tips
  • Discounts and tips overview
  • Add discounts to the store
    • Automatic discounts (promotions)
    • Discount coupons
    • Bulk discount prices for products
    • Discounts calculated on your server
  • Add tips or surcharges to the store
    • Add tips selection to the checkout
    • Apply hidden surcharges
    • Calculate surcharges on your server
  • Customize discounts
    • Set up "Buy X - Get Y" promotions
    • Set up "Free shipping" promotions
    • Set up start and end dates for discounts
    • Limit discounts to customer groups
    • Limit discounts by products and categories
    • Limit the number of discount coupon uses

Lightspeed® 2025

On this page
  • Connect JS API
  • Configure the hidden surcharge
  • See also

Was this helpful?

  1. Add tips or surcharges to the store

Apply hidden surcharges

PreviousAdd tips selection to the checkoutNextCalculate surcharges on your server

Last updated 2 months ago

Was this helpful?

You can add a hidden surcharge or a fee at the checkout with JavaScript code.

Connect JS API

To apply the JavaScript code, you need to enable Ecwid JS API on your storefront. To do so, set up a self-hosted JavaScript file running on your server and use the code example below.

Jump into the .

Configure the hidden surcharge

With Ecwid JS API enabled, you can use extra fields to apply a hidden surcharge to the order, for example, as an extra processing cost for some shipping methods.

To do so, you need to create an extra field with only 4 attributes and no others:

  • value with an internal name for the surcharge (customers won't be able to see it).

  • surchargeShortName with showSurchargePercentValue set to false.

  • options with only one option that has a surcharge value.

  • surchargeType that defines if the surcharge is calculated as a flat value (absolute) or percentage from the order total (percent).

Code example:

Ecwid.OnAPILoaded.add(function () {
	Ecwid.OnPageLoaded.add(function (page) {
		if (page.type == "CART") {
			// Initialize extra fields
			window.ec = window.ec || {};
			ec.order = ec.order || {};
			ec.order.extraFields = ec.order.extraFields || {};

			// Set order surcharge
			//'surcharge' part after the 'ec.order.extraFields.' becomes ID of the extra field
			ec.order.extraFields.surcharge = {
				'value': 'Custom charge',
				"options": [
					{
						"title": "Custom charge",
						"surcharge": 5
					},
				],
				"surchargeShortName": {
					"name": "Surcharge",
					"showSurchargePercentValue": false
				},
				'surchargeType': 'PERCENT'
			}
			window.Ecwid && Ecwid.refreshConfig();
		}
	});
});

This example applies a 5% surcharge at the checkout. The surcharge is invisible to the customers but visible to the store owner.

See also

Full documentation on setting up extra fields with hidden surcharges:

Quickstart guide
Checkout extra fields