> 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](/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="/files/BF3DskEjt9EONkUmy72A" 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](/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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
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=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
