> 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

Customize how product prices are displayed in the Alhena chat widget using convert price hooks.

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);
});
```
