An AI-powered WooCommerce log file analyzer. Integrates with the WordPress 7.0+ AI Client (wp_ai_client_prompt) to help store owners understand and resolve log issues directly from the WooCommerce status logs tab — without needing developer support.
| Dependency | Version |
|---|---|
| PHP | 8.0+ |
| WordPress | 7.0+ |
| WooCommerce | Latest stable |
| Node.js | 18+ |
| Composer | 2.x |
WordPress 7.0 introduces the WordPress AI Client (
wp_ai_client_prompt). The plugin will not initialize without it.
# 1. Clone into your local WordPress install
git clone git@github.com:stuartduff/wc-ai-log-analyzer.git wp-content/plugins/wc-ai-log-analyzer
cd wp-content/plugins/wc-ai-log-analyzer
# 2. Install PHP dependencies
composer install
# 3. Install JS dependencies
npm install
# 4. Compile assets
npm buildActivate the plugin from WP Admin → Plugins, then navigate to WooCommerce → Status → Logs to use it.
For active JS development with hot reloading:
npm startwc-ai-log-analyzer/
├── ai-log-analyzer.php # Plugin entry point — constants, autoloader, bootstrap
├── includes/
│ ├── class-plugin.php # Singleton core — dependency checks, wires all classes
│ ├── class-ai-client.php # Wrapper around wp_ai_client_prompt()
│ ├── class-analysis-engine.php# Orchestrates analysis + injects support URLs
│ ├── class-log-integration.php# WC log UI integration, AJAX handlers, HTML reports
│ └── class-log-parser.php # Log content sanitization and pre-processing
├── admin/
│ ├── class-admin-interface.php# Settings page registration and rendering
│ └── views/ # PHP view templates
├── src/
│ └── analyze/ # React frontend (wp-scripts)
│ ├── index.js # Entry point — mounts the React app
│ ├── index.scss # Styles
│ ├── analysis-results.jsx # Root component
│ ├── components/ # Severity notice, fix steps, support contact
│ └── hooks/ # use-analyze.js — AJAX fetch hook
├── build/ # Compiled JS/CSS (gitignored — run npm build)
└── tests/
├── php/ # PHPUnit test suites
└── js/ # wp-scripts JS test suites
npm build # Production build → build/
npm start # Development build with file watcher
npm lint:js # ESLint — src/
npm lint:css # Stylelint — src/
ynpm test:js # JS unit tests via wp-scriptscomposer lint # PHPCS with WordPress Coding Standards
composer lint:fix # PHPCBF auto-fix
composer test # PHPUnitnpm makepot # Regenerate languages/ai-log-analyzer-for-woocommerce.pot
npm build:zip # Build production zip → dist/ai-log-analyzer-for-woocommerce.zipBoth commands shell out to WP-CLI (wp i18n make-pot), so wp must be on your PATH — on macOS install with brew install wp-cli.
npm build:zip runs bin/build-zip.sh, which:
- Cleans
dist/. - Runs the production webpack build.
- Reinstalls Composer with
--no-dev --optimize-autoloaderfor a slim autoloader. - Stages the plugin into a slug-named folder, excluding everything in
.distignore. - Zips it to
dist/ai-log-analyzer-for-woocommerce.zip(installable via WP Admin → Plugins → Add New → Upload). - Restores Composer dev dependencies.
The plugin uses the WordPress AI Client API introduced in WordPress 7.0. The AI_Client class wraps wp_ai_client_prompt() and supports three model preferences (configurable via plugin settings):
| Setting | Model |
|---|---|
anthropic |
claude-sonnet-4-6 |
google |
gemini-3.1-pro-preview |
openai |
gpt-5.4 |
The AI is always called with a structured JSON output schema (RESPONSE_SCHEMA in AI_Client) and a system instruction that enforces plain-English, non-technical responses aimed at store owners.
The plugin detects which WooCommerce log handler is active and reads log content accordingly:
| Handler | Detection | Read method |
|---|---|---|
| FileV2 | Default (non-numeric, non-.log ID) | FileController::get_file_by_id() |
| Legacy | File ID ends in .log |
Reads from WC_LOG_DIR |
| Database | Numeric file ID | Queries {prefix}_woocommerce_log |
A user can run log analysis if they have manage_woocommerce and prompt_ai capabilities, or if the Allow Shop Managers setting is enabled and they have manage_woocommerce. See Plugin::current_user_can_analyze().
The src/analyze/ app is built with @wordpress/scripts and enqueued only on the WooCommerce status logs tab. It mounts into a <div id="ai-log-analyzer-results"> injected via admin_footer. Communication with the backend uses two AJAX actions:
ai_analyze_log— triggers analysis, returns structured JSONai_download_report— generates and streams a self-contained HTML report
- PHP: WordPress Coding Standards (WPCS 3.x). Run
composer lintbefore committing. - JS/CSS: enforced via
@wordpress/scriptsESLint and Stylelint configs. - Namespace:
AI_Log_Analyzer\(PSR-4, mapped toincludes/). - Option key:
ai_log_analyzer_settings(constantAI_LOG_ANALYZER_OPTION). - Text domain:
ai-log-analyzer.
- Fork the repository and create a feature branch from
main. - Follow the coding standards above — CI will fail on lint errors.
- Add or update tests for any changed behaviour.
- Open a pull request with a clear description of what changed and why.
For bug reports, please include the WordPress version, WooCommerce version, PHP version, and any relevant log output.
GPL-2.0-or-later — see LICENSE.