> For the complete documentation index, see [llms.txt](https://alhena.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alhena.gitbook.io/docs/developer-reference/website-sdk/examples/price-conversion.md).

# Price Conversion

The convert price hook lets you transform product prices before they are displayed in product cards. The hook function receives the original price and a metadata object, and should return the formatted price string.

## Hook Signature

```javascript
function convertPrice(price, metadata) { ... }
```

| Argument             | Type                | Description                                   |
| -------------------- | ------------------- | --------------------------------------------- |
| `price`              | string              | The original product price (e.g., `"$29.99"`) |
| `metadata.variantId` | string \| undefined | The external variant ID of the product        |

## Setting the Hook

There are two ways to set the hook:

### At initialization

```javascript
document.gleenConfig = {
  company: "your-company-key",
  apiBaseUrl: "https://app.alhena.ai",
  convertPrice: function (price, metadata) {
    return price;
  },
};
```

### After widget load

```javascript
window.gleenWidget.setConvertPriceHook(function (price, metadata) {
  return price;
});
```

Use `setConvertPriceHook` when the hook needs to be set or updated dynamically after the widget has loaded.

## Examples

### Currency Conversion

```javascript
window.gleenWidget.setConvertPriceHook(function (price, metadata) {
  const amount = parseFloat(price.replace(/[^0-9.]/g, ""));
  const converted = (amount * 0.85).toFixed(2);
  return "€" + converted;
});
```

### Variant-Aware Pricing

Use `metadata.variantId` to show different prices per product variant — for example, sale prices or region-specific pricing.

```javascript
const salePrices = {
  "variant-123": "$19.99",
  "variant-456": "$24.99",
};

window.gleenWidget.setConvertPriceHook(function (price, metadata) {
  if (metadata.variantId && salePrices[metadata.variantId]) {
    return salePrices[metadata.variantId];
  }
  return price;
});
```

### Locale-Based Formatting

```javascript
window.gleenWidget.setConvertPriceHook(function (price, metadata) {
  const amount = parseFloat(price.replace(/[^0-9.]/g, ""));
  return new Intl.NumberFormat("de-DE", {
    style: "currency",
    currency: "EUR",
  }).format(amount * 0.85);
});
```


---

# 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://alhena.gitbook.io/docs/developer-reference/website-sdk/examples/price-conversion.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.
