Extend WooCommerce AI with a custom module

Register a feature module from a companion plugin using WooCommerce AI’s module registry. This guide covers the ModuleInterface shipped in WooCommerce AI 0.8.0.

Note:

This is a Developer level doc. If you are unfamiliar working with code and resolving potential conflicts, we recommend you work with a Woo Agency Partner for larger projects, or find a WooCommerce developer on Codeable for smaller customizations. We are unable to provide support for customizations under our Support Policy.

Before you start

↑ Back to top

Use a test site with WooCommerce and WooCommerce AI active. You need access to install a companion plugin and review PHP errors. Implement the interface’s static is_available() method and instance init() method.

Register a module

↑ Back to top

Create a companion plugin file with the following example. The module is enabled by default and displays an administrator-only notice so you can verify initialization without changing store data.

<?php
/**
 * Plugin Name: Example WooCommerce AI Module
 *
 * @package Example_Woo_AI_Module
 */

namespace Example_Woo_AI_Module;

add_action(
	'woocommerce_ai_register_modules',
	function ( $registry ) {
		if ( ! interface_exists( 'WooCommerceAI\\Module\\ModuleInterface' ) ) {
			return;
		}

		$module = new class() implements \WooCommerceAI\Module\ModuleInterface {
			/**
			 * Check whether WooCommerce is available.
			 *
			 * @return bool Whether the module can initialize.
			 */
			public static function is_available(): bool {
				return class_exists( 'WooCommerce' );
			}

			/**
			 * Register the example administrator notice.
			 *
			 * @return void
			 */
			public function init(): void {
				add_action(
					'admin_notices',
					function () {
						if ( current_user_can( 'manage_options' ) ) {
							echo '<div class="notice notice-info"><p>' . esc_html__( 'The example WooCommerce AI module is running.', 'example-woo-ai-module' ) . '</p></div>';
						}
					}
				);
			}
		};

		$registry->register(
			'example_module',
			$module,
			array(
				'option'      => 'wcai_example_module_enabled',
				'title'       => 'Example module',
				'description' => 'A test module that displays an admin notice.',
				'default'     => 'yes',
			)
		);
	}
);

Check initialization

↑ Back to top
  1. Activate the companion plugin on your test site.
  2. Open a WordPress admin page as an administrator. Confirm that the example module notice appears.
  3. Deactivate the companion plugin and confirm that the notice disappears.
  4. If the notice is absent, check that WooCommerce AI and WooCommerce are active, the module option is enabled, and PHP did not report an error.

Module configuration

↑ Back to top

register() accepts a unique module ID, a ModuleInterface instance, and a configuration array. The option key names the stored enabled-state option; its default name is wcai_{id}_enabled. title and description describe the module. default is yes or no, with no as the fallback. A duplicate ID is rejected. Registering a module does not automatically add a new merchant control to the current settings screen.

Initialization order

↑ Back to top

The woocommerce_ai_register_modules action runs after built-in registration. On woocommerce_init, WooCommerce AI first calls register_pre_init() for modules implementing PreInitModuleInterface, regardless of enabled state. It then calls init() only for enabled, available modules. Use pre-initialization for prerequisite setup, and keep feature behavior in init().

Abilities are a separate extension point

↑ Back to top

A module is not automatically a chat or MCP tool. Register read abilities with the WordPress Abilities API and supply schemas, permissions, and annotations appropriate to the task. Review the WordPress Abilities API documentation before implementing an ability.

WooCommerce AI’s loader filters apply to abilities loaded through that loader. They do not automatically govern every directly registered third-party ability. WooCommerce AI supports read abilities and writes that use its supported review-and-apply workflow. WordPress.com can apply additional restrictions. Verify discovery and permissions through each intended consumer before using an ability in production.

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.