> For the complete documentation index, see [llms.txt](https://docs.ecwid.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ecwid.com/discounts-and-tips/add-tips-or-surcharges-to-the-store/add-tips-selection-to-the-checkout.md).

# Add tips selection to the checkout

You can add a configurable block with tip selections for customers at the end of 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 [Quickstart guide](https://docs.ecwid.com/storefronts/get-started/quickstart-customize-storefront-with-ecwid-js-api.md).

### Configure the tips block with the code

Start easily with the code example below:

```javascript
Ecwid.OnAPILoaded.add(function () {
	Ecwid.OnPageLoaded.add(function (page) {
		if (page.type == "CART") {
			window.ec = window.ec || {};
			ec.order = ec.order || {};
			ec.order.extraFields = ec.order.extraFields || {};

			ec.order.extraFields.tips = {
				'type': 'toggleButtonGroup',
				'options': [
					{
						'title': 'No tip',
					},
					{
						'title': '5%',
						'surcharge': 5
					},
					{
						'title': '10%',
						'surcharge': 10
					}
				],
				'surchargeType': 'PERCENT',
				'surchargeShortName': {
					'name': 'Tip',
					'showSurchargePercentValue': true,
					'nameTranslated': {
						'en': 'Tip',
						'nl': 'Tip'
					}
				},
				'showZeroSurchargeInTotal': false,
				'required': true,
				'checkoutDisplaySection': 'payment_details'
			};

			window.Ecwid && Ecwid.refreshConfig();
		}
	});
});
```

This example adds a required extra field where customers must choose one of the tip options specified in the code (0%, 5%, 10%). By default, the last option is chosen when the extra field is required (`'required': true`).

For customers, it will look like this:

<figure><img src="https://2472323273-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpZxwtrnfjGn9RK75zT5A%2Fuploads%2FINJZFCsEkwn0HAGjtyOe%2Fextrafield_tips.png?alt=media&amp;token=959cf5b1-504b-4038-b6b2-c5553d3b85f2" alt=""><figcaption></figcaption></figure>

You can specify your tip values by changing numbers and adding/removing objects in the `options` array.

### See also

Full documentation on setting up extra fields with tips selection:

[Checkout extra fields](https://docs.ecwid.com/api-reference/rest-api/checkout-extra-fields.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ecwid.com/discounts-and-tips/add-tips-or-surcharges-to-the-store/add-tips-selection-to-the-checkout.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
