---
title: 'TNT Search add custom Snipcart field'
url: 'https://getgrav.org/forum/plugins/tnt-search-add-custom-snipcart-field-t7236'
markdown: 'https://getgrav.org/forum/plugins/tnt-search-add-custom-snipcart-field-t7236.md'
date: '2026-06-21'
description: 'I am creating a shop for a customer with the Snipcart plugin. There will be a TNT search on the site, using the tntsearch plugin. I checked the docs how to add'
---

[Plugins](https://getgrav.org/forum/plugins)

#   TNT Search add custom Snipcart field 

 [plugin](https://getgrav.org/forum/tag/plugin) [plugins](https://getgrav.org/forum/tag/plugins) [theme](https://getgrav.org/forum/tag/theme)

 Solved by chraebsli [View solution](https://getgrav.org/forum/plugins/tnt-search-add-custom-snipcart-field-t7236#post-40752)

  Started by chraebsli 1 year ago · 1 replies · 776 views    

 [1 year ago](https://getgrav.org/forum/plugins/tnt-search-add-custom-snipcart-field-t7236#post-40751 "Permalink") 

I am creating a shop for a customer with the [Snipcart plugin](https://github.com/Crabston/grav-plugin-snipcart). There will be a TNT search on the site, using the [tntsearch plugin](https://github.com/trilbymedia/grav-plugin-tntsearch). I checked the docs how to add a custom field, and therefore I added this function to the `theme.php`:

```php
// custom TNT Search indexing to add ID field
public function onTNTSearchIndex(Event $e) {
    $fields = $e['fields'];
    $page = $e['page'];

    if (isset($page->header()->snipcart->product_id)) {
        $fields->product_id = $page->header()->snipcart->product_id;
    }
}
```

According to docs, this should create a custom field `product_id` with the content of `page->header()->snipcart->product_id`, but it doesn’t.

Frontmatter of a page looks like this:

```yaml
title: Product Name
snipcart:
  product_id: 1005
  price: 1990.0
```

## Debug

I debugged and here’s what I got:

```php
$this->grav[‘log’]->info(‘Header’, (array)$page->header()->snipcart);

// Output: Here I get the Snipcart object as it should be
Header {"product_id":4012,"price":2990} []
```

```php
$this->grav[‘log’]->info(‘Product ID’, (array)$page->header()->snipcart->product_id);

// Output: Here I tried to access the object I got from the above output and get nothing
Product ID [] []
```

last edited 09/16/25 by chraebsli

 [1 year ago](https://getgrav.org/forum/plugins/tnt-search-add-custom-snipcart-field-t7236#post-40752 "Permalink")  Solution 

Ahh nvm I got it. I accessed it the wrong way. Instead of `$page->header()->snipcart->product_id` it should be `$page->header()->snipcart['product_id']`.

Final PHP:

```php
// custom TNT Search indexing to add ID field
public function onTNTSearchIndex(Event $e) {
    $fields = $e['fields'];
    $page = $e['page'];

    if (isset($page->header()->snipcart['product_id'])) {
        $fields->product_id = $page->header()->snipcart['product_id'];
    }
}
```

 👍 1 

[Log in](https://getgrav.org/login?return=%2Fforum%2Fplugins%2Ftnt-search-add-custom-snipcart-field-t7236) to reply.

###  Suggested topics

 | Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| [Conflict with updated Form plugin and Add Page By Form](https://getgrav.org/forum/plugins/conflict-with-updated-form-plugin-and-add-page-by-form-t9480)    [Plugins](https://getgrav.org/forum/plugins) · by DrPen, 3 weeks ago |  | 2 | 281 | [3 weeks ago](https://getgrav.org/forum/plugins/conflict-with-updated-form-plugin-and-add-page-by-form-t9480 "by DrPen") |
| [grav-mcp update\_page sends lang in the body instead of the query string, so non-default languages are never updated](https://getgrav.org/forum/plugins/grav-mcp-update-page-sends-lang-in-the-body-instead-of-the-query-string-so-non-default-languages-are-never-updated-t9469)    [Plugins](https://getgrav.org/forum/plugins) · by renedebaaij, 4 weeks ago |  | 1 | 260 | [3 weeks ago](https://getgrav.org/forum/plugins/grav-mcp-update-page-sends-lang-in-the-body-instead-of-the-query-string-so-non-default-languages-are-never-updated-t9469 "by Andy Miller") |
| [Tools / Scheduler some jobs not running.](https://getgrav.org/forum/plugins/tools-scheduler-some-jobs-not-running-t9471)    [Plugins](https://getgrav.org/forum/plugins) · by Thomas, 4 weeks ago |  | 1 | 275 | [4 weeks ago](https://getgrav.org/forum/plugins/tools-scheduler-some-jobs-not-running-t9471 "by Thomas") |
| [How to clone a flex object in twig](https://getgrav.org/forum/plugins/how-to-clone-a-flex-object-in-twig-t9438)    [Plugins](https://getgrav.org/forum/plugins) · by complanar, 1 month ago |  | 6 | 593 | [1 month ago](https://getgrav.org/forum/plugins/how-to-clone-a-flex-object-in-twig-t9438 "by complanar") |
| [Integration of GRAV articles into my principal website](https://getgrav.org/forum/plugins/integration-of-grav-articles-into-my-principal-website-t9440)    [Plugins](https://getgrav.org/forum/plugins) · by BenLaKnet, 1 month ago |  | 1 | 497 | [1 month ago](https://getgrav.org/forum/plugins/integration-of-grav-articles-into-my-principal-website-t9440 "by BenLaKnet") |
