Blueprint

System Data Flow

Entry Point
Process Node
Data Store
Output
Productionv1.2.0

The CRM-Aware AI Hook

AI / CRM Integration

A server-side WordPress function that hydrates an LLM system prompt with real purchase history and CRM segment data — making every AI-powered support response contextually aware of who the student is and what they've bought.

Logic Breakdown

When a support request is triggered, the hook resolves the current `user_id` and makes two parallel data calls: `wc_get_orders()` retrieves the last three WooCommerce transactions, and WP Fusion's adapter fetches the user's FluentCRM tags in a single round-trip. The combined context is JSON-encoded and injected into the LLM's system prompt, enabling personalised responses without the user having to re-explain their history.

Architecture Decisions

  • 01WordPress hook intercepts an authenticated AJAX or REST request containing a valid `user_id`.
  • 02`wc_get_orders()` retrieves the last 3 orders, mapped to their line items for purchase context.
  • 03WP Fusion adapter fetches CRM tags/segments from FluentCRM in a single synchronous call.
  • 04Context object is JSON-encoded and injected directly into the LLM system prompt payload.

Code Snippet

php
the-crm-aware-ai-hook.php
// PHP / WordPress: Fetching User Context for AI Assistant
function get_student_context_for_ai($user_id) {
    $orders = wc_get_orders(['customer' => $user_id, 'limit' => 3]);
    $tags = wp_fusion()->user->get_tags($user_id); // Sync via WP Fusion

    $context = [
        "purchase_history" => array_map(fn($o) => $o->get_items(), $orders),
        "certifications"   => get_user_meta($user_id, 'completed_courses', true),
        "crm_segment"      => $tags
    ];

    return json_encode($context);
}

Key Dependencies

WooCommerce^8.0.0Order data & customer history
FluentCRM^2.7.0CRM tagging & segmentation
WP Fusion^3.41.0CRM sync adapter
OpenAI PHP Client^1.0.0LLM API integration

Known Limitations

  • Synchronous PHP execution blocks the request thread — consider async via Action Scheduler for high traffic.
  • Sensitive user data is in scope; always validate WP nonce and capability before calling.

Technical Spec

Language
PHP 8.1+
Platform
WordPress 6.x
CRM
FluentCRM + WP Fusion
Commerce
WooCommerce 8.x
LLM
Configurable (GPT-4 / Claude)
Output
JSON context string
Hook
wp_ajax_* / REST endpoint

Tags

PHPWordPressWooCommerceFluentCRMLLM

Live Sandbox

Interactive runtime environment — The CRM-Aware AI Hook v1.2.0

Production
the-crm-aware-ai-hook-sandbox

$ npm run sandbox

> Initialising The CRM-Aware AI Hook v1.2.0

> Status: Production

// Live iframe mounted once sandboxUrl is configured.