Tools hooks
This page lists the 8 hooks of this group. Each entry shows its type, the version it arrived in, where it runs, its arguments and a starting point.
addochat_account_dataaddochat_order_by_numberaddochat_order_trackingaddochat_page_contextaddochat_product_query_argsaddochat_tool_calledaddochat_tool_resultaddochat_tools
addochat_account_data
FilterSince 0.2.0 Runs in src/Tools/MyAccount.php.
Filters what the assistant gets about the account of the logged-in visitor. Remove fields you do not want sent to the AI or webhook (for example phone or addresses), or add your own.
| Argument | Type | Description |
|---|---|---|
$data | array<string, mixed> | Account: name, email, phone, billing, shipping, orders, customer_since. |
$user | \WP_User | The logged-in customer. |
add_filter( 'addochat_account_data', function ( $data, $user ) {
return $data;
}, 10, 2 );
addochat_order_by_number
FilterSince 0.1.0 Runs in src/Tools/LookupOrder.php.
Filters the order for an order number. Return a WC_Order when the shop uses its own numbering; return false when the number is not an order of this shop, so AddoChat does not try it as an order id (own numbers can overlap with the ids of other orders); leave null to use the order id.
| Argument | Type | Description |
|---|---|---|
$order | \WC_Order|false|null | Order found so far. |
$number | string | Order number as the visitor gave it. |
add_filter( 'addochat_order_by_number', function ( $order, $number ) {
return $order;
}, 10, 2 );
addochat_order_tracking
FilterSince 0.1.0 Runs in src/Tools/LookupOrder.php.
Filters the tracking of an order. WooCommerce has no standard place for it; return a list of carrier, code and url from your shipping plugin.
| Argument | Type | Description |
|---|---|---|
$tracking | array<int, array{carrier: string, code: string, url: string}> | Tracking, empty by default. |
$order | \WC_Order | The order. |
add_filter( 'addochat_order_tracking', function ( $tracking, $order ) {
return $tracking;
}, 10, 2 );
addochat_page_context
FilterSince 0.2.0 Runs in src/Tools/PageText.php.
Filters the text of a page the assistant or a colleague reads, for example to add custom fields or leave out a part. Return '' to give nothing.
| Argument | Type | Description |
|---|---|---|
$text | string | Plain text of the content, paragraphs separated by a blank line. |
$post | \WP_Post | The post. |
$url | string | Address the visitor is on. |
add_filter( 'addochat_page_context', function ( $text, $post, $url ) {
return $text;
}, 10, 3 );
addochat_product_query_args
FilterSince 0.1.0 Runs in src/Tools/SearchProducts.php.
Filters the wc_get_products() arguments of the product search tool.
| Argument | Type | Description |
|---|---|---|
$args | array<string, mixed> | Query arguments. |
$query | string | Search words. |
$context | \Addochat\Tools\Context | Who the call is for. |
add_filter( 'addochat_product_query_args', function ( $args, $query, $context ) {
return $args;
}, 10, 3 );
addochat_tool_called
ActionSince 0.1.0 Runs in src/Tools/Registry.php.
Fires after a tool ran. No input or result: use addochat_tool_result for those.
| Argument | Type | Description |
|---|---|---|
$name | string | Tool name. |
$context | \Addochat\Tools\Context | Who the call is for. |
$ok | bool | Whether it worked. |
$duration | int | Milliseconds. |
add_action( 'addochat_tool_called', function ( $name, $context, $ok, $duration ) {
// ...
}, 10, 4 );
addochat_tool_result
FilterSince 0.1.0 Runs in src/Tools/Registry.php.
Filters the result of a tool before the assistant sees it.
| Argument | Type | Description |
|---|---|---|
$result | array<string, mixed> | content (text for the model), data, is_error, and maybe cards, handoff and refs (since 0.2.0: what it used, as type order|product|customer|page and id) and cart (since 0.2.0: products offered for the cart). |
$name | string | Tool name. |
$context | \Addochat\Tools\Context | Who the call is for. |
add_filter( 'addochat_tool_result', function ( $result, $name, $context ) {
return $result;
}, 10, 3 );
addochat_tools
FilterSince 0.1.0 Runs in src/Tools/Registry.php.
Filters the tools of AddoChat. Add an object that implements \Addochat\Tools\Tool; it shows in the allowed tools setting, the MCP server and the Direct backend.
| Argument | Type | Description |
|---|---|---|
$tools | array<int, \Addochat\Tools\Tool> | Tools. |
add_filter( 'addochat_tools', function ( $tools ) {
return $tools;
} );