Black Friday: 79% off every plugin Shop the sale →

Developer Hooks

Everything the plugin exposes uses the swpr prefix: the PHP namespace SWPR\, options swpr_*, the table wp_swpr_chat_logs, the REST namespace swpr/v1 and the hooks below. Put the snippets in a small must-use plugin or your child theme’s functions.php.

Constants (wp-config.php)#

ConstantPurpose
SWPR_API_KEYYour AI provider key. Overrides any key saved in Connections.
LEETCART_STOREENGINE_STORE_URLPoint license checks and updates at a different store (for staging QA). Default https://technoleet.dev.
LEETCART_STOREENGINE_PRODUCT_IDOverride the StoreEngine product ID used for licensing. 0 disables licensing.

Filters#

swpr_client_ip – the IP address used for rate limiting. The plugin uses REMOTE_ADDR only, because forwarding headers can be forged. Behind a trusted proxy or CDN, resolve the real visitor IP yourself:

add_filter( 'swpr_client_ip', function ( $ip ) {
    if ( ! empty( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
        return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CF_CONNECTING_IP'] ) );
    }
    return $ip;
} );

swpr_chat_log_retention_days – days to keep chat messages before the daily swpr_cleanup event deletes them. Default 0 (keep indefinitely).

add_filter( 'swpr_chat_log_retention_days', function () {
    return 90;
} );

swpr_mcp_sse_max_seconds – how long a legacy MCP SSE connection stays open. Default 30 seconds, maximum 300, and never more than PHP’s max_execution_time.

add_filter( 'swpr_mcp_sse_max_seconds', function () {
    return 60;
} );

swpr_storeengine_store_url, swpr_storeengine_product_id, swpr_store_dashboard_url – licensing configuration: the store URL, the product ID and the link behind Manage License. Normally only used on staging sites.

Scheduled event#

swpr_cleanup runs daily and deletes messages older than the retention period above. It is registered on activation and removed on deactivation.

REST API (/wp-json/swpr/v1)#

MethodRouteAccess
POST/chatPublic, rate limited per IP. Returns a signed session_id to send back with follow-up messages.
POST/chat/clearPublic; needs a session_id signed by this site.
POST/cart/addPublic; accepts simple, purchasable, in-stock products only.
GET/testAdministrators. Reports provider, model and whether a key is set.
GET/POST/settings, /analytics, /chat-history, /models, /categories, /mcp-token, /clear-cache, /test-connectionAdministrators (manage_options).
POST/mcp; GET /mcp/sse; POST /mcp/messageAdministrators, or the MCP token. Only while the MCP server is enabled.

Debug logging#

Set WP_DEBUG and WP_DEBUG_LOG to true in wp-config.php and the plugin writes provider errors to wp-content/debug.log, prefixed with LeetCart AI:. API keys are redacted from logged messages.

Source and translations#

The unminified React source for the widget and admin lives in the plugin’s src folder; run npm install and npm run build to rebuild build/. A translation template is in languages/leetcart-ai-for-woocommerce.pot.

Was this article helpful?