algoliaAutocompleteConfig.hooks or algoliaInstantsearchConfig.hooks.
Use custom hooks
To use these hooks, add a new JavaScript file to your theme using the BigCommerce Script Manager.Create a script file
- Go to the BigCommerce Script Manager and click Create a Script.
-
Complete the script form settings:
- Name. Enter a name for the script.
- Description. Enter a description for the script.
- Placement. Select
Header. - Location. Select
All pages. - Script Category. Select
Essential. - Script type. Select
Script.
- If you want to add custom JS code for Autocomplete or InstantSearch hooks, add it to the Script Contents field.
JavaScript
Autocomplete hooks
The following hooks change the behavior of the autocomplete menu:autocompleteInitOptions
Sets parameters for the autocomplete menu.
Example:
JavaScript
autocompleteResultTemplate
Changes the HTML template that renders the Autocomplete results panel
Example:
JavaScript
InstantSearch hooks
The following hooks change the behavior of the search results page:instantSearchInitOptions
Changes InstantSearch options.
Example:
JavaScript
instantSearchResultTemplate
Changes the HTML template that renders the Autocomplete results panel
Example:
JavaScript
Recommend hooks
The following hooks change the options used for initializing Recommend:recommendInitOptions
Changes the Recommend initialization options.
For example:
JavaScript
recommendResultTemplate
Changes the HTML template that renders the Recommend results panel.
For example:
JavaScript
Add new custom hooks
To add new custom hooks, add them to the allowed list and edit the JavaScript file to add a new event trigger. You can’t add custom hooks for Recommend.Add new hooks to the allowed list
- Go to the BigCommerce Script Manager.
- Create or edit BigCommerce Algolia hooks script.
-
Add the new hook to the
allowedHooksarray.
JavaScript
JavaScript
Edit the JavaScript file
- Edit your Autocomplete or InstantSearch JavaScript file in Search Settings.
- Add a new event trigger to the JavaScript file.
JavaScript
JavaScript