'Setup', 'readiness' => 'Readiness checks', 'catalogue' => 'Catalogue audit', 'verification' => 'Purchase verification', 'diagnostics' => 'Diagnostics' ); public function register() { add_action( 'admin_menu', array( $this, 'menu' ) ); add_action( 'admin_post_wacc_action', array( $this, 'handle' ) ); } public function menu() { if ( defined( 'WC_VERSION' ) ) { add_submenu_page( 'woocommerce', 'Agentomise', 'Agentomise', 'manage_woocommerce', self::SLUG, array( $this, 'render' ) ); } else { add_options_page( 'Agentomise', 'Agentomise', 'manage_options', self::SLUG, array( $this, 'render' ) ); } } public static function can_manage() { return current_user_can( 'manage_woocommerce' ) || current_user_can( 'manage_options' ); } public static function url( $tab = 'setup' ) { return admin_url( ( defined( 'WC_VERSION' ) ? 'admin.php' : 'options-general.php' ) . '?page=' . self::SLUG . '&tab=' . ( isset( self::TABS[$tab] ) ? $tab : 'setup' ) ); } /** All mutations are POST-only, capability checked, and nonce protected. */ public function handle() { if ( ! self::can_manage() ) { wp_die( esc_html__( 'You cannot manage agent commerce.', 'agentomise-for-woocommerce' ), '', array( 'response' => 403 ) ); } if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || $_SERVER['REQUEST_METHOD'] !== 'POST' ) { wp_die( 'POST required.', '', array( 'response' => 405 ) ); } check_admin_referer( 'wacc_action' ); $input = wp_unslash( $_POST ); $task = isset( $input['task'] ) && is_string( $input['task'] ) ? sanitize_key( $input['task'] ) : ''; $message = 'Saved.'; $ok = true; switch ( $task ) { case 'registry_export': nocache_headers(); header( 'Content-Disposition: attachment; filename="server.json"' ); wp_send_json( Commerce\Discovery::document(), 200, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ); break; case 'settings': Settings::save( $input ); EventLog::record( 'settings_saved' ); delete_option( Readiness::OPTION ); break; case 'readiness': ( new Readiness() )->run(); $message = 'Readiness checks completed. Review individual results below.'; break; case 'audit': $page = isset( $input['audit_page'] ) && is_scalar( $input['audit_page'] ) ? max( 1, absint( $input['audit_page'] ) ) : 1; wp_safe_redirect( self::audit_url( $page, isset( $input['include_excluded'] ) && $input['include_excluded'] === '1' ) ); exit; case 'verify': $result = Verification::record( $input ); $ok = ! is_wp_error( $result ); $message = $ok ? 'Merchant-reported staging verification recorded.' : $result->get_error_message(); break; case 'clear_verification': delete_option( Verification::OPTION ); EventLog::record( 'verification_cleared' ); break; case 'clear_log': delete_option( EventLog::OPTION ); break; default: wp_die( 'Unknown action.', '', array( 'response' => 400 ) ); } set_transient( 'wacc_notice_' . get_current_user_id(), array( 'message' => $message, 'ok' => $ok ), 60 ); // Return to the section that owns the action; never trust a submitted redirect URL. $tabs = array( 'readiness' => 'readiness', 'verify' => 'verification', 'clear_verification' => 'verification', 'clear_log' => 'diagnostics' ); wp_safe_redirect( self::url( $tabs[$task] ?? 'setup' ) ); exit; } private function form( $task ) { echo '
'; } private function checkbox( $name, $label, $checked = false ) { echo ''; } public function render() { if ( ! self::can_manage() ) { wp_die( 'Access denied.', '', array( 'response' => 403 ) ); } echo 'Open your shop to AI agents. Agentomise
'; echo 'Let external customer agents shop through WooCommerce using its existing shipping, tax and payment plugins. Connect agents to the MCP endpoint for native checkout tools, or use the browser checkout handoff. WooCommerce AI and separate processor keys are not required.
'; $notice = get_transient( 'wacc_notice_' . get_current_user_id() ); if ( is_array( $notice ) ) { echo '' . esc_html( $notice['message'] ) . '
[agent_commerce_shop] to a WordPress page.WooCommerce: ' . esc_html( $deps['woocommerce'] ? $deps['wc_version'] : 'Not active' ) . ' · WooCommerce AI: ' . esc_html( $deps['ai']['active'] ? $deps['ai']['version'] : 'Not detected as active' ) . '
'; echo 'Open shopper page · Agent capabilities · Browser handoff OpenAPI schema
The browser handoff API and the native purchase MCP tools are separate interfaces. Optional WooCommerce AI/UCP integration remains separate and is not required.
'; echo 'Agent MCP endpoint: ' . esc_html( rest_url( Shopping\Api::NS . '/mcp' ) ) . '
The MCP tools use native WooCommerce carts and checkout through the installed gateways. Gateway-specific payment tokens must come from an authorised payment flow; a language model cannot invent them. Gateway JavaScript, bank authentication or redirects can still require customer action. Test each installed extension before offering agent purchases.
'; $settings = Settings::get(); $this->form( 'settings' ); echo 'Switch to Browse only to pause purchases. This does not cancel orders, reverse payments or stop requests already in progress. Existing browser carts remain available through normal WooCommerce checkout.
'; if ( Settings::legacy_handoff_only() ) { echo 'Your previous configuration enabled browser handoffs but not native agent checkout. It now uses Browse only to avoid enabling new purchase permissions automatically. Test your gateway, then select Shopping enabled to restore handoffs and enable MCP purchases.
Shopping enabled requires compatible WooCommerce native checkout, PHP OpenSSL, HTTPS in production and working same-site REST loopbacks. Uses existing payment plugins; no separate Stripe credentials. Gateway authentication may still require customer action. Test your gateway before accepting agent purchases.
Off by default. Up to 50 events are retained for seven days; expired entries are pruned on the next write and hidden on reads. Request bodies, credentials, customer data and payment payloads are never collected. Turning this off deletes the history.
'; submit_button( 'Save controls' ); echo ''; } private function discovery() { echo 'Connection metadata: ' . esc_html( Commerce\Discovery::url() ) . '. Store pages advertise this document through HTML and HTTP alternate links in Browse only or Shopping enabled. A convenience alias at ' . esc_html( home_url( '/mcp-server.json' ) ) . ' works when your server routes that path to WordPress; use the REST URL with plain permalinks.
Modern clients can call server/discover using MCP 2026-07-28 per-request metadata and headers. Existing clients can continue using the 2025-06-18 initialize handshake. The document uses the official registry schema; its URL and alternate links are discovery conventions, not a universally supported automatic connection mechanism.
' . esc_html( Commerce\Discovery::document()['name'] ) . '.mcp-publisher publish. Check the returned listing and republish when your endpoint or version changes.Export does not publish or verify ownership. Registry inclusion helps clients that consult that registry; each agent controls discovery, connection approval and payment authorisation.
'; } private function checks() { echo 'Runs a bounded HTTPS GET to your domain-root discovery document. It does not follow advertised endpoints, modify carts, create orders or charge payments.
'; echo 'Discovery URL: ' . esc_html( Readiness::discovery_url() ) . '
No saved readiness report. Run checks after changing dependencies or settings.
'; return; } echo 'Snapshot: ' . esc_html( wp_date( 'Y-m-d H:i T', $report['time'] ) ) . '. Rerun after configuration changes.
'; echo '| Check | Result | Details |
|---|---|---|
| ' . esc_html( $check['name'] ) . ' | ' . esc_html( strtoupper( $check['status'] ) ) . ' | ' . esc_html( $check['detail'] ) . ' |
PASS confirms only the stated check. REVIEW needs further evidence. FAIL identifies a blocker or active pause. These results never certify a successful purchase.
'; } public static function audit_url( $page, $include_excluded = false ) { return add_query_arg( 'include_excluded', $include_excluded ? '1' : '0', add_query_arg( 'audit_page', $page, self::url( 'catalogue' ) ) ); } private function catalog() { echo 'To exclude a product from agentic shopping, open Products → Edit product → Product data → General, tick Exclude from agentic shopping, and update it. All variations inherit the parent exclusion. Normal WooCommerce shopping is unaffected.
'; echo 'Read-only checks of 20 published parent products per page and up to 100 published variations per variable product. Findings are review suggestions, not automatic edits.
'; // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only catalogue scope and pagination; no settings or product data are changed. $include_excluded = isset( $_GET['include_excluded'] ) && $_GET['include_excluded'] === '1'; echo 'By default, products excluded from agentic shopping and their variations are skipped. Including them here does not enable them for agents.
'; $this->form( 'audit' ); $this->checkbox( 'include_excluded', 'Include excluded products', $include_excluded ); echo ''; submit_button( 'Audit catalogue page', 'secondary' ); echo ''; if ( ! isset( $_GET['audit_page'] ) || ! is_scalar( $_GET['audit_page'] ) ) { return; } $page = min( 1000000, max( 1, absint( wp_unslash( $_GET['audit_page'] ) ) ) ); $result = ( new CatalogAudit() )->run( $page, $include_excluded ); // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( isset( $result['error'] ) ) { echo '' . esc_html( $result['error'] ) . '
'; return; } echo 'Audit scope: ' . ( $include_excluded ? 'All published products, including excluded products.' : 'Published products not excluded from agentic shopping.' ) . '
'; echo '' . esc_html( sprintf( 'Page %d of %d; %d published parent products in this scope. Checked %d products and variations on this page.', $result['page'], $result['pages'], $result['total'], $result['checked'] ) ) . '
'; if ( empty( $result['rows'] ) ) { echo 'No findings on this page. Product suitability and shipping/payment compatibility still need testing.
'; } else { echo '| Product | Findings |
|---|---|
| ' . esc_html( $row['name'] ) . ' (#' . esc_html( $row['id'] ) . ') |
|
This is a merchant-attested checklist. Agentomise checks the selected order’s WooCommerce paid status and payment date; it cannot independently prove agent origin, processor settlement, authorisation or retry correctness.
'; $record = get_option( Verification::OPTION, array() ); if ( ! empty( $record ) ) { echo 'Merchant-reported test: ' . esc_html( $record['service'] ) . '; order #' . esc_html( $record['order_id'] ) . '; ' . esc_html( $record['environment'] ) . '; ' . esc_html( wp_date( 'Y-m-d H:i T', $record['time'] ) ) . '. WooCommerce ' . esc_html( $record['wc_version'] ) . ', WooCommerce AI ' . esc_html( $record['ai_version'] ) . '. Historical evidence only; repeat after upgrades or configuration changes.
Recording is disabled on production. On an isolated staging site, set WP_ENVIRONMENT_TYPE to staging in wp-config.php and use your gateway’s test mode. Environment type alone does not enable payment test mode.
Use an external buying agent supported by your shopping service. Enable the gateway’s test mode yourself. Complete the purchase there, then enter its WooCommerce order ID below. This form sends no payment requests.
'; $this->form( 'verify' ); echo ''; foreach ( Verification::STEPS as $key => $label ) { $this->checkbox( $key, $label ); } submit_button( 'Record merchant-reported test', 'secondary' ); echo ''; } private function events() { echo 'Only Agentomise actions are recorded. This is not a checkout traffic trace. Snapshot reports and verification records stay on this site until replaced or uninstalled; catalogue findings are generated on demand.
'; $events = EventLog::all(); if ( ! $events ) { echo 'No diagnostic events retained.
'; } else { echo '| Time | Event | Counts |
|---|---|---|
| ' . esc_html( wp_date( 'Y-m-d H:i T', $event['time'] ) ) . ' | ' . esc_html( $event['event'] ) . ' | ' . esc_html( wp_json_encode( $event['summary'] ) ) . ' |