> ## Documentation Index
> Fetch the complete documentation index at: https://docs.khaime.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Live Chat

> Add Khaime live chat to your WordPress site.

# Khaime Live Chat

Connect your WordPress site to your Khaime inbox. Configure it once and the chat widget appears on your site — no theme files to edit, and nothing to re-paste after a theme update.

<Card title="Download Plugin" icon="download" href="https://api.khaime.com/wordpress/download/khaime-chat">
  khaime-chat.zip
</Card>

<Note>
  Uses the same **partner API key** as Khaime Storefront, so running both plugins means one credential to manage.
</Note>

## Setup

1. Install and activate the plugin.
2. Go to **Khaime → Live Chat** and paste your partner API key (from **Settings → API** in your dashboard).
3. The screen confirms the connection and names the store it resolved.

Live chat must also be enabled for your business in the Khaime dashboard. If it isn't, the settings screen says so explicitly rather than failing silently.

<Warning>
  **Live** and **Sandbox** are separate accounts, not two modes of one. Live talks to `api.khaime.com`, Sandbox to `api.khaimedev.com`, and your key only exists in one of them — a `pk_live_` key will not authenticate against Sandbox.
</Warning>

<Note>
  Widget **appearance** — colour, position, launcher label, edge spacing, pre-chat fields — lives in your Khaime dashboard, not in the plugin. Those settings apply to every embed, including stores not built on WordPress.
</Note>

## Filters

### Delay loading until cookie consent

The widget stores a chat session ID in the browser's local storage once it loads. If your visitors are covered by GDPR or similar, hold it back until you have consent:

```php theme={null}
add_filter('khaime_chat_should_load', function ($load) {
    return $load && my_consent_plugin_has_consent();
});
```

### Attach your own data to conversations

Anything under `metadata` arrives with the conversation, so your team sees the context behind a message.

```php theme={null}
add_filter('khaime_chat_visitor', function ($visitor, $metadata) {
    $visitor['metadata']['cart_total'] = WC()->cart?->get_total('edit');
    $visitor['metadata']['tier']       = get_user_meta(get_current_user_id(), 'tier', true);
    return $visitor;
}, 10, 2);
```

<Warning>
  This payload is rendered into the page HTML. Never put secrets, tokens, or API keys in it.
</Warning>

### Override the widget's appearance for this site only

```php theme={null}
add_filter('khaime_chat_script_attributes', function ($attrs) {
    $attrs['data-primary-color'] = '#ff6600';
    return $attrs;
});
```

Supported attributes: `data-primary-color`, `data-font`, `data-api-url`, `data-socket-url`.

## Local development

Point both plugins at a local backend by defining this in `wp-config.php`:

```php theme={null}
define('KHAIME_API_URL', 'http://localhost:4000/api/v1');
```

It overrides the Environment setting entirely.

## Troubleshooting

**The widget isn't appearing**, and the settings screen says it's connected. Live chat also has to be enabled for your business in the Khaime dashboard, and another plugin may be filtering `khaime_chat_should_load` to `false` — cookie-consent plugins commonly do.

**A change you made hasn't taken effect.** Settings are cached. Press **Test connection** to refresh immediately.

### Still stuck?

<CardGroup cols={2}>
  <Card title="Email support" icon="envelope" href="mailto:support@khaime.ai">
    [support@khaime.ai](mailto:support@khaime.ai)
  </Card>

  <Card title="Community" icon="discord" href="https://discord.gg/khaime">
    Ask in the Khaime Discord
  </Card>
</CardGroup>

Include your site URL and whether **Test connection** succeeds — it's the quickest way to tell a configuration problem from a connection one.
