New — Sohay now answers WooCommerce product, policy & cart questions. See how →

Customising Sohay with code

Worked examples for the customisations that actually come up, and where to put them.

Working examples for the changes people ask for most. Each is a complete snippet you can drop in.

Where to put it

A small plugin of your own, or a site-specific mu-plugin.

A theme’s functions.php works and ties your customisations to the theme — switch themes and they vanish, usually at the worst moment. For anything that changes what data leaves your site, that is a bad property.

Scope the widget to part of the site

add_filter( 'sohaychat_should_render_widget', function ( $enabled ) {
    if ( ! $enabled ) { return false; }
    return function_exists( 'is_shop' ) && ( is_shop() || is_product() );
} );

Respect the incoming $enabled — that is what keeps the admin checkbox meaningful.

Keep catalog answers, never touch the cart

add_filter( 'sohaychat_tools', function ( $tools ) {
    unset( $tools['sohaychat-wc/get-cart'], $tools['sohaychat-wc/update-cart'] );
    return $tools;
} );

Removing a tool means the chatbot is never told it exists, so it can neither call it nor send its data upstream.

Pin the model list

add_filter( 'sohaychat_allowed_openai_models', function () {
    return array( 'gpt-4o-mini' );
} );

A ceiling on spend that no admin-screen mistake can undo. Useful where several people can reach AI Settings.

Set spend caps in code

add_filter( 'sohaychat_usage_tracker_options', function ( $opts ) {
    $opts['site_cap']  = 5000000;
    $opts['actor_cap'] = 25000;
    return $opts;
} );

Ceilings reset at UTC midnight. 0 disables one.

Fix per-visitor limits behind a proxy

add_filter( 'sohaychat_rate_limit_options', function ( $opts ) {
    $opts['proxy_support'] = true;
    return $opts;
} );

Only when your site is reachable exclusively through the trusted proxy, and that proxy overwrites the client-IP headers on every request. On an origin also reachable directly, a visitor can forge them. See Daily token caps and rate limits.

Ship errors somewhere permanent

add_action( 'sohaychat_log_error', function ( $message, $context ) {
    // Sentry, Stackdriver, your own logger.
}, 10, 2 );

The Diagnostics buffer holds 100 entries, which answers “what just happened?” and not “what happened at 3am on Tuesday?”.

Restrict what an operator can see

sohaychat_admin_conversation_scope narrows which conversations a non-admin operator can reach, beyond the built-in assigned-or-unassigned scoping.

Reseller links

sohaychat_help_url and sohaychat_upgrade_url override the admin header’s Help and Upgrade links, so they point at your support rather than ours.

Provider-specific request settings

sohaychat_provider_options carries per-provider settings — Gemini’s safety thresholds, thinking budget, or search grounding.

Where to go next

Hooks and filters — where to start for the full map, and Adding your own chat tool to give the chatbot a new capability.

Mithun B.
Mithun B.

More articles by Mithun B..

View all posts

Give your website an assistant that answers from your content

Grounded answers, a team inbox, and store-aware tools — free on WordPress.org.

Add Sohay — Free

Free plugin · You bring your OpenAI key · Works with any theme