Commit 46a62cda17f for woocommerce
commit 46a62cda17f13ad1f6c20b102977e7fc885f3b5f
Author: AnnaMag <AnnaMag@users.noreply.github.com>
Date: Wed Nov 18 17:06:53 2026 +0100
Agent readiness: Sales readiness page and AI tools Overview as React views (#70590)
* Agent readiness: rank checks by sales, let the rules file set Required store checks
ProductSales reads each product's and variation's net sales over the
last 90 days from the Analytics lookup tables. The scan adds up the
sales of each check's failing products, or only the failing variations
of a variable product, and stores the share. Shares are left out with
fewer than 20 orders, or while Analytics holds under 90% of the store's
orders.
The rules file's store_checks marks a store check required or off
without a release. The UCP catalog search check asks once more before it
fails, and keeps the status and content type of a failed answer.
* Agent readiness: Sales readiness page and the AI tools Overview
The Agentic commerce settings tab becomes AI tools, with AI shopping and
an Overview. Sales readiness is a React page under WooCommerce, fed by
wc/v3/agent-readiness/view: Fix first, then a card per merchant
question with the setup steps and store checks that answer it, then the
product checks per channel. ReadinessCheckPage builds the view and
ReadinessCopy holds its wording.
* Agent readiness: keep each POST answer per body, not per URL
post_json() cached its answer by URL alone, so a second POST of a different
body to the same URL in one scan got the first body's answer. Both callers
send an empty body today, so no result changes. post_json_again() now
clears only the answer for its own body.
Fixes WOOAIRR-787.
* Agent readiness: keep the connection URL fix on the new setup steps
The permalinks button and the file instruction lived on the old settings page. Sales readiness and the AI shopping checklist now say the same thing, and offer Change permalinks only when permalinks are one of the fixes.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Agent readiness: show the product details card as couldn't check when no product page loads
The review markup check passed without loading a page when ratings are off or no product has reviews, so in coming soon mode the card listed every other check as couldn't check under a No issues badge instead of the single couldn't-check row.
* Agent readiness: always return five setup-step action fields
PHPStan rejected optional indexes 3 and 4 after the connection URL step
started using them. Every check_action() result now includes the link
text and fix line, empty when unused.
* Agent readiness: register Sales readiness only when the feature is on
Without the flag the menu and REST routes are gone, but /sales-readiness
still loaded and the view request failed with a generic error.
* Agent readiness: keep fix links on the Agentic commerce tab
This branch has no AI shopping section yet. Point UCP and policy fixes
at the current tab so they work if this PR merges to trunk before #70590.
* Agent readiness: address CodeRabbit findings on sales shares and settings
Clear sales_share when example membership changes, count Analytics orders
before revenue, exclude WCPay test orders from the import denominator, group
settings by shows_required(), and read nested AggregateOffer policies.
* Agent readiness: match Sales readiness and AI tools styles to the prototype
From the design QA pass, measured on the rendered prototype:
- Card introductions use body-md; channel names use heading-sm, counts
body-lg and "of 15 can be listed" body-sm; no divider under channels.
- The Required badge is no longer bold: semibold applies to the group
label only.
- 24px between cards; 28px from a card heading to its introduction and
32px to a first row on Sales readiness; 24px under the Fix first
introduction and 16px from a group label to its first row.
- AI tools: compact buttons, 18px from the description to Fix first,
16px from the last row to View all checks.
- The Copilot channel is named "Copilot".
* Agent readiness: keep the row padding at the top of an open fold
The first-row rule for a card's opening list also reached the list
inside "Show N more checks", so its first row sat 4px under the line
above it instead of 12px. The README names the channel Copilot.
* Agent readiness: inline one-caller helpers and drop CSS that matched nothing
Inline the one-caller helpers in ReadinessCheckPage, turn fix_link_text()
into an ordered map, and use the injected features controller. Drop the
external-link rule (no such links), the group label's padding and the AI
shopping steps rule, which repeated what already applied.
* Keep guest checkout Optional in agent readiness.
With guest checkout off, UCP still serves the catalog and carts, so it no longer blocks the AI shopping switch. Also turn on a payment method in the ready-store settings tests, since that step is Required.
* Keep AI shopping fix links and an Optional guest checkout after the merge.
The merge from the base took its Agentic commerce fix links over the AI shopping ones. Restore them, and make the settings test and README treat guest checkout as Optional with UCP checkout too.
* Count WCPay test orders apart, so the sales import check works without HPOS.
The posts order store doesn't support meta_query: it ignored the exclusion and raised a doing-it-wrong notice on every scan. Count all orders and the test-mode ones, and subtract.
* Point a shop manager at someone who can set the privacy page, and type the UCP discovery check.
* Keep the detail a UCP check served, and leave child orders and Search-only products in the right readiness counts.
* Show products the scan can't check, and keep unsaved AI shopping fields.
A catalog of only hidden or unsupported products is not an empty store. Flipping AI shopping no longer reloads over a dirty form. A parent with no variation attribute keeps the whole product's sales.
* Open Product visibility on the AI shopping section.
The switch comment was also over the line length CI allows.
diff --git a/plugins/woocommerce/changelog/add-agent-readiness-single-page b/plugins/woocommerce/changelog/add-agent-readiness-single-page
new file mode 100644
index 00000000000..16e79f76d7d
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-agent-readiness-single-page
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Agent readiness: move the Agentic commerce tab to AI tools, with AI shopping, and add the Sales readiness page and the Overview, React views fed by wc/v3/agent-readiness/view.
diff --git a/plugins/woocommerce/client/admin/changelog/fix-sales-readiness-ci b/plugins/woocommerce/client/admin/changelog/fix-sales-readiness-ci
new file mode 100644
index 00000000000..45470ee8350
--- /dev/null
+++ b/plugins/woocommerce/client/admin/changelog/fix-sales-readiness-ci
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Fix Sales readiness Prettier lint and polling unit expectation so CI can pass.
diff --git a/plugins/woocommerce/client/admin/client/layout/controller.js b/plugins/woocommerce/client/admin/client/layout/controller.js
index 1b57d91315f..78d7855e431 100644
--- a/plugins/woocommerce/client/admin/client/layout/controller.js
+++ b/plugins/woocommerce/client/admin/client/layout/controller.js
@@ -78,6 +78,11 @@ const LaunchStore = lazy(
)
);
+const SalesReadiness = lazy(
+ () =>
+ import( /* webpackChunkName: "sales-readiness" */ '../sales-readiness' )
+);
+
const MobileAppLoginPage = lazy(
() =>
import(
@@ -211,6 +216,25 @@ export const getPages = ( reports = [] ) => {
},
} );
+ if ( isFeatureEnabled( 'agent_readiness' ) ) {
+ pages.push( {
+ container: SalesReadiness,
+ layout: {
+ header: false,
+ },
+ path: '/sales-readiness',
+ breadcrumbs: [
+ ...initialBreadcrumbs,
+ __( 'Sales readiness', 'woocommerce' ),
+ ],
+ wpOpenMenu: 'toplevel_page_woocommerce',
+ capability: 'manage_woocommerce',
+ navArgs: {
+ id: 'woocommerce-sales-readiness',
+ },
+ } );
+ }
+
pages.push( {
container: CoreProfiler,
path: '/setup-wizard',
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/ai-shopping-header.scss b/plugins/woocommerce/client/admin/client/sales-readiness/ai-shopping-header.scss
new file mode 100644
index 00000000000..6aeb8ca98d6
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/ai-shopping-header.scss
@@ -0,0 +1,28 @@
+// AI tools > AI shopping: the breadcrumb as the WooCommerce header's title, the description on
+// its own line under it.
+.woocommerce-layout__header:has(.wc-ai-shopping-header__trail) .woocommerce-layout__header-wrapper {
+ flex-wrap: wrap;
+}
+
+// With the tabs hidden, the first card would touch the header.
+body:has(.wc-ai-shopping-header__trail) .wc-agentic-commerce {
+ margin-block-start: var(--wpds-dimension-gap-2xl);
+}
+
+.wc-ai-shopping-header__trail {
+ display: inline-flex;
+ align-items: center;
+ gap: var(--wpds-dimension-gap-sm);
+}
+
+.wc-ai-shopping-header__separator {
+ color: var(--wpds-color-foreground-content-neutral-weak);
+}
+
+.wc-ai-shopping-header__description {
+ flex-basis: 100%;
+ margin: 0;
+ padding-inline: 24px;
+ padding-block-end: var(--wpds-dimension-gap-lg);
+ color: var(--wpds-color-foreground-content-neutral-weak);
+}
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/ai-shopping-header.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/ai-shopping-header.tsx
new file mode 100644
index 00000000000..eaf51baf572
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/ai-shopping-header.tsx
@@ -0,0 +1,57 @@
+/**
+ * External dependencies
+ */
+import { registerPlugin } from '@wordpress/plugins';
+import { WooHeaderItem, WooHeaderPageTitle } from '@woocommerce/admin-layout';
+import { Link } from '@wordpress/ui';
+
+/**
+ * Internal dependencies
+ */
+import './ai-shopping-header.scss';
+
+interface AiShoppingHeaderProps {
+ parentLabel: string;
+ parentUrl: string;
+ title: string;
+ description: string;
+}
+
+/**
+ * WooCommerce > Settings > AI tools > AI shopping: the breadcrumb becomes the WooCommerce page
+ * header's title, with the description under it, as the offline payment methods pages do. The
+ * PHP section hides the settings tabs.
+ */
+export const registerAiShoppingHeader = ( {
+ parentLabel,
+ parentUrl,
+ title,
+ description,
+}: AiShoppingHeaderProps ): void => {
+ registerPlugin( 'wc-ai-shopping-header', {
+ scope: 'woocommerce-admin',
+ render: () => (
+ <>
+ <WooHeaderPageTitle>
+ <span className="wc-ai-shopping-header__trail">
+ <Link tone="neutral" href={ parentUrl }>
+ { parentLabel }
+ </Link>
+ <span
+ aria-hidden="true"
+ className="wc-ai-shopping-header__separator"
+ >
+ /
+ </span>
+ <span aria-current="page">{ title }</span>
+ </span>
+ </WooHeaderPageTitle>
+ <WooHeaderItem>
+ <p className="wc-ai-shopping-header__description">
+ { description }
+ </p>
+ </WooHeaderItem>
+ </>
+ ),
+ } );
+};
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/components/check-row.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/components/check-row.tsx
new file mode 100644
index 00000000000..79411634a6b
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/components/check-row.tsx
@@ -0,0 +1,186 @@
+/**
+ * External dependencies
+ */
+import { Badge, Icon, Link, Stack, Text, VisuallyHidden } from '@wordpress/ui';
+import { Button } from '@wordpress/components';
+import { Path, SVG } from '@wordpress/primitives';
+import { createInterpolateElement } from '@wordpress/element';
+import { __, sprintf } from '@wordpress/i18n';
+import type { ReactNode } from 'react';
+
+/**
+ * Internal dependencies
+ */
+import type { CheckRow as CheckRowData, ViewBadge, ViewLink } from '../types';
+
+/**
+ * Where to fix it: an outline button when it has a URL, plain text otherwise.
+ */
+export const RowLink = ( {
+ link,
+ onClick,
+}: {
+ link: ViewLink;
+ onClick?: () => void;
+} ) =>
+ link.href ? (
+ <Button
+ variant="secondary"
+ size="compact"
+ href={ link.href }
+ onClick={ onClick }
+ >
+ { link.text }
+ </Button>
+ ) : (
+ <Text variant="body-sm" className="wc-sales-readiness__muted">
+ { link.text }
+ </Text>
+ );
+
+// The swatch icon, a dashed circle, from the WordPress icons package from version 18 on.
+// This package pins an older version that doesn't have it.
+const dashedCircle = (
+ <SVG
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="1.5"
+ >
+ <Path d="M11.0537 4.81202C11.6819 4.72933 12.3181 4.72933 12.9463 4.81202M14.7744 5.30187C15.3598 5.54434 15.9109 5.86249 16.4135 6.24819M17.7518 7.58648C18.1375 8.08914 18.4557 8.64019 18.6981 9.22555M19.188 11.0537C19.2707 11.6819 19.2707 12.3181 19.188 12.9463M18.6981 14.7744C18.4557 15.3598 18.1375 15.9109 17.7518 16.4135M16.4135 17.7518C15.9109 18.1375 15.3598 18.4557 14.7744 18.6981M12.9463 19.188C12.3181 19.2707 11.6819 19.2707 11.0537 19.188M9.22555 18.6981C8.64019 18.4557 8.08914 18.1375 7.58648 17.7518M6.24819 16.4135C5.86249 15.9109 5.54434 15.3598 5.30187 14.7744M4.81202 12.9463C4.72933 12.3181 4.72933 11.6819 4.81202 11.0537M5.30187 9.22555C5.54434 8.64019 5.86249 8.08914 6.24819 7.58648M7.58648 6.24819C8.08914 5.86249 8.64019 5.54434 9.22555 5.30187" />
+ </SVG>
+);
+
+// The circled check, as in the design: a passed check or a found item.
+const circledCheck = (
+ <SVG
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="1.5"
+ >
+ <Path
+ d="M12 19.25C16.0041 19.25 19.25 16.0041 19.25 12C19.25 7.99594 16.0041 4.75 12 4.75C7.99594 4.75 4.75 7.99594 4.75 12C4.75 16.0041 7.99594 19.25 12 19.25Z"
+ strokeLinejoin="round"
+ />
+ <Path d="M9 12L11 14L15 10" />
+ </SVG>
+);
+
+/**
+ * The marker before a row: a dashed circle for something to do, a circled check for something passed.
+ */
+export const RowMarker = ( {
+ done,
+ muted = false,
+}: {
+ done: boolean;
+ muted?: boolean;
+} ) => (
+ <Icon
+ icon={ done ? circledCheck : dashedCircle }
+ size={ 24 }
+ className={
+ 'wc-sales-readiness-row__marker' +
+ ( muted ? ' wc-sales-readiness-row__marker--muted' : '' )
+ }
+ />
+);
+
+interface RowProps {
+ done?: boolean;
+ /** A grey marker, for a check that couldn't run. */
+ muted?: boolean;
+ title: string;
+ badge?: ViewBadge | null;
+ /** Where to fix it, at the end of the row. */
+ action?: ReactNode;
+ children?: ReactNode;
+ srState?: string;
+}
+
+/**
+ * A row's frame: marker, title with its badge, whatever goes under the title, then the action.
+ */
+export const Row = ( {
+ done = false,
+ muted = false,
+ title,
+ badge,
+ action,
+ children,
+ srState,
+}: RowProps ) => (
+ <Stack
+ direction="row"
+ gap="lg"
+ align="center"
+ render={ <li /> }
+ className="wc-sales-readiness-row"
+ >
+ <RowMarker done={ done } muted={ muted } />
+ <Stack direction="column" className="wc-sales-readiness-row__body">
+ <Text variant="body-md" className="wc-sales-readiness-row__title">
+ { srState && <VisuallyHidden>{ srState } </VisuallyHidden> }
+ { title }
+ { badge && (
+ <Badge intent={ badge.intent }>{ badge.text }</Badge>
+ ) }
+ </Text>
+ { children }
+ </Stack>
+ { action && (
+ <div className="wc-sales-readiness-row__action">{ action }</div>
+ ) }
+ </Stack>
+);
+
+/**
+ * One check. Failing: what to do, why it matters and what was found, the fix line when there is
+ * one, and where to fix it. Passed: its title and why it matters.
+ */
+export const CheckRow = ( { row }: { row: CheckRowData } ) => {
+ const states: Record< CheckRowData[ 'state' ], string > = {
+ open: __( 'Issue:', 'woocommerce' ),
+ required: __( 'Issue:', 'woocommerce' ),
+ unknown: __( "Couldn't check:", 'woocommerce' ),
+ pass: __( 'Passed:', 'woocommerce' ),
+ };
+ return (
+ <Row
+ done={ row.state === 'pass' }
+ muted={ row.state === 'unknown' }
+ title={ row.title }
+ srState={ states[ row.state ] }
+ badge={ row.badge }
+ action={ row.link && <RowLink link={ row.link } /> }
+ >
+ { row.text && (
+ <Text variant="body-sm" className="wc-sales-readiness__muted">
+ { row.text }
+ </Text>
+ ) }
+ { row.fix && (
+ <Text variant="body-sm" className="wc-sales-readiness-row__fix">
+ { row.fix }
+ </Text>
+ ) }
+ { row.seen_at && (
+ <Text variant="body-sm" className="wc-sales-readiness__muted">
+ { createInterpolateElement(
+ sprintf(
+ /* translators: %s: page title where the issue was found. */
+ __( 'Found on <link>%s</link>', 'woocommerce' ),
+ row.seen_at.text
+ ),
+ {
+ link: <Link href={ row.seen_at.href } />,
+ }
+ ) }
+ </Text>
+ ) }
+ </Row>
+ );
+};
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/components/checked-card.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/components/checked-card.tsx
new file mode 100644
index 00000000000..2145d19b3d9
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/components/checked-card.tsx
@@ -0,0 +1,59 @@
+/**
+ * External dependencies
+ */
+import { Card, Text } from '@wordpress/ui';
+import { Button } from '@wordpress/components';
+
+/**
+ * Internal dependencies
+ */
+import type { ReadinessView } from '../types';
+import { RunStatus } from './run-status';
+
+interface CheckedCardProps {
+ view: ReadinessView;
+ running: boolean;
+ onRun: () => void;
+}
+
+/**
+ * When the store was last checked, with Check again. Before the first check it says what a
+ * check shows and offers Run check.
+ */
+export const CheckedCard = ( { view, running, onRun }: CheckedCardProps ) => (
+ <Card.Root className="wc-sales-readiness-card">
+ <Card.Content>
+ { view.intro && (
+ <Text
+ variant="body-md"
+ className="wc-sales-readiness-checked__intro"
+ >
+ { view.intro }
+ </Text>
+ ) }
+ <div className="wc-sales-readiness-checked">
+ <div>
+ <Text variant="body-md">{ view.last_checked }</Text>
+ { view.checked_note && (
+ <Text
+ variant="body-sm"
+ className="wc-sales-readiness__muted"
+ >
+ { view.checked_note }
+ </Text>
+ ) }
+ </div>
+ <Button
+ variant="secondary"
+ size="compact"
+ disabled={ view.run.pending || running }
+ isBusy={ running }
+ onClick={ onRun }
+ >
+ { view.run.label }
+ </Button>
+ </div>
+ <RunStatus run={ view.run } />
+ </Card.Content>
+ </Card.Root>
+);
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/components/fix-first.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/components/fix-first.tsx
new file mode 100644
index 00000000000..844d9d5b05e
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/components/fix-first.tsx
@@ -0,0 +1,105 @@
+/**
+ * External dependencies
+ */
+import { Badge, Card, Text } from '@wordpress/ui';
+
+/**
+ * Internal dependencies
+ */
+import type { FixFirst as FixFirstData } from '../types';
+import { Row, RowLink } from './check-row';
+
+type FixFirstItem = FixFirstData[ 'items' ][ number ];
+
+type TierGroup = {
+ tier: string;
+ badge: FixFirstItem[ 'badge' ];
+ items: FixFirstItem[];
+};
+
+function groupByTier( items: FixFirstData[ 'items' ] ): TierGroup[] {
+ const groups: TierGroup[] = [];
+ for ( const item of items ) {
+ const last = groups[ groups.length - 1 ];
+ if ( ! last || last.tier !== item.tier ) {
+ groups.push( {
+ tier: item.tier,
+ badge: item.badge,
+ items: [ item ],
+ } );
+ } else {
+ last.items.push( item );
+ }
+ }
+ return groups;
+}
+
+/**
+ * The Fix first items under a heading per tier: what each group of issues stops. A product item's
+ * line starts with its share of sales.
+ */
+export const FixFirstList = ( {
+ items,
+}: {
+ items: FixFirstData[ 'items' ];
+} ) => (
+ <div className="wc-sales-readiness-fix-first-groups">
+ { groupByTier( items ).map( ( group ) => (
+ <div key={ group.tier } className="wc-sales-readiness-tier-group">
+ <div className="wc-sales-readiness-tier">
+ <Text
+ variant="heading-sm"
+ className="wc-sales-readiness-card__label"
+ >
+ { group.tier }
+ </Text>
+ { group.badge && (
+ <Badge intent={ group.badge.intent }>
+ { group.badge.text }
+ </Badge>
+ ) }
+ </div>
+ <ol className="wc-sales-readiness-list">
+ { group.items.map( ( item ) => (
+ <Row
+ key={ item.id }
+ title={ item.title }
+ action={
+ item.link && <RowLink link={ item.link } />
+ }
+ srState={ item.tier + ':' }
+ >
+ { item.why && (
+ <Text
+ variant="body-sm"
+ className="wc-sales-readiness__muted"
+ >
+ { item.why }
+ </Text>
+ ) }
+ </Row>
+ ) ) }
+ </ol>
+ </div>
+ ) ) }
+ </div>
+);
+
+/**
+ * The Fix first card on the Sales readiness page.
+ */
+export const FixFirstCard = ( { fixFirst }: { fixFirst: FixFirstData } ) => (
+ <Card.Root className="wc-sales-readiness-card">
+ <Card.Header>
+ <Card.Title className="wc-sales-readiness-card__title">
+ { fixFirst.title }
+ </Card.Title>
+ </Card.Header>
+ <Card.Content>
+ <Text variant="body-md" className="wc-sales-readiness__muted">
+ { fixFirst.ranking }
+ </Text>
+ <FixFirstList items={ fixFirst.items } />
+ </Card.Content>
+ </Card.Root>
+);
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/components/run-status.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/components/run-status.tsx
new file mode 100644
index 00000000000..993a8f377f1
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/components/run-status.tsx
@@ -0,0 +1,40 @@
+/**
+ * External dependencies
+ */
+import { Text, VisuallyHidden } from '@wordpress/ui';
+
+/**
+ * Internal dependencies
+ */
+import type { ReadinessView } from '../types';
+import { RowLink } from './check-row';
+
+/**
+ * The check's status under Run check: while it runs, a message for screen readers only (the
+ * disabled button shows it's running), and the message itself when the check is stuck, with a
+ * button to Scheduled Actions.
+ */
+export const RunStatus = ( { run }: { run: ReadinessView[ 'run' ] } ) => {
+ if ( run.pending && ! run.stalled ) {
+ return (
+ <div role="status">
+ <VisuallyHidden>{ run.message }</VisuallyHidden>
+ </div>
+ );
+ }
+ if ( ! run.message ) {
+ return null;
+ }
+ return (
+ <div className="wc-sales-readiness-run-status" role="status">
+ <Text variant="body-sm" className="wc-sales-readiness__muted">
+ { run.message }
+ </Text>
+ { run.link && (
+ <div className="wc-sales-readiness-row__action">
+ <RowLink link={ run.link } />
+ </div>
+ ) }
+ </div>
+ );
+};
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/components/section-card.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/components/section-card.tsx
new file mode 100644
index 00000000000..4c806c61f0b
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/components/section-card.tsx
@@ -0,0 +1,220 @@
+/**
+ * External dependencies
+ */
+import { useState } from '@wordpress/element';
+import type { ReactNode } from 'react';
+import { Badge, Card, Collapsible, CollapsibleCard, Text } from '@wordpress/ui';
+import { Button } from '@wordpress/components';
+import { __, _n, sprintf } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import type { Declared, Section } from '../types';
+import { CheckRow, Row, RowLink } from './check-row';
+
+/**
+ * "Show N more checks" under what it folds, and what to say once open.
+ */
+export const Fold = ( {
+ label,
+ hideLabel,
+ children,
+}: {
+ label: string;
+ hideLabel: string;
+ children: ReactNode;
+} ) => {
+ const [ open, setOpen ] = useState( false );
+ return (
+ <Collapsible.Root
+ open={ open }
+ onOpenChange={ setOpen }
+ className="wc-sales-readiness-fold"
+ >
+ <Collapsible.Panel>{ children }</Collapsible.Panel>
+ <Collapsible.Trigger
+ render={ <Button variant="tertiary" size="compact" /> }
+ >
+ { open ? hideLabel : label }
+ </Collapsible.Trigger>
+ </Collapsible.Root>
+ );
+};
+
+/**
+ * A question card: its badge, a note, how many products each channel can list, every check
+ * that didn't pass, then the passed ones behind a fold. A card where every check passed
+ * starts closed, and opens on its header to list them.
+ */
+export const SectionCard = ( { section }: { section: Section } ) => {
+ const checks = [ ...section.rows, ...section.folded ];
+ const passed =
+ checks.length > 0 && checks.every( ( row ) => row.state === 'pass' );
+ const head = (
+ <div className="wc-sales-readiness-card__head">
+ <Card.Title className="wc-sales-readiness-card__title">
+ { section.title }
+ </Card.Title>
+ <Badge intent={ section.badge.intent }>
+ { section.badge.text }
+ </Badge>
+ </div>
+ );
+ const note = section.note && (
+ <Text
+ variant="body-md"
+ className="wc-sales-readiness__muted wc-sales-readiness-card__description"
+ >
+ { section.note }
+ </Text>
+ );
+ const list = ( rows: Section[ 'rows' ] ) => (
+ <ul className="wc-sales-readiness-list">
+ { rows.map( ( row ) => (
+ <CheckRow key={ row.id } row={ row } />
+ ) ) }
+ </ul>
+ );
+
+ if ( passed ) {
+ return (
+ <CollapsibleCard.Root
+ className="wc-sales-readiness-card"
+ id={ 'wc-sales-readiness-' + section.id }
+ >
+ <CollapsibleCard.Header>{ head }</CollapsibleCard.Header>
+ <CollapsibleCard.Content>
+ { note }
+ { list( checks ) }
+ </CollapsibleCard.Content>
+ </CollapsibleCard.Root>
+ );
+ }
+
+ return (
+ <Card.Root
+ className="wc-sales-readiness-card"
+ id={ 'wc-sales-readiness-' + section.id }
+ >
+ <Card.Header>{ head }</Card.Header>
+ <Card.Content>
+ { note }
+ { section.channels.length > 0 && (
+ <ul className="wc-sales-readiness-channels">
+ { section.channels.map( ( channel ) => (
+ <li key={ channel.name }>
+ <Text
+ variant="heading-sm"
+ className="wc-sales-readiness-card__label"
+ >
+ { channel.name }
+ </Text>
+ <div>
+ <Text variant="body-lg">
+ { channel.listable }
+ </Text>{ ' ' }
+ <Text
+ variant="body-sm"
+ className="wc-sales-readiness__muted"
+ >
+ { channel.of }
+ </Text>
+ </div>
+ </li>
+ ) ) }
+ </ul>
+ ) }
+ { section.empty && (
+ <div className="wc-sales-readiness-empty">
+ <Text
+ variant="body-md"
+ className={
+ section.empty.text
+ ? 'wc-sales-readiness-empty__title'
+ : undefined
+ }
+ >
+ { section.empty.title }
+ </Text>
+ { section.empty.text && (
+ <Text
+ variant="body-sm"
+ className="wc-sales-readiness__muted"
+ >
+ { section.empty.text }
+ </Text>
+ ) }
+ { section.empty.link && (
+ <div className="wc-sales-readiness-row__action">
+ <RowLink link={ section.empty.link } />
+ </div>
+ ) }
+ </div>
+ ) }
+ { section.rows.length > 0 && list( section.rows ) }
+ { section.folded.length > 0 && (
+ <Fold
+ hideLabel={ __( 'Hide', 'woocommerce' ) }
+ label={ sprintf(
+ /* translators: %d: number of checks. */
+ _n(
+ 'Show %d more check',
+ 'Show %d more checks',
+ section.folded.length,
+ 'woocommerce'
+ ),
+ section.folded.length
+ ) }
+ >
+ { list( section.folded ) }
+ </Fold>
+ ) }
+ </Card.Content>
+ </Card.Root>
+ );
+};
+
+/**
+ * Protocols and files the store serves to agents: information, never pass or fail, so the card
+ * starts closed and opens on its header to list them.
+ */
+export const DeclaredCard = ( { declared }: { declared: Declared } ) => (
+ <CollapsibleCard.Root
+ className="wc-sales-readiness-card"
+ id="wc-sales-readiness-declared"
+ >
+ <CollapsibleCard.Header>
+ <div className="wc-sales-readiness-card__head">
+ <Card.Title className="wc-sales-readiness-card__title">
+ { declared.title }
+ </Card.Title>
+ <Badge intent={ declared.badge.intent }>
+ { declared.badge.text }
+ </Badge>
+ </div>
+ </CollapsibleCard.Header>
+ <CollapsibleCard.Content>
+ <Text
+ variant="body-md"
+ className="wc-sales-readiness__muted wc-sales-readiness-card__description"
+ >
+ { declared.text }
+ </Text>
+ <ul className="wc-sales-readiness-list">
+ { declared.items.map( ( item ) => (
+ <Row
+ key={ item.name }
+ done={ item.found }
+ title={ item.name }
+ srState={
+ item.found
+ ? __( 'Found:', 'woocommerce' )
+ : __( 'Not found:', 'woocommerce' )
+ }
+ />
+ ) ) }
+ </ul>
+ </CollapsibleCard.Content>
+ </CollapsibleCard.Root>
+);
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/index.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/index.tsx
new file mode 100644
index 00000000000..eb22b145e38
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/index.tsx
@@ -0,0 +1,61 @@
+/**
+ * External dependencies
+ */
+import { Page } from '@wordpress/admin-ui';
+import { Notice, Spinner } from '@wordpress/components';
+
+/**
+ * Internal dependencies
+ */
+import './sales-readiness.scss';
+import { useReadinessView } from './use-readiness-view';
+import { CheckedCard } from './components/checked-card';
+import { FixFirstCard } from './components/fix-first';
+import { DeclaredCard, SectionCard } from './components/section-card';
+
+/**
+ * WooCommerce > Sales readiness: when the store was last checked, Fix first, then a card per
+ * merchant question with the checks from the last scan, and what the store shares with agents.
+ */
+export default function SalesReadiness() {
+ const { view, error, running, runCheck } = useReadinessView();
+
+ return (
+ <Page
+ className="wc-sales-readiness"
+ title={ view?.title ?? '' }
+ subTitle={ view?.description }
+ showSidebarToggle={ false }
+ >
+ <div className="wc-sales-readiness__content">
+ { error && (
+ <Notice status="error" isDismissible={ false }>
+ { error }
+ </Notice>
+ ) }
+ { ! view && ! error && <Spinner /> }
+ { view && (
+ <>
+ <CheckedCard
+ view={ view }
+ running={ running }
+ onRun={ runCheck }
+ />
+ { view.fix_first && (
+ <FixFirstCard fixFirst={ view.fix_first } />
+ ) }
+ { view.sections.map( ( section ) => (
+ <SectionCard
+ key={ section.id }
+ section={ section }
+ />
+ ) ) }
+ { view.declared && (
+ <DeclaredCard declared={ view.declared } />
+ ) }
+ </>
+ ) }
+ </div>
+ </Page>
+ );
+}
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/overview.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/overview.tsx
new file mode 100644
index 00000000000..db064fe1fff
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/overview.tsx
@@ -0,0 +1,140 @@
+/**
+ * External dependencies
+ */
+import { Badge, Card, Text } from '@wordpress/ui';
+import { Button, Notice, Spinner } from '@wordpress/components';
+import { __ } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import './sales-readiness.scss';
+import type { ReadinessView } from './types';
+import { useReadinessView } from './use-readiness-view';
+import { FixFirstList } from './components/fix-first';
+import { RunStatus } from './components/run-status';
+
+/**
+ * WooCommerce > Settings > AI tools, the Overview: the AI shopping card, then the Sales readiness
+ * card with Fix first and a link to every check.
+ */
+export default function SalesReadinessOverview( {
+ initialView = null,
+}: {
+ initialView?: ReadinessView | null;
+} ) {
+ const { view, error, running, runCheck } = useReadinessView( initialView );
+
+ if ( ! view ) {
+ return error ? (
+ <Notice status="error" isDismissible={ false }>
+ { error }
+ </Notice>
+ ) : (
+ <Spinner />
+ );
+ }
+ const { shopping, view_all: viewAll } = view.overview;
+
+ return (
+ <div className="wc-sales-readiness wc-sales-readiness--overview">
+ { error && (
+ <Notice status="error" isDismissible={ false }>
+ { error }
+ </Notice>
+ ) }
+ <Card.Root className="wc-sales-readiness-card">
+ <Card.Header>
+ <div className="wc-sales-readiness-card__head">
+ <Card.Title className="wc-sales-readiness-card__title">
+ { shopping.title }
+ </Card.Title>
+ { shopping.badge && (
+ <Badge intent={ shopping.badge.intent }>
+ { shopping.badge.text }
+ </Badge>
+ ) }
+ </div>
+ </Card.Header>
+ <Card.Content>
+ <Text
+ variant="body-md"
+ className="wc-sales-readiness__muted"
+ >
+ { shopping.text }
+ </Text>
+ <div className="wc-sales-readiness-card__actions">
+ <Button
+ variant="secondary"
+ size="compact"
+ href={ shopping.button.href }
+ >
+ { shopping.button.text }
+ </Button>
+ </div>
+ </Card.Content>
+ </Card.Root>
+ <Card.Root className="wc-sales-readiness-card">
+ <Card.Header>
+ <Card.Title className="wc-sales-readiness-card__title">
+ { view.title }
+ </Card.Title>
+ </Card.Header>
+ <Card.Content>
+ <Text
+ variant="body-md"
+ className="wc-sales-readiness__muted"
+ >
+ { view.description }
+ { view.overview.based_on &&
+ ' ' + view.overview.based_on }
+ </Text>
+ { view.intro ? (
+ <>
+ <Text
+ variant="body-sm"
+ className="wc-sales-readiness__muted"
+ >
+ { view.last_checked }
+ </Text>
+ <RunStatus run={ view.run } />
+ <div className="wc-sales-readiness-card__actions">
+ <Button
+ variant="secondary"
+ size="compact"
+ disabled={ view.run.pending || running }
+ isBusy={ running }
+ onClick={ runCheck }
+ >
+ { view.run.label }
+ </Button>
+ </div>
+ </>
+ ) : (
+ <>
+ { view.fix_first ? (
+ <FixFirstList items={ view.fix_first.items } />
+ ) : (
+ <Text variant="body-md">
+ { __(
+ 'Nothing to fix first.',
+ 'woocommerce'
+ ) }
+ </Text>
+ ) }
+ <div className="wc-sales-readiness-card__actions wc-sales-readiness-card__actions--link">
+ <Button
+ variant="tertiary"
+ size="compact"
+ href={ viewAll.href }
+ >
+ { viewAll.text }
+ </Button>
+ </div>
+ </>
+ ) }
+ </Card.Content>
+ </Card.Root>
+ </div>
+ );
+}
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/sales-readiness.scss b/plugins/woocommerce/client/admin/client/sales-readiness/sales-readiness.scss
new file mode 100644
index 00000000000..d16fde5015e
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/sales-readiness.scss
@@ -0,0 +1,373 @@
+// Sales readiness page and the AI tools Overview. Tokens from the design system; the build injects their fallbacks.
+
+// The prototype's buttons (WordPress UI minimal and outline): semibold, and a light background
+// on hover and focus that stays after a click until focus moves; the focus ring only for keyboard focus.
+@mixin sales-readiness-button($padding: var(--wpds-dimension-padding-md)) {
+ &.components-button {
+ padding-inline: $padding;
+ background: var(--wpds-color-background-interactive-brand-weak);
+ box-shadow: none;
+ color: var(--wpds-color-foreground-interactive-brand);
+ font-size: var(--wpds-typography-font-size-md);
+ font-weight: 600;
+
+ &:not(:disabled):is(:hover, :active, :focus, [aria-expanded="true"]) {
+ background: var(--wpds-color-background-interactive-brand-weak-active);
+ box-shadow: none;
+ color: var(--wpds-color-foreground-interactive-brand-active);
+ }
+
+ &:disabled {
+ color: var(--wpds-color-foreground-interactive-brand-disabled);
+ }
+
+ &:focus:not(:focus-visible) {
+ outline: none;
+ }
+
+ &:focus-visible {
+ outline: var(--wpds-border-width-focus) solid var(--wpds-color-stroke-focus);
+ outline-offset: 1px;
+ }
+ }
+}
+
+// The page header (admin-ui Page) runs edge to edge: drop wc-admin's margin and gutter around the page.
+.woocommerce-admin-page__sales-readiness {
+ .woocommerce-layout__primary {
+ margin: 0;
+ }
+
+ .woocommerce-layout__main {
+ padding: 0;
+ }
+
+ // The page title is semibold in the design; the admin-ui Page header sets medium.
+ .wc-sales-readiness h1 {
+ font-weight: 600;
+ }
+}
+
+.wc-sales-readiness {
+ --wc-sr-muted: var(--wpds-color-foreground-content-neutral-weak);
+ --wc-sr-stroke: var(--wpds-color-stroke-surface-neutral-weak);
+ --wc-sr-link: var(--wpds-color-foreground-interactive-brand);
+
+ color: var(--wpds-color-foreground-content-neutral);
+
+ &__content {
+ box-sizing: border-box;
+ width: 100%;
+ // Cards are 632px wide, as in the design.
+ max-width: calc(632px + 2 * var(--wpds-dimension-padding-lg));
+ margin: 0 auto;
+ display: flex;
+ flex-direction: column;
+ gap: var(--wpds-dimension-gap-xl);
+ padding: var(--wpds-dimension-padding-2xl) var(--wpds-dimension-padding-lg);
+ }
+
+ &__muted {
+ color: var(--wc-sr-muted);
+ }
+
+ // No orphans: balance the last line of text.
+ :is(p, .components-text, [class*="__body-"]) {
+ text-wrap: pretty;
+ }
+
+ // AI tools Overview: centered in the settings panel, like the Sales readiness content.
+ &--overview {
+ box-sizing: border-box;
+ display: flex;
+ flex-direction: column;
+ gap: var(--wpds-dimension-gap-lg);
+ max-width: 632px;
+ margin: 0 auto;
+ // The settings form already leaves a gap under the tabs.
+ padding-block: 0 var(--wpds-dimension-padding-3xl);
+ }
+}
+
+.wc-sales-readiness-card {
+ border-color: var(--wpds-color-stroke-surface-neutral);
+
+ &__title {
+ font-weight: 600;
+ }
+
+ &__head {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: var(--wpds-dimension-gap-md);
+ width: 100%;
+ }
+
+ // Fix first group labels and channel names: heading-sm, semibold as in the design.
+ &__label {
+ font-weight: 600;
+ }
+
+ &__actions {
+ margin-block-start: var(--wpds-dimension-gap-md);
+ }
+
+ // 16px from the last row's divider to "View all checks" on the Overview.
+ .wc-sales-readiness-list + &__actions {
+ margin-block-start: var(--wpds-dimension-gap-lg);
+ }
+
+ // "View all checks": a minimal button, like Show more, its text in line with the card text.
+ &__actions--link > .components-button {
+ @include sales-readiness-button(var(--wpds-dimension-padding-sm));
+ margin-inline-start: calc(-1 * var(--wpds-dimension-padding-sm));
+ }
+
+ // 24px from a question card's description to its first row.
+ &__description {
+ display: block;
+ margin-block-end: var(--wpds-dimension-gap-xl);
+ }
+
+ // A list that opens the card starts 4px under the content's edge (32px under the title), not a
+ // row's padding below it. After a description or the channels, it starts at their margin.
+ .wc-sales-readiness-list:first-child > .wc-sales-readiness-row:first-child {
+ padding-block-start: var(--wpds-dimension-padding-xs);
+ }
+
+ :is(&__description, .wc-sales-readiness-channels) + .wc-sales-readiness-list > .wc-sales-readiness-row:first-child {
+ padding-block-start: 0;
+ }
+
+ // An open fold continues the list above it, under that list's last line.
+ .wc-sales-readiness-fold .wc-sales-readiness-list > .wc-sales-readiness-row:first-child {
+ padding-block-start: var(--wpds-dimension-padding-md);
+ }
+}
+
+// Sales readiness page: the card header is 24px tall with the title at its top, so the content
+// starts 28px under the title, and a badge centers on the title. The Overview keeps the card's 24px.
+.wc-sales-readiness:not(.wc-sales-readiness--overview) .wc-sales-readiness-card {
+ .wc-sales-readiness-card__title {
+ min-height: 24px;
+ }
+
+ .wc-sales-readiness-card__head {
+ align-items: flex-start;
+
+ > :not(.wc-sales-readiness-card__title) {
+ margin-block-start: -2px;
+ }
+ }
+}
+
+.wc-sales-readiness-list {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+
+ // A line between rows: none under the last row of a closed list.
+ > .wc-sales-readiness-row {
+ border-block-end: 1px solid var(--wc-sr-stroke);
+ }
+}
+
+// A list that ends the card (Fix first, an open fold, a passed card) has no line under its last row.
+.wc-sales-readiness-card .wc-sales-readiness-list:last-child > .wc-sales-readiness-row:last-child {
+ border-block-end: 0;
+}
+
+// Each Fix first tier has its own list, so drop the line under that group's last row.
+.wc-sales-readiness-tier-group .wc-sales-readiness-list > .wc-sales-readiness-row:last-child {
+ border-block-end: 0;
+}
+
+// When some rows have a button, the buttons share a column, so every row's text stops at the same place.
+@media (min-width: 601px) {
+ .wc-sales-readiness-list:has(.wc-sales-readiness-row__action) {
+ display: grid;
+ grid-template-columns: 24px minmax(0, 1fr) auto;
+ column-gap: var(--wpds-dimension-gap-lg);
+
+ > * {
+ grid-column: 1 / -1;
+ }
+
+ > .wc-sales-readiness-row {
+ display: grid;
+ grid-template-columns: subgrid;
+ align-items: center;
+ }
+
+ .wc-sales-readiness-row__action {
+ grid-column: 3;
+ justify-self: end;
+ }
+ }
+}
+
+// 24px from the card description to Fix first's first heading. Padding, so the margins don't collapse.
+.wc-sales-readiness-fix-first-groups {
+ padding-block-start: var(--wpds-dimension-gap-xl);
+}
+
+// On the Overview the design has 18px there: a 12px gap plus a 10px margin, measured to the heading text, which sits 4px into its 24px line.
+.wc-sales-readiness--overview .wc-sales-readiness-fix-first-groups {
+ padding-block-start: 18px;
+}
+
+// A tier heading on a 24px line (its badge's height), 12px under the group above, then the first
+// row's own padding: 16px from the heading to the row's title.
+.wc-sales-readiness-tier {
+ display: flex;
+ align-items: center;
+ gap: var(--wpds-dimension-gap-sm);
+ min-height: 24px;
+ margin: 0;
+}
+
+.wc-sales-readiness-tier-group + .wc-sales-readiness-tier-group {
+ margin-block-start: var(--wpds-dimension-gap-md);
+}
+
+.wc-sales-readiness-row {
+ padding: var(--wpds-dimension-padding-md) 0;
+ margin: 0;
+
+ // Dark line icons; grey only for a check that couldn't run.
+ &__marker {
+ flex: 0 0 auto;
+ color: var(--wpds-color-foreground-content-neutral);
+ fill: none;
+
+ &--muted {
+ color: var(--wc-sr-muted);
+ }
+ }
+
+ // 2px from the title to the why line, 4px between the lines under it, as in the design.
+ &__body {
+ flex: 1;
+ min-width: 0;
+ gap: var(--wpds-dimension-gap-xs);
+ }
+
+ &__title {
+ display: inline-flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: var(--wpds-dimension-gap-sm);
+ margin-block-end: -2px;
+ font-weight: 600;
+ }
+
+ // The fix line reads as an instruction, so it keeps the text color.
+ &__fix {
+ color: var(--wpds-color-foreground-content-neutral);
+ }
+
+ // Where to fix it: an outline button, or plain text when there is no link.
+ &__action {
+ flex: none;
+
+ > .components-button {
+ @include sales-readiness-button(var(--wpds-dimension-padding-sm));
+ border: 1px solid var(--wpds-color-stroke-interactive-brand);
+
+ &:is(:hover, :active, :focus) {
+ border-color: var(--wpds-color-stroke-interactive-brand-active);
+ }
+ }
+ }
+}
+
+.wc-sales-readiness-channels {
+ list-style: none;
+ margin: 0 0 var(--wpds-dimension-gap-xl);
+ padding: 0;
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
+ gap: var(--wpds-dimension-gap-xl);
+
+ li {
+ margin: 0;
+ display: flex;
+ flex-direction: column;
+ gap: var(--wpds-dimension-gap-xs);
+ }
+}
+
+.wc-sales-readiness-fold {
+ padding-block-start: var(--wpds-dimension-padding-sm);
+
+ // "Show more" and "Hide": a minimal button whose text lines up with the card text, while its
+ // hover background reaches past it.
+ > .components-button {
+ @include sales-readiness-button(var(--wpds-dimension-padding-sm));
+ margin-inline-start: calc(-1 * var(--wpds-dimension-padding-sm));
+ border-color: transparent;
+
+ // Hide, while the checks are open, and either button after a click, until focus moves.
+ &:not(:disabled):is(:focus, [aria-expanded="true"]) {
+ border-color: var(--wpds-color-stroke-interactive-brand);
+ }
+ }
+}
+
+// No products: the title, a line under it, then Add a product.
+.wc-sales-readiness-empty {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 2px;
+
+ &__title {
+ font-weight: 600;
+ }
+
+ .wc-sales-readiness-row__action {
+ margin-block-start: var(--wpds-dimension-gap-md);
+ }
+}
+
+// Check can't start: the message, then Go to Scheduled Actions.
+.wc-sales-readiness-run-status {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ gap: var(--wpds-dimension-gap-md);
+ margin-block-start: var(--wpds-dimension-gap-md);
+}
+
+.wc-sales-readiness-checked {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: var(--wpds-dimension-gap-lg);
+
+ > div {
+ display: flex;
+ flex-direction: column;
+ gap: 2px;
+ }
+
+ &__intro {
+ display: block;
+ margin-block-end: var(--wpds-dimension-gap-md);
+ }
+
+ // Check again: an outline button.
+ > .components-button {
+ @include sales-readiness-button;
+ border-color: var(--wpds-color-stroke-interactive-brand);
+
+ &:not(:disabled):is(:hover, :active, :focus) {
+ border-color: var(--wpds-color-stroke-interactive-brand-active);
+ }
+
+ &:disabled {
+ border-color: var(--wpds-color-stroke-interactive-brand-disabled);
+ }
+ }
+}
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/test/check-row.test.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/test/check-row.test.tsx
new file mode 100644
index 00000000000..973ce064ebe
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/test/check-row.test.tsx
@@ -0,0 +1,108 @@
+/**
+ * External dependencies
+ */
+import { render, screen } from '@testing-library/react';
+
+/**
+ * Internal dependencies
+ */
+import { CheckRow } from '../components/check-row';
+import type { CheckRow as CheckRowData } from '../types';
+
+const row = ( fields: Partial< CheckRowData > ): CheckRowData => ( {
+ id: 'llms_txt',
+ state: 'open',
+ title: 'Add an llms.txt file',
+ badge: null,
+ text: 'We found no file at /llms.txt.',
+ fix: '',
+ link: null,
+ seen_at: null,
+ ...fields,
+} );
+
+const renderRow = ( data: CheckRowData ) =>
+ render(
+ <ul>
+ <CheckRow row={ data } />
+ </ul>
+ );
+
+describe( 'CheckRow', () => {
+ it( 'shows a failing check as what to do, what was found, and no fix line when there is none', () => {
+ const { container } = renderRow( row( {} ) );
+
+ expect(
+ screen.getByText( 'Add an llms.txt file' )
+ ).toBeInTheDocument();
+ expect(
+ screen.getByText( 'We found no file at /llms.txt.' )
+ ).toBeInTheDocument();
+ expect(
+ container.querySelector( '.wc-sales-readiness-row__fix' )
+ ).toBeNull();
+ expect( screen.queryByRole( 'link' ) ).toBeNull();
+ expect(
+ container.querySelector( '.wc-sales-readiness-row__marker' )
+ ).toHaveAttribute( 'aria-hidden', 'true' );
+ } );
+
+ it( 'marks a blocker Required, with its fix line and where to fix it', () => {
+ renderRow(
+ row( {
+ state: 'required',
+ title: 'Let visitors open store pages without signing in',
+ badge: { intent: 'low', text: 'Required' },
+ fix: 'Turn off the sign-in requirement.',
+ link: {
+ href: '/wp-admin/visibility',
+ text: 'Go to Site visibility',
+ },
+ } )
+ );
+
+ expect( screen.getByText( 'Required' ) ).toBeInTheDocument();
+ expect(
+ screen.getByText( 'Turn off the sign-in requirement.' )
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole( 'link', { name: 'Go to Site visibility' } )
+ ).toHaveAttribute( 'href', '/wp-admin/visibility' );
+ } );
+
+ it( 'says when a check could not run, with what happened', () => {
+ renderRow(
+ row( {
+ state: 'unknown',
+ title: 'Add an llms.txt file',
+ text: "This couldn't be checked. Try again later.",
+ } )
+ );
+
+ expect( screen.getByText( "Couldn't check:" ) ).toBeInTheDocument();
+ expect(
+ screen.getByText( "This couldn't be checked. Try again later." )
+ ).toBeInTheDocument();
+ expect( screen.queryByRole( 'link' ) ).toBeNull();
+ } );
+
+ it( 'shows a passed check by its passing title and why it matters', () => {
+ renderRow(
+ row( {
+ state: 'pass',
+ title: 'Your store has an llms.txt file',
+ text: 'llms.txt gives AI assistants a short summary of your store.',
+ } )
+ );
+
+ expect( screen.getByText( 'Passed:' ) ).toBeInTheDocument();
+ expect(
+ screen.getByText( 'Your store has an llms.txt file' )
+ ).toBeInTheDocument();
+ expect(
+ screen.getByText(
+ 'llms.txt gives AI assistants a short summary of your store.'
+ )
+ ).toBeInTheDocument();
+ } );
+} );
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/test/fix-first.test.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/test/fix-first.test.tsx
new file mode 100644
index 00000000000..7a3f2d58423
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/test/fix-first.test.tsx
@@ -0,0 +1,44 @@
+/**
+ * External dependencies
+ */
+import { render, screen } from '@testing-library/react';
+
+/**
+ * Internal dependencies
+ */
+import { FixFirstList } from '../components/fix-first';
+import type { FixFirstItem } from '../types';
+
+const item = ( id: string, tier: string ): FixFirstItem => ( {
+ id,
+ tier,
+ badge:
+ tier === 'Required for AI shopping'
+ ? { intent: 'low', text: 'Required' }
+ : null,
+ title: id,
+ why: '',
+ link: null,
+} );
+
+describe( 'FixFirstList', () => {
+ it( 'names each tier once, with the Required badge once beside its heading', () => {
+ render(
+ <FixFirstList
+ items={ [
+ item( 'payment_method', 'Required for AI shopping' ),
+ item( 'guest_checkout', 'Required for AI shopping' ),
+ item( 'image', 'Needed to list products' ),
+ ] }
+ />
+ );
+
+ expect(
+ screen.getAllByText( 'Required for AI shopping' )
+ ).toHaveLength( 1 );
+ expect( screen.getAllByText( 'Needed to list products' ) ).toHaveLength(
+ 1
+ );
+ expect( screen.getAllByText( 'Required' ) ).toHaveLength( 1 );
+ } );
+} );
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/test/section-card.test.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/test/section-card.test.tsx
new file mode 100644
index 00000000000..c9d237dba45
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/test/section-card.test.tsx
@@ -0,0 +1,111 @@
+/**
+ * External dependencies
+ */
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+
+/**
+ * Internal dependencies
+ */
+import { SectionCard } from '../components/section-card';
+import type { CheckRow, RowState, Section } from '../types';
+
+const row = ( id: string, state: RowState ): CheckRow => ( {
+ id,
+ state,
+ title: id,
+ badge: null,
+ text: '',
+ fix: '',
+ link: null,
+ seen_at: null,
+} );
+
+const section = ( rows: CheckRow[], folded: CheckRow[] ): Section => ( {
+ id: 'find',
+ title: 'Can AI assistants find your store?',
+ badge: { intent: 'low', text: '3 issues' },
+ note: null,
+ channels: [],
+ rows,
+ folded,
+ empty: null,
+} );
+
+describe( 'SectionCard', () => {
+ it( 'shows every check that did not pass and folds the passed ones', () => {
+ render(
+ <SectionCard
+ section={ section(
+ [
+ row( 'a', 'required' ),
+ row( 'b', 'open' ),
+ row( 'c', 'open' ),
+ row( 'd', 'unknown' ),
+ ],
+ [ row( 'e', 'pass' ) ]
+ ) }
+ />
+ );
+ for ( const shown of [ 'a', 'b', 'c', 'd' ] ) {
+ expect( screen.getByText( shown ) ).toBeVisible();
+ }
+ expect( screen.queryByText( 'e' ) ).toBeNull();
+ expect(
+ screen.getByRole( 'button', { name: 'Show 1 more check' } )
+ ).toBeInTheDocument();
+ } );
+
+ it( 'has no fold when nothing passed', () => {
+ render(
+ <SectionCard section={ section( [ row( 'a', 'open' ) ], [] ) } />
+ );
+ expect( screen.queryByText( /more check/ ) ).toBeNull();
+ } );
+
+ it( 'starts closed when every check passed, and lists them all once opened', async () => {
+ render(
+ <SectionCard
+ section={ section(
+ [],
+ [
+ row( 'a', 'pass' ),
+ row( 'b', 'pass' ),
+ row( 'c', 'pass' ),
+ ]
+ ) }
+ />
+ );
+ expect( screen.queryByText( 'a' ) ).not.toBeVisible();
+ await userEvent.click(
+ screen.getByRole( 'button', {
+ name: /Can AI assistants find your store\?/,
+ } )
+ );
+ for ( const passed of [ 'a', 'b', 'c' ] ) {
+ expect( screen.getByText( passed ) ).toBeVisible();
+ }
+ expect( screen.queryByText( /more check/ ) ).toBeNull();
+ } );
+
+ it( 'shows the no products state with a way to add one', () => {
+ render(
+ <SectionCard
+ section={ {
+ ...section( [], [] ),
+ empty: {
+ title: 'You don’t have any products yet',
+ text: 'Product checks start once you add products.',
+ link: { href: '#new', text: 'Add a product' },
+ },
+ } }
+ />
+ );
+ expect(
+ screen.getByText( 'You don’t have any products yet' )
+ ).toBeVisible();
+ expect(
+ screen.getByRole( 'link', { name: 'Add a product' } )
+ ).toHaveAttribute( 'href', '#new' );
+ } );
+} );
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/test/use-readiness-view.test.tsx b/plugins/woocommerce/client/admin/client/sales-readiness/test/use-readiness-view.test.tsx
new file mode 100644
index 00000000000..13146cf5a14
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/test/use-readiness-view.test.tsx
@@ -0,0 +1,126 @@
+/**
+ * External dependencies
+ */
+import { act, render, renderHook, screen } from '@testing-library/react';
+import apiFetch from '@wordpress/api-fetch';
+
+/**
+ * Internal dependencies
+ */
+import {
+ POLL_FOR_MS,
+ POLL_MS,
+ SCAN_PATH,
+ useReadinessView,
+} from '../use-readiness-view';
+import { RunStatus } from '../components/run-status';
+
+jest.mock( '@wordpress/api-fetch', () => jest.fn() );
+const mockFetch = apiFetch as unknown as jest.Mock;
+
+const view = ( pending: boolean, label = 'Run check' ) => ( {
+ sections: [],
+ fix_first: null,
+ run: { label, pending, stalled: false, message: '', link: null },
+} );
+
+const viewCalls = () =>
+ mockFetch.mock.calls.filter( ( [ args ] ) => args.path !== SCAN_PATH )
+ .length;
+
+describe( 'useReadinessView', () => {
+ beforeEach( () => {
+ jest.useFakeTimers();
+ mockFetch.mockReset();
+ } );
+ afterEach( () => jest.useRealTimers() );
+
+ it( 'reads the view again while a check is pending, and shows the results once it finishes', async () => {
+ mockFetch
+ .mockResolvedValueOnce( view( false ) )
+ .mockResolvedValueOnce( {} )
+ .mockResolvedValueOnce( view( true ) )
+ .mockResolvedValueOnce( view( true ) )
+ .mockResolvedValueOnce( view( false, 'Check again' ) );
+ const { result } = renderHook( () => useReadinessView() );
+ await act( async () => jest.advanceTimersByTime( 0 ) );
+ await act( async () => result.current.runCheck() );
+ expect( result.current.view?.run.pending ).toBe( true );
+
+ await act( async () => jest.advanceTimersByTime( POLL_MS ) );
+ expect( result.current.view?.run.pending ).toBe( true );
+ await act( async () => jest.advanceTimersByTime( POLL_MS ) );
+ expect( result.current.view?.run.label ).toBe( 'Check again' );
+
+ await act( async () => jest.advanceTimersByTime( POLL_MS * 3 ) );
+ expect( viewCalls() ).toBe( 4 );
+ } );
+
+ it( 'uses a view that came with the page without loading it again', async () => {
+ const initial = view( false, 'Check again' ) as never;
+ const { result } = renderHook( () => useReadinessView( initial ) );
+ await act( async () => jest.advanceTimersByTime( POLL_MS ) );
+ expect( result.current.view ).toBe( initial );
+ expect( viewCalls() ).toBe( 0 );
+ } );
+
+ it( 'polls a pending view that came with the page until the check finishes', async () => {
+ mockFetch.mockImplementation( async () =>
+ view( false, 'Check again' )
+ );
+ const { result } = renderHook( () =>
+ useReadinessView( view( true ) as never )
+ );
+ await act( async () => jest.advanceTimersByTime( POLL_MS ) );
+ expect( result.current.view?.run.label ).toBe( 'Check again' );
+ expect( viewCalls() ).toBe( 1 );
+ } );
+
+ it( 'does not poll when nothing is pending', async () => {
+ mockFetch.mockImplementation( async () => view( false ) );
+ renderHook( () => useReadinessView() );
+ await act( async () => jest.advanceTimersByTime( POLL_MS * 3 ) );
+ expect( viewCalls() ).toBe( 1 );
+ } );
+
+ it( 'stops polling a check that stays pending', async () => {
+ mockFetch.mockImplementation( async () => view( true ) );
+ renderHook( () => useReadinessView() );
+ await act( async () => jest.advanceTimersByTime( 0 ) );
+ for ( let i = 0; i < POLL_FOR_MS / POLL_MS + 5; i++ ) {
+ await act( async () => jest.advanceTimersByTime( POLL_MS ) );
+ }
+ expect( viewCalls() ).toBe( POLL_FOR_MS / POLL_MS );
+ } );
+} );
+
+describe( 'RunStatus', () => {
+ const run = ( pending: boolean, stalled: boolean, message: string ) => ( {
+ label: 'Run check',
+ pending,
+ stalled,
+ message,
+ link: null,
+ } );
+
+ it( 'shows no spinner while a check runs, only its message for screen readers', () => {
+ const { container } = render(
+ <RunStatus run={ run( true, false, 'Checking your store.' ) } />
+ );
+ expect( container.querySelector( '.components-spinner' ) ).toBeNull();
+ expect( screen.getByRole( 'status' ) ).toHaveTextContent(
+ 'Checking your store.'
+ );
+ expect(
+ container.querySelector( '.wc-sales-readiness__muted' )
+ ).toBeNull();
+ } );
+
+ it( 'shows the message once the check is stuck', () => {
+ const { container } = render(
+ <RunStatus run={ run( true, true, 'Not started.' ) } />
+ );
+ expect( container.querySelector( '.components-spinner' ) ).toBeNull();
+ expect( screen.getByText( 'Not started.' ) ).toBeVisible();
+ } );
+} );
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/types.ts b/plugins/woocommerce/client/admin/client/sales-readiness/types.ts
new file mode 100644
index 00000000000..704b9b05562
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/types.ts
@@ -0,0 +1,111 @@
+/**
+ * What wc/v3/agent-readiness/view returns: the Sales readiness page and the AI tools
+ * Overview as text, badges and links, built by ReadinessCheckPage in PHP.
+ */
+
+export type BadgeIntent =
+ 'high' | 'medium' | 'low' | 'stable' | 'informational' | 'draft' | 'none';
+
+export interface ViewBadge {
+ intent: BadgeIntent;
+ text: string;
+}
+
+export interface ViewLink {
+ /** Empty when the text is shown without a link. */
+ href: string;
+ text: string;
+}
+
+export type RowState = 'open' | 'required' | 'unknown' | 'pass';
+
+export interface CheckRow {
+ /** The check's id. */
+ id: string;
+ state: RowState;
+ /** What to do while the check fails, its passing title once it passes. */
+ title: string;
+ /** Required, or Likely conflict. */
+ badge: ViewBadge | null;
+ /** Why it matters, and what the check found while it fails. */
+ text: string;
+ /** What to do, or '' when there is nothing more specific than the title. */
+ fix: string;
+ link: ViewLink | null;
+ seen_at: ViewLink | null;
+}
+
+export interface FixFirstItem {
+ /** The check's id. */
+ id: string;
+ tier: string;
+ /** Shown beside the tier heading: Required for the Required tier. */
+ badge: ViewBadge | null;
+ title: string;
+ why: string;
+ link: ViewLink | null;
+}
+
+export interface FixFirst {
+ title: string;
+ ranking: string;
+ items: FixFirstItem[];
+}
+
+export interface Channel {
+ name: string;
+ listable: string;
+ /** "of 15 can be listed". */
+ of: string;
+}
+
+export interface Section {
+ id: string;
+ title: string;
+ badge: ViewBadge;
+ note: string | null;
+ channels: Channel[];
+ rows: CheckRow[];
+ folded: CheckRow[];
+ /** What the card says instead of checks: every product passed, or there are no products yet. */
+ empty: { title: string; text: string; link: ViewLink | null } | null;
+}
+
+export interface Declared {
+ title: string;
+ badge: ViewBadge;
+ text: string;
+ items: { name: string; found: boolean }[];
+}
+
+export interface ShoppingCard {
+ title: string;
+ badge: ViewBadge | null;
+ text: string;
+ button: ViewLink;
+}
+
+export interface ReadinessView {
+ title: string;
+ description: string;
+ last_checked: string;
+ checked_note: string | null;
+ intro: string | null;
+ run: {
+ label: string;
+ pending: boolean;
+ stalled: boolean;
+ message: string;
+ /** Scheduled Actions, when the check can't start. */
+ link: ViewLink | null;
+ };
+ fix_first: FixFirst | null;
+ sections: Section[];
+ declared: Declared | null;
+ overview: {
+ shopping: ShoppingCard;
+ view_all: ViewLink;
+ /** "Based on your 5,000 most recently changed products.", when the check stopped at the limit. */
+ based_on: string | null;
+ };
+}
diff --git a/plugins/woocommerce/client/admin/client/sales-readiness/use-readiness-view.ts b/plugins/woocommerce/client/admin/client/sales-readiness/use-readiness-view.ts
new file mode 100644
index 00000000000..260e27dd755
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/sales-readiness/use-readiness-view.ts
@@ -0,0 +1,102 @@
+/**
+ * External dependencies
+ */
+import { useCallback, useEffect, useRef, useState } from '@wordpress/element';
+import apiFetch from '@wordpress/api-fetch';
+import { __ } from '@wordpress/i18n';
+
+/**
+ * Internal dependencies
+ */
+import type { ReadinessView } from './types';
+
+export const VIEW_PATH = '/wc/v3/agent-readiness/view';
+export const SCAN_PATH = '/wc/v3/agent-readiness/scan';
+
+/**
+ * How often the view is read again while a check is pending, so its results show once it finishes.
+ */
+export const POLL_MS = 5000;
+
+/**
+ * How long a pending check is polled for. The pending message already says when a check is stuck.
+ */
+export const POLL_FOR_MS = 10 * 60 * 1000;
+
+/**
+ * Loads the view, and queues a check: the scan runs in the background, so after
+ * queuing it the view is read again for the pending message, and then every
+ * POLL_MS while the check is pending, so the results replace it when it finishes.
+ * A view that came with the page is used as is, without loading it again.
+ */
+export function useReadinessView( initialView: ReadinessView | null = null ) {
+ const [ view, setView ] = useState< ReadinessView | null >( initialView );
+ const [ error, setError ] = useState< string | null >( null );
+ const [ running, setRunning ] = useState( false );
+ const pendingSince = useRef< number | null >( null );
+ // True after a view has been shown: poll failures must not replace it or stop polling.
+ const hasView = useRef( initialView !== null );
+
+ const load = useCallback( async () => {
+ try {
+ const loaded = await apiFetch< ReadinessView >( {
+ path: VIEW_PATH,
+ } );
+ setView( loaded );
+ setError( null );
+ hasView.current = true;
+ } catch {
+ if ( hasView.current ) {
+ return;
+ }
+ setError(
+ __(
+ 'Your check results didn’t load. Reload the page to try again.',
+ 'woocommerce'
+ )
+ );
+ }
+ }, [] );
+
+ const preloaded = useRef( initialView );
+ useEffect( () => {
+ if ( ! preloaded.current ) {
+ void load();
+ }
+ }, [ load ] );
+
+ useEffect( () => {
+ if ( ! view?.run.pending ) {
+ pendingSince.current = null;
+ return;
+ }
+ pendingSince.current ??= Date.now();
+ const timer = setInterval( () => {
+ if ( Date.now() - ( pendingSince.current ?? 0 ) >= POLL_FOR_MS ) {
+ clearInterval( timer );
+ return;
+ }
+ void load();
+ }, POLL_MS );
+ return () => clearInterval( timer );
+ }, [ view?.run.pending, load ] );
+
+ const runCheck = useCallback( async () => {
+ setRunning( true );
+ try {
+ await apiFetch( { path: SCAN_PATH, method: 'POST' } );
+ await load();
+ } catch {
+ setError(
+ __(
+ 'The check didn’t start. Reload the page to try again.',
+ 'woocommerce'
+ )
+ );
+ } finally {
+ setRunning( false );
+ }
+ }, [ load ] );
+
+ return { view, error, running, runCheck };
+}
diff --git a/plugins/woocommerce/client/admin/client/wp-admin-scripts/settings-embed/index.tsx b/plugins/woocommerce/client/admin/client/wp-admin-scripts/settings-embed/index.tsx
index 4610ee8325c..802f34f1732 100644
--- a/plugins/woocommerce/client/admin/client/wp-admin-scripts/settings-embed/index.tsx
+++ b/plugins/woocommerce/client/admin/client/wp-admin-scripts/settings-embed/index.tsx
@@ -5,7 +5,7 @@
/**
* External dependencies
*/
-import { createRoot } from '@wordpress/element';
+import { createRoot, lazy, Suspense } from '@wordpress/element';
/**
* Internal dependencies
@@ -32,6 +32,7 @@ import { registerSettingsEmailPreviewFill } from '~/settings-email/settings-emai
import { registerSettingsEmailFeedbackFill } from '~/settings-email/settings-email-feedback-slotfill';
import { registerSettingsEmailListingFill } from '~/settings-email/settings-email-listing-slotfill';
import { registerSettingsUIScreens } from '~/settings/settings-ui-registry';
+import { registerAiShoppingHeader } from '~/sales-readiness/ai-shopping-header';
const renderPaymentsSettings = () => {
const pages = [
@@ -72,6 +73,51 @@ const renderPaymentsSettings = () => {
} );
};
+const SalesReadinessOverview = lazy(
+ () =>
+ import(
+ /* webpackChunkName: "sales-readiness-overview" */ '~/sales-readiness/overview'
+ )
+);
+
+/**
+ * WooCommerce > Settings > AI tools opens on the Overview, which the PHP tab leaves a root for.
+ */
+const renderSalesReadinessOverview = () => {
+ const root = document.getElementById( 'wc-agent-readiness-overview' );
+ if ( root ) {
+ let initialView = null;
+ try {
+ initialView = JSON.parse( root.dataset.view ?? 'null' );
+ } catch {
+ // The Overview loads the view itself.
+ }
+ createRoot( root ).render(
+ <Suspense fallback={ null }>
+ <SalesReadinessOverview initialView={ initialView } />
+ </Suspense>
+ );
+ }
+};
+
+/**
+ * AI tools > AI shopping: the breadcrumb and description become the page header. The PHP section
+ * leaves them on a root, with a plain breadcrumb that shows until this runs.
+ */
+const renderAiShoppingHeader = () => {
+ const root = document.getElementById( 'wc-agentic-commerce-header' );
+ if ( root ) {
+ const { parentLabel, parentUrl, title, description } = root.dataset;
+ registerAiShoppingHeader( {
+ parentLabel: parentLabel ?? '',
+ parentUrl: parentUrl ?? '',
+ title: title ?? '',
+ description: description ?? '',
+ } );
+ root.remove();
+ }
+};
+
const registerSlotFills = () => {
possiblyRenderSettingsSlots();
registerTaxSettingsConflictErrorFill();
@@ -100,4 +146,6 @@ const registerSlotFills = () => {
};
renderPaymentsSettings();
+renderSalesReadinessOverview();
+renderAiShoppingHeader();
registerSlotFills();
diff --git a/plugins/woocommerce/client/legacy/css/admin.scss b/plugins/woocommerce/client/legacy/css/admin.scss
index 66b9c41da41..8293225203c 100644
--- a/plugins/woocommerce/client/legacy/css/admin.scss
+++ b/plugins/woocommerce/client/legacy/css/admin.scss
@@ -9729,9 +9729,55 @@ body.woocommerce-settings-payments-section_legacy {
}
}
-// Settings > Agentic commerce.
+// Settings > AI tools.
+// White panel under a grey tab strip, as on the Payments tab (settings-payments-body.scss).
+body.woocommerce_page_wc-settings.woocommerce-settings-agentic-commerce-tab {
+
+ .nav-tab-wrapper {
+ background-color: #f0f0f1;
+ }
+
+ #wpcontent {
+ display: flex;
+ flex-direction: column;
+ }
+
+ #wpbody,
+ #mainform {
+ background-color: #fff;
+ }
+
+ #wpbody {
+ flex: 1;
+ }
+
+ // Save changes is 40px, like Save in the design.
+ .woocommerce-save-button.components-button {
+ block-size: 40px;
+ padding-inline: 16px;
+ }
+}
+
+.wc-agentic-commerce-breadcrumb {
+ font-size: 14px;
+
+ a {
+ color: #1d2327;
+ }
+
+ [aria-hidden="true"] {
+ margin-inline: 4px;
+ color: #a7aaad;
+ }
+
+ [aria-current="page"] {
+ font-weight: 600;
+ }
+}
+
.wc-agentic-commerce {
max-inline-size: 720px;
+ margin-inline: auto;
h2,
h3 {
@@ -9763,53 +9809,44 @@ body.woocommerce-settings-payments-section_legacy {
.wc-agentic-commerce-card__header {
padding: 24px 24px 16px;
- p {
- margin: 4px 0 0;
- color: #50575e;
- }
-
- &--split {
+ // The title, with how many steps are left at the end of the line.
+ .wc-agentic-commerce-card__title {
display: flex;
justify-content: space-between;
- align-items: flex-start;
+ align-items: center;
gap: 16px;
}
+
+ p {
+ margin: 4px 0 0;
+ color: #50575e;
+ }
}
- .wc-agentic-commerce-card__body,
- .wc-agentic-commerce-card__footer {
+ .wc-agentic-commerce-card__body {
margin: 0;
padding: 16px 24px;
}
- .wc-agentic-commerce-card__footer {
- border-block-start: 1px solid #f0f0f1;
- color: #50575e;
+ .wc-agentic-commerce-card__header + .wc-agentic-commerce-card__body {
+ padding-block-start: 0;
}
- .wc-agentic-commerce-card--split {
- display: grid;
- grid-template-columns: 2fr 1fr;
-
- > div {
- padding: 24px;
- }
+ // Copy is 40px, the height of its field.
+ .wc-agentic-commerce-address {
+ display: flex;
+ gap: 8px;
- > div + div {
- border-inline-start: 1px solid #f0f0f1;
+ input,
+ .button {
+ min-block-size: 40px;
}
- h3 {
- margin-block-end: 8px;
- font-size: 11px;
- text-transform: uppercase;
+ input {
+ flex: 1;
}
}
- .wc-agentic-commerce-placeholder p {
- color: #757575;
- }
-
.wc-agentic-commerce-policies .form-table {
display: block;
inline-size: auto;
@@ -9834,6 +9871,17 @@ body.woocommerce-settings-payments-section_legacy {
inline-size: 100%;
min-inline-size: 0 !important;
}
+
+ // A Status or Sales readiness link opens the page on the field it names.
+ :target {
+ scroll-margin-block-start: 120px;
+ }
+
+ tr:has(:target) {
+ outline: 2px solid var(--wp-admin-theme-color, #2271b1);
+ outline-offset: 4px;
+ border-radius: 2px;
+ }
}
}
@@ -9875,6 +9923,17 @@ body.woocommerce-settings-payments-section_legacy {
}
}
+.wc-agentic-commerce-header {
+ margin-block: 16px 20px;
+ padding-block-end: 16px;
+ border-block-end: 1px solid #dcdcde;
+
+ p {
+ margin: 4px 0 0;
+ color: #757575;
+ }
+}
+
.wc-agentic-commerce-counts {
display: grid;
grid-template-columns: repeat(3, 1fr);
@@ -9893,6 +9952,14 @@ body.woocommerce-settings-payments-section_legacy {
border-inline-start: 1px solid #f0f0f1;
}
+ li > span {
+ color: #757575;
+ font-size: 11px;
+ font-weight: 500;
+ letter-spacing: 0.04em;
+ text-transform: uppercase;
+ }
+
strong {
font-size: 1.6em;
font-weight: 400;
@@ -9900,123 +9967,154 @@ body.woocommerce-settings-payments-section_legacy {
}
}
-.wc-agentic-commerce-group {
+.wc-agentic-commerce-badge {
+ display: inline-block;
+ flex: none;
+ white-space: nowrap;
+ padding: 2px 8px;
+ border: 1px solid transparent;
+ border-radius: 4px;
+ font-size: 12px;
+ line-height: 1.5;
+ background: #f0f0f1;
+ color: #1d2327;
- ul {
- margin: 0;
+ &--info {
+ background: #fff;
+ border-color: #dcdcde;
}
- &__title {
+ &--pass {
+ background: #edfaef;
+ color: $green;
+ }
+
+ &--check {
+ background: #f9e2a1;
+ color: #1d2327;
+ }
+}
+
+.wc-agentic-commerce-results {
+ margin: 8px 0 0;
+
+ li {
display: flex;
+ justify-content: space-between;
align-items: center;
- gap: 8px;
margin: 0;
- padding: 10px 24px;
- font-size: 13px;
- background: #f6f7f7;
- border-block: 1px solid #f0f0f1;
+ padding: 12px 24px;
+ border-block-start: 1px solid #f0f0f1;
}
- &--done summary {
- cursor: pointer;
+ li:first-child {
+ border-block-start-color: #dcdcde;
}
}
-.wc-agentic-commerce-count {
- padding: 0 6px;
- border-radius: 8px;
- background: #dcdcde;
- font-size: 11px;
+.wc-agentic-commerce-items {
+ margin: 0 24px;
}
-.wc-agentic-commerce-check {
+.wc-agentic-commerce-item {
display: flex;
align-items: center;
- gap: 12px;
+ gap: 16px;
margin: 0;
- padding: 12px 24px;
+ padding: 12px 0;
border-block-end: 1px solid #f0f0f1;
- &__text {
- flex: 1;
- font-weight: 600;
+ // Dividers only between rows.
+ &:last-child {
+ border-block-end: 0;
}
- &__icon {
- inline-size: 18px;
- block-size: 18px;
- border: 2px solid #a7aaad;
- border-radius: 50%;
+ > div {
+ flex: 1;
+ min-inline-size: 0;
}
- &--required &__icon {
- border-color: #b26200;
+ p {
+ margin: 0 0 2px;
}
- &--done .dashicons {
- color: $green;
+ .description {
+ color: #757575;
}
-}
-.wc-agentic-commerce-badge {
- display: inline-block;
- white-space: nowrap;
- padding: 0 8px;
- border-radius: 2px;
- font-weight: 600;
- background: #f0f0f1;
- color: #1d2327;
+ &__title {
+ font-size: 13px;
+ font-weight: 600;
- &--pass {
- background: #edfaef;
- color: $green;
+ .wc-agentic-commerce-badge {
+ margin-inline-start: 8px;
+ font-weight: 400;
+ }
}
- &--fix {
- background: #fcf0e1;
- color: #8a4d00;
+ // The design's line icons: a dashed circle for a step to do, a circled check once it's done.
+ &__icon {
+ flex: none;
+ inline-size: 24px;
+ block-size: 24px;
+ background-color: #1e1e1e;
+ mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.5'%3E%3Cpath d='M11.0537 4.81202C11.6819 4.72933 12.3181 4.72933 12.9463 4.81202M14.7744 5.30187C15.3598 5.54434 15.9109 5.86249 16.4135 6.24819M17.7518 7.58648C18.1375 8.08914 18.4557 8.64019 18.6981 9.22555M19.188 11.0537C19.2707 11.6819 19.2707 12.3181 19.188 12.9463M18.6981 14.7744C18.4557 15.3598 18.1375 15.9109 17.7518 16.4135M16.4135 17.7518C15.9109 18.1375 15.3598 18.4557 14.7744 18.6981M12.9463 19.188C12.3181 19.2707 11.6819 19.2707 11.0537 19.188M9.22555 18.6981C8.64019 18.4557 8.08914 18.1375 7.58648 17.7518M6.24819 16.4135C5.86249 15.9109 5.54434 15.3598 5.30187 14.7744M4.81202 12.9463C4.72933 12.3181 4.72933 11.6819 4.81202 11.0537M5.30187 9.22555C5.54434 8.64019 5.86249 8.08914 6.24819 7.58648M7.58648 6.24819C8.08914 5.86249 8.64019 5.54434 9.22555 5.30187'/%3E%3C/svg%3E") center / contain no-repeat;
}
- &--check {
- background: #fcf9e8;
- color: #8a6100;
+ &--pass &__icon {
+ mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.5'%3E%3Cpath stroke-linejoin='round' d='M12 19.25C16.0041 19.25 19.25 16.0041 19.25 12C19.25 7.99594 16.0041 4.75 12 4.75C7.99594 4.75 4.75 7.99594 4.75 12C4.75 16.0041 7.99594 19.25 12 19.25Z'/%3E%3Cpath d='M9 12L11 14L15 10'/%3E%3C/svg%3E");
}
}
-.wc-agentic-commerce-card__section {
- padding: 16px 24px 24px;
- border-block-start: 1px solid #f0f0f1;
+// Review: an outline button, 32px, at the end of each open step.
+.wc-agentic-commerce .wc-agentic-commerce-review.button {
+ flex: none;
+ min-block-size: 32px;
+ padding-inline: 8px;
+ border-color: var(--wp-admin-theme-color, #3858e9);
+ background: #fff;
+ color: var(--wp-admin-theme-color, #3858e9);
+ font-weight: 600;
+ line-height: 30px;
+}
- h3 {
- margin-block-end: 8px;
+.wc-agentic-commerce-more {
+ padding: 12px 24px 20px;
+
+ > summary {
+ color: var(--wp-admin-theme-color, #2271b1);
+ font-weight: 600;
+ cursor: pointer;
+ list-style: none;
+
+ &::-webkit-details-marker {
+ display: none;
+ }
}
-}
-.wc-agentic-commerce-channels {
- margin-block-end: 16px;
-}
+ > .wc-agentic-commerce-items {
+ margin: 8px 0 0;
+ }
-.wc-agentic-commerce-summary {
- max-inline-size: 900px;
+ .wc-agentic-commerce-more__hide,
+ &[open] .wc-agentic-commerce-more__show {
+ display: none;
+ }
- li {
- display: flex;
- justify-content: space-between;
- padding: 8px 12px;
- margin: 0;
- background: #fff;
- border: 1px solid #dcdcde;
- border-block-end-width: 0;
+ &[open] .wc-agentic-commerce-more__hide {
+ display: inline;
+ }
- &:last-child {
- border-block-end-width: 1px;
- }
+ &--js[open] > summary {
+ display: none;
}
-}
-.wc-agentic-commerce-checks + details,
-.wc-agentic-commerce-checks ~ h4 {
- margin-block-start: 12px;
+ .wc-agentic-commerce-more__close {
+ margin-block-start: 8px;
+ color: var(--wp-admin-theme-color, #2271b1);
+ font-weight: 600;
+ text-decoration: none;
+ }
}
.wc-agentic-commerce-ucp-switch {
diff --git a/plugins/woocommerce/client/legacy/js/admin/wc-agentic-commerce-settings.js b/plugins/woocommerce/client/legacy/js/admin/wc-agentic-commerce-settings.js
index a98acedbe2d..e180fa90471 100644
--- a/plugins/woocommerce/client/legacy/js/admin/wc-agentic-commerce-settings.js
+++ b/plugins/woocommerce/client/legacy/js/admin/wc-agentic-commerce-settings.js
@@ -9,10 +9,6 @@
const toggle = document.querySelector( '.wc-agentic-commerce-ucp-switch' );
const knob = toggle && toggle.querySelector( '.woocommerce-input-toggle' );
const message = document.querySelector( '.wc-agentic-commerce-ucp-message' );
- const statusBadge = document.querySelector( '.wc-agentic-commerce-status' );
- const accessSummary = document.querySelector(
- '.wc-agentic-commerce-access-summary'
- );
const render = ( enabled ) => {
toggle.setAttribute( 'aria-checked', enabled ? 'true' : 'false' );
@@ -20,22 +16,13 @@
knob.classList.toggle( 'woocommerce-input-toggle--disabled', ! enabled );
};
- const renderStatus = ( status ) => {
- if ( ! statusBadge || ! settings.i18n.statusLabel[ status ] ) {
- return;
- }
- statusBadge.textContent = settings.i18n.statusLabel[ status ];
- const badges = { active: 'pass', off: 'off', needs_attention: 'fix' };
- Object.values( badges ).forEach( ( badge ) =>
- statusBadge.classList.remove( 'wc-agentic-commerce-badge--' + badge )
- );
- statusBadge.classList.add(
- 'wc-agentic-commerce-badge--' + ( badges[ status ] || 'off' )
- );
- };
if ( toggle && knob && message ) {
+ let leaving = false;
toggle.addEventListener( 'click', async () => {
+ if ( leaving ) {
+ return;
+ }
const enable = toggle.getAttribute( 'aria-checked' ) !== 'true';
toggle.disabled = true;
knob.classList.add( 'woocommerce-input-toggle--loading' );
@@ -46,39 +33,57 @@
data: { enabled: enable },
} );
render( response.enabled );
- renderStatus( response.status );
- message.textContent = response.enabled ? settings.i18n.on : '';
- if ( accessSummary ) {
- accessSummary.textContent =
- accessSummary.dataset[ response.enabled ? 'on' : 'off' ];
+ // Status and the other cards depend on the switch.
+ // A dirty form warns before leaving, so don't reload over unsaved fields.
+ if ( window.onbeforeunload ) {
+ message.textContent = settings.i18n.unsaved;
+ return;
}
+ leaving = true;
+ // Not reload(): after Save changes, that would post the settings form again.
+ window.location.assign( window.location.href.split( '#' )[ 0 ] );
} catch ( error ) {
render( ! enable );
message.textContent = ( error && error.message ) || settings.i18n.error;
} finally {
- toggle.disabled = false;
- knob.classList.remove( 'woocommerce-input-toggle--loading' );
+ if ( ! leaving ) {
+ toggle.disabled = false;
+ knob.classList.remove( 'woocommerce-input-toggle--loading' );
+ }
}
} );
}
- const run = document.querySelector( '.wc-agentic-commerce-run' );
- const runMessage = document.querySelector( '.wc-agentic-commerce-run-message' );
- if ( run && runMessage ) {
- run.addEventListener( 'click', async () => {
- run.disabled = true;
- try {
- await window.wp.apiFetch( {
- path: settings.scanPath,
- method: 'POST',
- } );
- runMessage.textContent = settings.i18n.running;
- } catch ( error ) {
- run.disabled = false;
- runMessage.textContent = ( error && error.message ) || settings.i18n.error;
+ // "Hide" goes below an opened fold, as a button that closes it; without this script the summary toggles.
+ document.querySelectorAll( '.wc-agentic-commerce-more' ).forEach( ( details ) => {
+ const summary = details.querySelector( ':scope > summary' );
+ const label = summary && summary.querySelector( '.wc-agentic-commerce-more__hide' );
+ if ( ! label ) {
+ return;
+ }
+ const hide = document.createElement( 'button' );
+ hide.type = 'button';
+ hide.className = 'button-link wc-agentic-commerce-more__close';
+ hide.textContent = label.textContent;
+ hide.addEventListener( 'click', () => {
+ details.open = false;
+ summary.focus();
+ } );
+ details.append( hide );
+ details.classList.add( 'wc-agentic-commerce-more--js' );
+ // The summary hides once open, so focus moves to what it revealed.
+ details.addEventListener( 'toggle', () => {
+ const active = details.ownerDocument.activeElement;
+ if ( ! details.open || ( active !== summary && active !== details.ownerDocument.body ) ) {
+ return;
+ }
+ const revealed = summary.nextElementSibling;
+ if ( revealed && revealed !== hide ) {
+ revealed.tabIndex = -1;
+ revealed.focus();
}
} );
- }
+ } );
document.querySelectorAll( '.wc-agentic-commerce-copy' ).forEach( ( button ) => {
button.addEventListener( 'click', async () => {
diff --git a/plugins/woocommerce/includes/admin/views/html-admin-settings.php b/plugins/woocommerce/includes/admin/views/html-admin-settings.php
index 08e0f53054d..c05d0c750fb 100644
--- a/plugins/woocommerce/includes/admin/views/html-admin-settings.php
+++ b/plugins/woocommerce/includes/admin/views/html-admin-settings.php
@@ -62,7 +62,9 @@ try {
}
// Drill-down pages replace the top-level settings tabs with their own header when the shell can render.
+// AI tools > AI shopping renders its header, with the breadcrumb back to AI tools, from settings-embed.
$hide_nav = ( 'checkout' === $current_tab && in_array( $current_section, array( 'offline', 'bacs', 'cheque', 'cod' ), true ) )
+ || ( 'agentic-commerce' === $current_tab && 'shopping' === $current_section )
|| $is_rendering_settings_ui_drill_down;
$is_settings_ui_page = null !== $settings_ui_settings_page;
diff --git a/plugins/woocommerce/includes/class-woocommerce.php b/plugins/woocommerce/includes/class-woocommerce.php
index e91f2206534..2e45af8370b 100644
--- a/plugins/woocommerce/includes/class-woocommerce.php
+++ b/plugins/woocommerce/includes/class-woocommerce.php
@@ -465,6 +465,7 @@ final class WooCommerce {
$container->get( Automattic\WooCommerce\Internal\AgentReadiness\ScheduledScan::class )->register();
$container->get( Automattic\WooCommerce\Internal\AgentReadiness\ReadinessRestController::class )->register();
$container->get( Automattic\WooCommerce\Internal\AgentReadiness\AgenticCommerceSettings::class )->register();
+ $container->get( Automattic\WooCommerce\Internal\AgentReadiness\ReadinessCheckPage::class )->register();
$container->get( Automattic\WooCommerce\Internal\AgentReadiness\ProductsList::class )->register();
$container->get( Automattic\WooCommerce\Internal\Admin\OrderTaxLookupMigrator::class )->register();
$container->get( Automattic\WooCommerce\Internal\ProductDownloads\DownloadableFileAttachments::class )->register();
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/AgentReadiness.php b/plugins/woocommerce/src/Internal/AgentReadiness/AgentReadiness.php
index 7d6305439e0..2c07f4da883 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/AgentReadiness.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/AgentReadiness.php
@@ -393,7 +393,7 @@ class AgentReadiness {
*
* @param array<string, mixed>|null $report Stored report.
* @param array<int, array{id:string,ok:bool|null,blocks:string,level:string,name:string,label:string,why:string,fix:string,fix_url:string}>|null $live Store conditions already read, or null to read them.
- * @return array<int, array{id:string,ok:bool|null,blocks:string,group?:string,level:string,name:string,label:string,why:string,fix:string,fix_url:string,conflict?:bool,pending?:bool,seen_at?:string}>
+ * @return array<int, array{id:string,ok:bool|null,blocks:string,group?:string,level:string,name:string,label:string,why:string,fix:string,fix_url:string,conflict?:bool,pending?:bool,seen_at?:string,source?:string}>
*/
public function get_store_checks( ?array $report, ?array $live = null ): array {
$checks = $live ?? $this->store_conditions->all();
@@ -419,6 +419,7 @@ class AgentReadiness {
'conflict' => ! empty( $check['conflict'] ),
'pending' => ! empty( $check['pending'] ),
'seen_at' => (string) ( $check['seen_at'] ?? '' ),
+ 'source' => sanitize_text_field( (string) ( $check['source'] ?? '' ) ),
);
}
return $checks;
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/AgenticCommerceSettings.php b/plugins/woocommerce/src/Internal/AgentReadiness/AgenticCommerceSettings.php
index e73351c5ea6..4c0d3a050c2 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/AgenticCommerceSettings.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/AgenticCommerceSettings.php
@@ -9,7 +9,7 @@ use Automattic\WooCommerce\Internal\RegisterHooksInterface;
defined( 'ABSPATH' ) || exit;
/**
- * Adds the WooCommerce > Settings > Agentic commerce tab while the
+ * Adds the WooCommerce > Settings > AI tools tab while the
* agent_readiness feature is enabled, and names the options it saves.
*
* @since 11.4.0
@@ -62,27 +62,11 @@ class AgenticCommerceSettings implements RegisterHooksInterface {
private AgentReadiness $agent_readiness;
/**
- * UCP switch.
+ * Sales readiness.
*
- * @var UcpSwitch
+ * @var ReadinessCheckPage
*/
- private UcpSwitch $ucp_switch;
-
- /**
- * Background scan.
- *
- * @var ScheduledScan
- */
- private ScheduledScan $scheduled_scan;
-
- /**
- * Link to the AI tools tab: its landing page, or a section of it.
- *
- * @param string $section Section id, or '' for the landing page.
- */
- public static function url( string $section = '' ): string {
- return admin_url( 'admin.php?page=wc-settings&tab=' . self::TAB . ( '' === $section ? '' : '§ion=' . $section ) );
- }
+ private ReadinessCheckPage $readiness_page;
/**
* Initialize dependencies.
@@ -92,15 +76,22 @@ class AgenticCommerceSettings implements RegisterHooksInterface {
* @param FeaturesController $features_controller Features controller.
* @param StoreConditions $store_conditions Store conditions.
* @param AgentReadiness $agent_readiness Readiness service.
- * @param UcpSwitch $ucp_switch UCP switch.
- * @param ScheduledScan $scheduled_scan Background scan.
+ * @param ReadinessCheckPage $readiness_page Sales readiness.
*/
- final public function init( FeaturesController $features_controller, StoreConditions $store_conditions, AgentReadiness $agent_readiness, UcpSwitch $ucp_switch, ScheduledScan $scheduled_scan ): void {
+ final public function init( FeaturesController $features_controller, StoreConditions $store_conditions, AgentReadiness $agent_readiness, ReadinessCheckPage $readiness_page ): void {
$this->features_controller = $features_controller;
$this->store_conditions = $store_conditions;
$this->agent_readiness = $agent_readiness;
- $this->ucp_switch = $ucp_switch;
- $this->scheduled_scan = $scheduled_scan;
+ $this->readiness_page = $readiness_page;
+ }
+
+ /**
+ * Link to the AI tools tab: its landing page, or a section of it.
+ *
+ * @param string $section Section id, or '' for the landing page.
+ */
+ public static function url( string $section = '' ): string {
+ return admin_url( 'admin.php?page=wc-settings&tab=' . self::TAB . ( '' === $section ? '' : '§ion=' . $section ) );
}
/**
@@ -120,10 +111,28 @@ class AgenticCommerceSettings implements RegisterHooksInterface {
return;
}
add_filter( 'woocommerce_get_settings_pages', array( $this, 'handle_woocommerce_get_settings_pages' ) );
+ add_filter( 'admin_body_class', array( $this, 'handle_admin_body_class' ), 20 );
+ }
+
+ /**
+ * Mark the AI tools tab on the body, so its panel can be white like the Payments tab.
+ *
+ * @internal
+ *
+ * @param mixed $classes Body classes.
+ * @return mixed
+ */
+ public function handle_admin_body_class( $classes ) {
+ global $current_tab;
+
+ if ( ! is_string( $classes ) || self::TAB !== $current_tab ) {
+ return $classes;
+ }
+ return "$classes woocommerce-settings-agentic-commerce-tab";
}
/**
- * Add the Agentic commerce page to the settings pages.
+ * Add the AI tools tab to the settings pages.
*
* @internal
*
@@ -134,7 +143,7 @@ class AgenticCommerceSettings implements RegisterHooksInterface {
if ( ! is_array( $pages ) || ! class_exists( \WC_Settings_Page::class, false ) ) {
return $pages;
}
- $pages[] = new AgenticCommerceSettingsPage( $this->store_conditions, $this->agent_readiness, $this->ucp_switch, $this->scheduled_scan );
+ $pages[] = new AgenticCommerceSettingsPage( $this->store_conditions, $this->agent_readiness, $this->readiness_page );
return $pages;
}
}
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/AgenticCommerceSettingsPage.php b/plugins/woocommerce/src/Internal/AgentReadiness/AgenticCommerceSettingsPage.php
index f3a17b11b69..37a57975ed5 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/AgenticCommerceSettingsPage.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/AgenticCommerceSettingsPage.php
@@ -3,49 +3,30 @@ declare( strict_types = 1 );
namespace Automattic\WooCommerce\Internal\AgentReadiness;
-use Automattic\WooCommerce\Enums\ProductType;
use Automattic\WooCommerce\StoreApi\Utilities\Ucp\Utils as UcpUtils;
-use Automattic\WooCommerce\Internal\Traits\ScriptDebug;
defined( 'ABSPATH' ) || exit;
/**
- * WooCommerce > Settings > Agentic commerce. The UCP switch saves on its own
- * through wc/v3/agent-readiness/ucp; the store policy fields save with
- * Save changes. Only created by AgenticCommerceSettings while the
- * agent_readiness feature is enabled, after WC_Settings_Page has loaded.
+ * WooCommerce > Settings > AI tools. It opens on the Overview, a React view with the AI shopping card and the
+ * Sales readiness card (settings-embed mounts it); Manage opens AI shopping, with the UCP switch, what AI assistants can see, Status, the store
+ * policy fields and the store address. The UCP switch saves on its own through
+ * wc/v3/agent-readiness/ucp; the store policy fields save with Save changes. Only created by
+ * AgenticCommerceSettings while the agent_readiness feature is enabled, after WC_Settings_Page has loaded.
*
* @since 11.4.0
*/
class AgenticCommerceSettingsPage extends \WC_Settings_Page {
- use ScriptDebug;
-
- private const SCRIPT_HANDLE = 'wc-agentic-commerce-settings';
+ use ReadinessMarkup;
private const POLICIES_SECTION = 'agentic_commerce_policies';
- /**
- * Example products per product check, to keep the page short. The count column has the total.
- */
- private const EXAMPLES_SHOWN = 3;
-
/**
* Marks the page dropdowns on this tab, which share options with other tabs.
*/
private const PAGE_FIELD_KEY = 'agentic_commerce_page';
- /**
- * Checks that can only run when the check they name passed, so aren't shown when it failed.
- */
- private const CHECK_NEEDS = array(
- 'product_jsonld_from_core' => 'product_jsonld_present',
- 'product_jsonld_required_fields' => 'product_jsonld_present',
- 'product_offer_jsonld' => 'product_jsonld_present',
- 'llms_txt_valid' => 'llms_txt_present',
- 'llms_txt_links_resolve' => 'llms_txt_present',
- );
-
/**
* Store conditions.
*
@@ -61,50 +42,69 @@ class AgenticCommerceSettingsPage extends \WC_Settings_Page {
private AgentReadiness $agent_readiness;
/**
- * UCP switch.
+ * Sales readiness, linked from Status.
*
- * @var UcpSwitch
+ * @var ReadinessCheckPage
*/
- private UcpSwitch $ucp_switch;
-
- /**
- * Background scan.
- *
- * @var ScheduledScan
- */
- private ScheduledScan $scheduled_scan;
+ private ReadinessCheckPage $readiness_page;
/**
* Constructor.
*
- * @param StoreConditions $store_conditions Store conditions.
- * @param AgentReadiness $agent_readiness Readiness service.
- * @param UcpSwitch $ucp_switch UCP switch.
- * @param ScheduledScan $scheduled_scan Background scan.
+ * @param StoreConditions $store_conditions Store conditions.
+ * @param AgentReadiness $agent_readiness Readiness service.
+ * @param ReadinessCheckPage $readiness_page Sales readiness.
*/
- public function __construct( StoreConditions $store_conditions, AgentReadiness $agent_readiness, UcpSwitch $ucp_switch, ScheduledScan $scheduled_scan ) {
+ public function __construct( StoreConditions $store_conditions, AgentReadiness $agent_readiness, ReadinessCheckPage $readiness_page ) {
$this->id = AgenticCommerceSettings::TAB;
- $this->label = __( 'Agentic commerce', 'woocommerce' );
+ $this->label = __( 'AI tools', 'woocommerce' );
$this->store_conditions = $store_conditions;
$this->agent_readiness = $agent_readiness;
- $this->ucp_switch = $ucp_switch;
- $this->scheduled_scan = $scheduled_scan;
+ $this->readiness_page = $readiness_page;
parent::__construct();
add_filter( 'woocommerce_admin_settings_sanitize_option', array( $this, 'sanitize_page_option' ), 10, 3 );
- add_action( 'woocommerce_settings_' . self::POLICIES_SECTION . '_after', array( $this, 'render_policies_footnote' ) );
}
/**
- * The store policy fields. The privacy policy page is a WordPress setting, so it is
- * listed, and saved, only for users who can manage privacy options.
+ * The Overview and AI shopping.
+ *
+ * @return array<string, string>
+ */
+ protected function get_own_sections() {
+ return array(
+ '' => __( 'Overview', 'woocommerce' ),
+ AgenticCommerceSettings::SHOPPING_SECTION => __( 'AI shopping', 'woocommerce' ),
+ );
+ }
+
+ /**
+ * No section links: the landing page's cards and AI shopping's breadcrumb replace them.
+ *
+ * @return void
+ */
+ public function output_sections() {
+ }
+
+ /**
+ * The landing page has no fields.
*
* @return array<int, array<string, mixed>>
*/
protected function get_settings_for_default_section() {
+ return array();
+ }
+
+ /**
+ * The store policy fields, on AI shopping. The privacy policy page is a WordPress setting, so it is
+ * listed, and saved, only for users who can manage privacy options.
+ *
+ * @return array<int, array<string, mixed>>
+ */
+ protected function get_settings_for_shopping_section() {
$store_pages = StoreConditions::store_page_ids();
- $pages = array( '' => __( 'Select a page…', 'woocommerce' ) );
+ $pages = array( '' => __( 'Choose a page', 'woocommerce' ) );
$published = get_pages(
array(
'post_status' => 'publish',
@@ -141,11 +141,11 @@ class AgenticCommerceSettingsPage extends \WC_Settings_Page {
array(
'title' => __( 'Store policies', 'woocommerce' ),
'type' => 'title',
- 'desc' => __( 'Choose the pages AI agents will link shoppers to before they buy, so they know your return, shipping and privacy terms up front.', 'woocommerce' ),
+ 'desc' => __( 'AI assistants share these pages with shoppers. The pages you choose here are also used across the rest of your store.', 'woocommerce' ),
'id' => self::POLICIES_SECTION,
),
$page_field( AgenticCommerceSettings::REFUND_RETURNS_PAGE_OPTION, __( 'Refund and returns', 'woocommerce' ) ),
- $page_field( AgenticCommerceSettings::SHIPPING_POLICY_PAGE_OPTION, __( 'Shipping policy', 'woocommerce' ) ),
+ $page_field( AgenticCommerceSettings::SHIPPING_POLICY_PAGE_OPTION, __( 'Shipping policy', 'woocommerce' ), __( 'Optional.', 'woocommerce' ) ),
...( current_user_can( 'manage_privacy_options' ) ? array( $page_field( AgenticCommerceSettings::PRIVACY_PAGE_OPTION, __( 'Privacy policy', 'woocommerce' ) ) ) : array() ),
$page_field( AgenticCommerceSettings::TERMS_PAGE_OPTION, __( 'Terms and conditions', 'woocommerce' ) ),
$page_field( AgenticCommerceSettings::FAQ_PAGE_OPTION, __( 'FAQ', 'woocommerce' ), __( 'Optional.', 'woocommerce' ) ),
@@ -158,29 +158,50 @@ class AgenticCommerceSettingsPage extends \WC_Settings_Page {
}
/**
- * Render the page as the design's cards: the switch, what agents can see, Status,
- * the store policy fields, the store address and Security.
+ * Render the current section. The Overview leaves a root for its React view;
+ * AI shopping has the switch, what AI assistants can see, Status, the store policy fields and the
+ * store address.
*/
public function output(): void {
- $report = $this->agent_readiness->get_cached_report();
- $checks = $this->store_conditions->all();
- $failing = $this->store_conditions->failing_required( $checks );
+ global $current_section;
+
+ $report = $this->agent_readiness->get_cached_report();
+ $checks = $this->store_conditions->all();
- $this->enqueue_script( count( $failing ) );
+ $this->enqueue_script();
+ if ( AgenticCommerceSettings::SHOPPING_SECTION !== $current_section ) {
+ // Cards only; nothing here saves with Save changes.
+ $GLOBALS['hide_save_button'] = true;
+ // The Overview is React: the settings-embed script mounts it here. The view comes with the page, so the
+ // cards draw without waiting for wc/v3/agent-readiness/view.
+ printf(
+ '<div class="wc-agentic-commerce"><div id="wc-agent-readiness-overview" class="wc-agent-readiness-overview" data-view="%s"></div></div>',
+ esc_attr( (string) wp_json_encode( $this->readiness_page->view() ) )
+ );
+ return;
+ }
+ // The page header, with the breadcrumb as the page title, in place of the settings tabs: settings-embed
+ // moves the breadcrumb into the WooCommerce header and removes this root, which shows until it does.
+ // Not a nav element: the settings form styles those as its tab bar.
+ printf(
+ '<div id="wc-agentic-commerce-header" class="wc-agentic-commerce-header" data-parent-label="%1$s" data-parent-url="%2$s" data-title="%3$s" data-description="%4$s"><div class="wc-agentic-commerce-breadcrumb" role="navigation" aria-label="%5$s"><a href="%2$s">%1$s</a> <span aria-hidden="true">/</span> <span aria-current="page">%3$s</span></div><p>%4$s</p></div>',
+ esc_attr( $this->label ),
+ esc_url( AgenticCommerceSettings::url() ),
+ esc_attr__( 'AI shopping', 'woocommerce' ),
+ esc_attr__( 'Control how AI assistants shop your store.', 'woocommerce' ),
+ esc_attr__( 'Breadcrumbs', 'woocommerce' )
+ );
echo '<div class="wc-agentic-commerce">';
- echo '<p class="wc-agentic-commerce-intro">' . esc_html__( 'Let AI shopping assistants find your products, build a cart, and send shoppers to your checkout to pay. Uses the Universal Commerce Protocol (UCP).', 'woocommerce' ) . '</p>';
- $this->render_switch( $checks, count( $failing ) );
+ $this->render_switch( $checks );
$this->render_visibility( $report );
- $this->render_status( $checks, $this->ucp_switch->status( $failing ) );
- $this->render_readiness( array_slice( $this->agent_readiness->get_store_checks( $report, $checks ), count( $checks ) ), (bool) ( array_column( $checks, 'ok', 'id' )['launched'] ?? true ), $report );
+ $this->render_status( $checks, $report );
echo '<div class="wc-agentic-commerce-card wc-agentic-commerce-policies">';
parent::output();
echo '</div>';
- $this->render_address_and_test();
- $this->render_security();
+ $this->render_address();
echo '</div>';
}
@@ -210,269 +231,71 @@ class AgenticCommerceSettingsPage extends \WC_Settings_Page {
return null;
}
- /**
- * Footnote under the store policy fields.
- *
- * @internal
- */
- public function render_policies_footnote(): void {
- echo '<p class="description">' . esc_html__( 'Refund and returns, privacy policy and terms and conditions are the pages your store already uses at checkout and in your footer. Changing a page here changes it everywhere in your store.', 'woocommerce' ) . '</p>';
- }
-
/**
* Product counts from the last stored readiness report.
*
* @param array<string, mixed>|null $report Stored report, or null before the first scan.
*/
private function render_visibility( ?array $report ): void {
- echo '<div class="wc-agentic-commerce-card">';
- echo '<div class="wc-agentic-commerce-card__header"><h2>' . esc_html__( 'What agents can see', 'woocommerce' ) . '</h2>';
- echo '<p>' . esc_html__( 'Agents see the same products shoppers see in your shop. To keep a product away from agents, set its catalog visibility to Hidden.', 'woocommerce' ) . '</p></div>';
+ echo '<div class="wc-agentic-commerce-card" id="wc-agentic-commerce-visibility">';
+ echo '<div class="wc-agentic-commerce-card__header"><h2>' . esc_html__( 'Product visibility', 'woocommerce' ) . '</h2>';
+ echo '<p>' . esc_html__( 'AI assistants see the same products as shoppers. Shoppers can buy simple and variable products through them.', 'woocommerce' ) . '</p></div>';
if ( null === $report ) {
- echo '<p class="wc-agentic-commerce-card__body">' . esc_html__( 'Product counts appear after the first agent readiness check.', 'woocommerce' ) . '</p></div>';
+ echo '<p class="wc-agentic-commerce-card__body">' . esc_html__( 'Product counts show after the first Sales readiness check.', 'woocommerce' ) . '</p></div>';
return;
}
- $list_url = static fn( array $args ): string => add_query_arg(
- array_merge(
- array(
- 'post_type' => 'product',
- 'post_status' => 'publish',
- ),
- $args
- ),
- admin_url( 'edit.php' )
- );
- $supported = ProductType::SIMPLE . ',' . ProductType::VARIABLE;
- // The products list can't filter out hidden products, so the available count has no list to link to.
$cards = array(
- array(
- 'count' => (int) ( $report['products'] ?? 0 ),
- 'label' => __( 'Available to agents', 'woocommerce' ),
- 'url' => '',
- ),
- array(
- 'count' => (int) ( $report['hidden_from_catalog'] ?? 0 ),
- 'label' => __( 'Hidden from your catalog', 'woocommerce' ),
- 'url' => $list_url(
- array(
- 'product_type' => $supported,
- 'product_visibility' => 'exclude-from-catalog',
- )
- ),
- ),
- array(
- 'count' => (int) ( $report['unsupported_types'] ?? 0 ),
- 'label' => __( 'Not supported yet', 'woocommerce' ),
- 'url' => $list_url( array( 'product_type' => implode( ',', $this->unsupported_product_types() ) ) ),
- ),
+ // The whole catalog, like the other two; `products` stops at PRODUCT_LIMIT. Reports from before `available` have only `products`.
+ array( __( 'Available to AI assistants', 'woocommerce' ), (int) ( $report['available'] ?? $report['products'] ?? 0 ), '', ProductScan::COUNT_AVAILABLE ),
+ array( __( 'Hidden from your catalog', 'woocommerce' ), (int) ( $report['hidden_from_catalog'] ?? 0 ), __( 'Products set to Hidden in Catalog visibility.', 'woocommerce' ), ProductScan::COUNT_HIDDEN ),
+ array( __( 'Product type not supported yet', 'woocommerce' ), (int) ( $report['unsupported_types'] ?? 0 ), __( 'AI assistants can find these products, but shoppers can\'t buy them through an assistant yet. This includes grouped, external, subscription, booking and bundle products.', 'woocommerce' ), ProductScan::COUNT_UNSUPPORTED ),
);
echo '<ul class="wc-agentic-commerce-counts">';
foreach ( $cards as $card ) {
printf(
- '<li><span>%1$s</span> <strong>%2$s</strong>%3$s</li>',
- esc_html( $card['label'] ),
- esc_html( number_format_i18n( $card['count'] ) ),
- '' === $card['url'] ? '' : ' <a href="' . esc_url( $card['url'] ) . '">' . esc_html__( 'View products', 'woocommerce' ) . '</a>'
+ '<li><span>%1$s%2$s</span> <strong>%3$s</strong> <a href="%4$s">%5$s</a></li>',
+ esc_html( $card[0] ),
+ '' === $card[2] ? '' : ' ' . wc_help_tip( $card[2] ),
+ esc_html( number_format_i18n( $card[1] ) ),
+ esc_url( ProductsList::url( $card[3] ) ),
+ esc_html__( 'View products', 'woocommerce' )
);
}
echo '</ul>';
- echo '<p class="wc-agentic-commerce-card__footer">' . esc_html__( 'Simple and variable products only, for now.', 'woocommerce' ) . '</p>';
echo '</div>';
}
- /**
- * "Run check" queues the background scan through wc/v3/agent-readiness/scan. While a scan
- * waits the button is disabled. When Action Scheduler looks stalled, the page says so;
- * the scan never runs in the request (WOOAI-1661).
- *
- * @param array<string, mixed>|null $report Stored report, or null before the first scan.
- */
- private function render_run( ?array $report ): void {
- $pending = $this->scheduled_scan->is_pending();
- $stalled = $pending && $this->scheduled_scan->is_stalled();
- $message = '';
- if ( $stalled ) {
- $message = __( 'The check has not started because scheduled actions do not seem to be running on this site. It runs once they do. See WooCommerce > Status > Scheduled Actions.', 'woocommerce' );
- } elseif ( $pending ) {
- $message = __( 'Checking your store in the background. Reload this page in a minute to see the result.', 'woocommerce' );
- } elseif ( null !== $report && ! empty( $report['generated_at'] ) ) {
- /* translators: %s: how long ago the check ran, e.g. "5 mins". */
- $message = sprintf( __( 'Last checked %s ago.', 'woocommerce' ), human_time_diff( (int) strtotime( (string) $report['generated_at'] ) ) );
- }
- ?>
- <p>
- <button type="button" class="button wc-agentic-commerce-run" <?php disabled( $pending ); ?>><?php esc_html_e( 'Run check', 'woocommerce' ); ?></button>
- <span class="description wc-agentic-commerce-run-message" role="status"><?php echo esc_html( $message ); ?></span>
- </p>
- <?php
- }
-
- /**
- * Per-channel product counts and each failing product check with example products.
- *
- * @param array<string, mixed> $report Stored report.
- */
- private function render_product_checks( array $report ): void {
- $channels = array_filter( is_array( $report['channels'] ?? null ) ? $report['channels'] : array(), 'is_array' );
- $channels = array_map(
- static fn( array $channel ): array => $channel + array_fill_keys( array( 'url', 'name', 'spec', 'listable', 'not_listable', 'with_gaps', 'complete' ), '' ),
- $channels
- );
- $failing = array_filter(
- is_array( $report['checks'] ?? null ) ? $report['checks'] : array(),
- static fn( $check ): bool => is_array( $check ) && (int) ( $check['count'] ?? 0 ) > 0
- );
-
- echo '<div class="wc-agentic-commerce-card__section"><h3>' . esc_html__( 'Product checks', 'woocommerce' ) . '</h3>';
- echo '<p>' . esc_html__( 'Checks your products against the product data specs of AI shopping channels, so agents such as ChatGPT, Google and Copilot can list and recommend them.', 'woocommerce' ) . '</p>';
- if ( ! empty( $report['truncated'] ) ) {
- /* translators: %d: number of products checked. */
- echo '<div class="notice notice-info inline"><p>' . esc_html( sprintf( __( 'Only the %d most recently updated products were checked.', 'woocommerce' ), ProductScan::PRODUCT_LIMIT ) ) . '</p></div>';
- }
- ?>
- <table class="widefat striped wc-agentic-commerce-channels">
- <thead>
- <tr>
- <th><?php esc_html_e( 'Channel', 'woocommerce' ); ?></th>
- <th><?php esc_html_e( 'Can be listed', 'woocommerce' ); ?></th>
- <th><?php esc_html_e( 'Missing a required field', 'woocommerce' ); ?></th>
- <th><?php esc_html_e( 'Listed with gaps', 'woocommerce' ); ?></th>
- <th><?php esc_html_e( 'Complete', 'woocommerce' ); ?></th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ( $channels as $channel_id => $channel ) : ?>
- <tr>
- <td><a href="<?php echo esc_url( (string) $channel['url'] ); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html( (string) $channel['name'] ); ?></a><br /><span class="description"><?php echo esc_html( (string) $channel['spec'] ); ?></span></td>
- <td><?php echo esc_html( number_format_i18n( (int) $channel['listable'] ) ); ?></td>
- <td><?php echo wp_kses_post( self::count_link( (int) $channel['not_listable'], ProductFailures::channel_value( ProductScan::NOT_LISTABLE, (string) $channel_id ), ! empty( $report['failures_stored'] ) ) ); ?></td>
- <td><?php echo esc_html( number_format_i18n( (int) $channel['with_gaps'] ) ); ?></td>
- <td><?php echo esc_html( number_format_i18n( (int) $channel['complete'] ) ); ?></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php
- if ( empty( $failing ) ) {
- echo '<p>' . esc_html__( 'Every product passed every check.', 'woocommerce' ) . '</p></div>';
- return;
- }
- ?>
- <table class="widefat striped wc-agentic-commerce-product-checks">
- <thead>
- <tr>
- <th><?php esc_html_e( 'Problem', 'woocommerce' ); ?></th>
- <th><?php esc_html_e( 'Channels', 'woocommerce' ); ?></th>
- <th><?php esc_html_e( 'Products', 'woocommerce' ); ?></th>
- <th><?php esc_html_e( 'Examples', 'woocommerce' ); ?></th>
- </tr>
- </thead>
- <tbody>
- <?php foreach ( $failing as $check ) : ?>
- <tr>
- <td>
- <strong><?php echo esc_html( (string) $check['label'] ); ?></strong>
- <p><?php echo esc_html( (string) $check['why'] ); ?></p>
- <p><a href="<?php echo esc_url( (string) $check['fix_url'] ); ?>"><?php echo esc_html( (string) $check['fix'] ); ?></a></p>
- </td>
- <td><?php echo empty( $check['channels'] ) ? esc_html__( 'Product page only', 'woocommerce' ) : wp_kses_post( implode( '<br />', $this->channel_tags( (array) $check['channels'], $channels ) ) ); ?></td>
- <td><?php echo wp_kses_post( self::count_link( (int) $check['count'], (string) ( $check['id'] ?? '' ), ! empty( $report['failures_stored'] ) ) ); ?></td>
- <td><?php echo wp_kses_post( implode( '<br />', $this->product_links( (array) ( $check['product_ids'] ?? array() ) ) ) ); ?></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- </div>
- <?php
- }
-
- /**
- * A count, linked to the Products list filtered to those products when each product's failures are stored.
- *
- * @param int $count Number of products.
- * @param string $value Stored failure value.
- * @param bool $linked Whether the list can be filtered.
- * @return string Escaped HTML.
- */
- private static function count_link( int $count, string $value, bool $linked ): string {
- $text = esc_html( number_format_i18n( $count ) );
- return $linked && $count > 0 ? '<a href="' . esc_url( ProductsList::url( $value ) ) . '">' . $text . '</a>' : $text;
- }
-
- /**
- * "Required by X" or "Harder to find on X" per channel.
- *
- * @param array $check_channels Field and effect by channel id.
- * @param array $channels Channels from the report.
- * @return array<int, string> Escaped HTML.
- */
- private function channel_tags( array $check_channels, array $channels ): array {
- $tags = array();
- foreach ( $check_channels as $channel_id => $spec ) {
- $name = (string) ( $channels[ $channel_id ]['name'] ?? $channel_id );
- if ( ReadinessRule::EFFECT_NOT_LISTABLE === ( $spec['effect'] ?? '' ) ) {
- /* translators: %s: channel name, e.g. ChatGPT. */
- $tags[] = '<mark class="wc-agentic-commerce-badge wc-agentic-commerce-badge--fix">' . esc_html( sprintf( __( 'Required by %s', 'woocommerce' ), $name ) ) . '</mark>';
- } else {
- /* translators: %s: channel name, e.g. ChatGPT. */
- $tags[] = esc_html( sprintf( __( 'Harder to find on %s', 'woocommerce' ), $name ) );
- }
- }
- return $tags;
- }
-
- /**
- * Edit links for the example products that still exist.
- *
- * @param array $product_ids Product ids.
- * @return array<int, string> Escaped HTML.
- */
- private function product_links( array $product_ids ): array {
- $links = array();
- foreach ( $product_ids as $product_id ) {
- $url = get_edit_post_link( (int) $product_id, 'raw' );
- if ( ! $url ) {
- continue;
- }
- $links[] = '<a href="' . esc_url( $url ) . '">' . esc_html( get_the_title( (int) $product_id ) ) . '</a>';
- if ( self::EXAMPLES_SHOWN === count( $links ) ) {
- break;
- }
- }
- return $links;
- }
-
/**
* The UCP switch card. The switch saves right away, apart from Save changes. While the
* store is in coming soon mode, the card says so: agents can't shop a store that isn't live.
*
- * @param array<int, array{id:string,ok:bool,fix_url:string}> $checks Store conditions.
- * @param int $failing_required Number of failing required setup checks.
+ * @param array<int, array{id:string,ok:bool,blocks:string,group:string,level:string,name:string,label:string,why:string,fix:string,fix_url:string}> $checks Store conditions.
*/
- private function render_switch( array $checks, int $failing_required ): void {
+ private function render_switch( array $checks ): void {
$enabled = UcpUtils::is_enabled();
- $message = $enabled ? self::on_message( $failing_required ) : '';
+ $failing = $this->store_conditions->failing_required( $checks );
+ $blocked = ! $enabled && array() !== $failing;
$launched = current( array_filter( $checks, static fn( array $check ): bool => 'launched' === $check['id'] ) );
?>
<div class="wc-agentic-commerce-card wc-agentic-commerce-switch-card">
<div class="wc-agentic-commerce-switch-row">
- <button type="button" class="wc-agentic-commerce-ucp-switch button-link" role="switch" aria-checked="<?php echo $enabled ? 'true' : 'false'; ?>" aria-labelledby="wc-agentic-commerce-ucp-title" aria-describedby="wc-agentic-commerce-ucp-desc" <?php disabled( ! $enabled && $failing_required > 0 ); ?>>
+ <button type="button" class="wc-agentic-commerce-ucp-switch button-link" role="switch" aria-checked="<?php echo $enabled ? 'true' : 'false'; ?>" aria-labelledby="wc-agentic-commerce-ucp-title" aria-describedby="wc-agentic-commerce-ucp-desc" <?php disabled( $blocked ); ?>>
<span class="woocommerce-input-toggle woocommerce-input-toggle--<?php echo $enabled ? 'enabled' : 'disabled'; ?>"><?php echo $enabled ? esc_html__( 'Yes', 'woocommerce' ) : esc_html__( 'No', 'woocommerce' ); ?></span>
</button>
<div>
- <h2 id="wc-agentic-commerce-ucp-title"><?php esc_html_e( 'Let AI agents shop your store', 'woocommerce' ); ?></h2>
- <p id="wc-agentic-commerce-ucp-desc"><?php esc_html_e( 'AI shopping assistants find your products and build a cart. Shoppers pay on your checkout, so you keep the order and the customer. Turn it off at any time to stop all agent access.', 'woocommerce' ); ?></p>
- <p class="wc-agentic-commerce-ucp-message" role="status"><?php echo esc_html( $message ); ?></p>
+ <h2 id="wc-agentic-commerce-ucp-title"><?php esc_html_e( 'Allow AI assistants to shop your store', 'woocommerce' ); ?></h2>
+ <p id="wc-agentic-commerce-ucp-desc"><?php esc_html_e( 'Your products can be found by AI assistants and added to a shopper’s cart. Orders come through your checkout as usual.', 'woocommerce' ); ?></p>
+ <p class="wc-agentic-commerce-ucp-message" role="status"><?php echo ( $enabled && array() === $failing ) ? esc_html__( 'AI shopping is on. AI assistants can now find and shop your store.', 'woocommerce' ) : ''; ?></p>
</div>
</div>
<?php if ( $launched && ! $launched['ok'] ) : ?>
<div class="wc-agentic-commerce-notice">
<span class="dashicons dashicons-warning" aria-hidden="true"></span>
- <p><?php esc_html_e( 'Your store is in coming soon mode, so agents can\'t shop it yet. Take it live to let them in.', 'woocommerce' ); ?></p>
- <a class="button button-primary" href="<?php echo esc_url( $launched['fix_url'] ); ?>"><?php esc_html_e( 'Go to Site visibility', 'woocommerce' ); ?></a>
+ <p><?php esc_html_e( 'Your store is in coming soon mode, so AI assistants can’t shop it yet. Make your store live to let them in.', 'woocommerce' ); ?></p>
+ <a class="button button-primary" href="<?php echo esc_url( $launched['fix_url'] ); ?>"><?php esc_html_e( 'Change site visibility', 'woocommerce' ); ?></a>
</div>
<?php endif; ?>
</div>
@@ -480,477 +303,108 @@ class AgenticCommerceSettingsPage extends \WC_Settings_Page {
}
/**
- * What the switch says while UCP is on.
+ * The Setup checklist: how many steps are left, then the open setup checks in one list, required ones first and
+ * marked Required. Each says why it matters, with a Review button to where to fix it. Completed checks fold
+ * behind "Show N completed steps". UCP itself is the switch, so it is not listed.
*
- * @param int $failing_required Number of failing required setup checks.
- */
- private static function on_message( int $failing_required ): string {
- if ( $failing_required > 0 ) {
- /* translators: %d: number of failing required setup checks. */
- return sprintf( _n( 'AI agents can shop your store, but %d required setup check below still needs fixing.', 'AI agents can shop your store, but %d required setup checks below still need fixing.', $failing_required, 'woocommerce' ), $failing_required );
- }
- return __( 'AI agents can now find and shop your store.', 'woocommerce' );
- }
-
- /**
- * The Status card: a badge, then the setup checks grouped into Required, Recommended and Done.
- * Each open check says what to do and links to where to do it. UCP itself is the switch, so it is not listed.
- *
- * @param array<int, array{id:string,level:string,ok:bool,name:string,label:string,fix_url:string}> $checks Store conditions.
- * @param string $status UcpSwitch status.
- */
- private function render_status( array $checks, string $status ): void {
- $statuses = self::status_labels();
- $classes = array(
- UcpSwitch::STATUS_ACTIVE => 'pass',
- UcpSwitch::STATUS_OFF => 'off',
- UcpSwitch::STATUS_NEEDS_ATTENTION => 'fix',
- );
- $groups = array(
- 'required' => array( __( 'Required', 'woocommerce' ), array() ),
- 'recommended' => array( __( 'Recommended', 'woocommerce' ), array() ),
- 'done' => array( __( 'Done', 'woocommerce' ), array() ),
- );
- foreach ( $checks as $check ) {
- if ( 'ucp_on' === $check['id'] ) {
- continue;
- }
- $group = $check['ok'] ? 'done' : ( StoreConditions::shows_required( $check ) ? 'required' : 'recommended' );
- $groups[ $group ][1][] = $check;
+ * @param array<int, array{id:string,ok:bool,blocks:string,level:string,name:string,label:string,why:string,fix:string,fix_url:string}> $checks Store conditions.
+ * @param array<string, mixed>|null $report Stored report, or null before the first scan.
+ */
+ private function render_status( array $checks, ?array $report ): void {
+ $done = array_filter( $checks, static fn( array $check ): bool => 'ucp_on' !== $check['id'] && $check['ok'] );
+ $open = ReadinessCheckPage::open_steps( $checks );
+ $required = count( array_filter( $open, array( StoreConditions::class, 'shows_required' ) ) );
+ if ( $required > 0 ) {
+ /* translators: %d: number of failing required setup steps. */
+ $summary = sprintf( _n( 'Finish %d required step to get your store ready for AI shopping.', 'Finish %d required steps to get your store ready for AI shopping.', $required, 'woocommerce' ), $required );
+ } elseif ( array() !== $open ) {
+ /* translators: %d: number of open setup steps. */
+ $summary = sprintf( _n( 'Your store is ready for AI shopping. You have %d optional step left.', 'Your store is ready for AI shopping. You have %d optional steps left.', count( $open ), 'woocommerce' ), count( $open ) );
+ } elseif ( UcpUtils::is_enabled() ) {
+ $summary = __( 'Your store is ready for AI shopping.', 'woocommerce' );
+ } else {
+ $summary = __( 'Your store is ready for AI shopping. Turn it on to let AI assistants find your products.', 'woocommerce' );
}
- // The summary follows the Required rows on this card. $failing_required is the smaller set that blocks the switch.
- $shown_failing = count( $groups['required'][1] );
- $summary = $shown_failing > 0
- /* translators: %d: number of failing checks shown as Required. */
- ? sprintf( _n( '%d required step to finish so agents can shop your store.', '%d required steps to finish so agents can shop your store.', $shown_failing, 'woocommerce' ), $shown_failing )
- : __( 'Everything agents need is set up.', 'woocommerce' );
?>
- <div class="wc-agentic-commerce-card wc-agentic-commerce-status-card">
- <div class="wc-agentic-commerce-card__header wc-agentic-commerce-card__header--split">
- <div>
- <h2><?php esc_html_e( 'Status', 'woocommerce' ); ?></h2>
- <p><?php echo esc_html( $summary ); ?></p>
+ <div class="wc-agentic-commerce-card wc-agentic-commerce-status-card" id="wc-agentic-commerce-status">
+ <div class="wc-agentic-commerce-card__header">
+ <div class="wc-agentic-commerce-card__title">
+ <h2><?php esc_html_e( 'Setup checklist', 'woocommerce' ); ?></h2>
+ <?php if ( array() !== $open ) : ?>
+ <mark class="wc-agentic-commerce-badge wc-agentic-commerce-badge--info">
+ <?php
+ /* translators: %d: number of setup steps left. */
+ echo esc_html( sprintf( _n( '%d step left', '%d steps left', count( $open ), 'woocommerce' ), count( $open ) ) );
+ ?>
+ </mark>
+ <?php endif; ?>
</div>
- <mark class="wc-agentic-commerce-badge wc-agentic-commerce-badge--<?php echo esc_attr( $classes[ $status ] ); ?> wc-agentic-commerce-status"><?php echo esc_html( $statuses[ $status ] ); ?></mark>
+ <p><?php echo esc_html( $summary ); ?></p>
</div>
- <?php foreach ( $groups as $id => $group ) : ?>
- <?php
- if ( array() === $group[1] ) {
- continue;
- }
- $heading = sprintf( '%1$s <span class="wc-agentic-commerce-count">%2$s</span>', esc_html( $group[0] ), esc_html( number_format_i18n( count( $group[1] ) ) ) );
- ?>
- <?php if ( 'done' === $id ) : ?>
- <details class="wc-agentic-commerce-group wc-agentic-commerce-group--done">
- <summary class="wc-agentic-commerce-group__title"><?php echo wp_kses_post( $heading ); ?></summary>
- <ul>
- <?php foreach ( $group[1] as $check ) : ?>
- <li class="wc-agentic-commerce-check wc-agentic-commerce-check--done"><span class="dashicons dashicons-yes-alt" aria-hidden="true"></span><span><?php echo esc_html( $check['name'] ); ?></span></li>
- <?php endforeach; ?>
- </ul>
- </details>
- <?php else : ?>
- <div class="wc-agentic-commerce-group wc-agentic-commerce-group--<?php echo esc_attr( $id ); ?>">
- <h3 class="wc-agentic-commerce-group__title"><?php echo wp_kses_post( $heading ); ?></h3>
- <ul>
- <?php foreach ( $group[1] as $check ) : ?>
- <?php $action = $this->check_action( $check ); ?>
- <li class="wc-agentic-commerce-check wc-agentic-commerce-check--<?php echo esc_attr( $id ); ?>">
- <span class="wc-agentic-commerce-check__icon" aria-hidden="true"></span>
- <span class="wc-agentic-commerce-check__text"><?php echo esc_html( $action[0] ); ?></span>
- <?php if ( '' !== $action[2] ) : ?>
- <a class="button" href="<?php echo esc_url( $action[2] ); ?>"><?php echo esc_html( $action[1] ); ?></a>
- <?php endif; ?>
- </li>
- <?php endforeach; ?>
- </ul>
- </div>
- <?php endif; ?>
- <?php endforeach; ?>
- </div>
- <?php
- }
-
- /**
- * Protocols and files the store declares to agents, as information: found or not found, never pass or fail.
- *
- * @param array $items Items from the report.
- */
- private function render_declared( array $items ): void {
- $items = array_filter( $items, 'is_array' );
- if ( array() === $items ) {
- return;
- }
- $found = count( array_filter( $items, static fn( array $item ): bool => true === ( $item['found'] ?? null ) ) );
- $unknown = count( array_filter( $items, static fn( array $item ): bool => null === ( $item['found'] ?? null ) ) );
- if ( count( $items ) === $unknown ) {
- $summary = __( 'Not checked', 'woocommerce' );
- } elseif ( $unknown > 0 ) {
- /* translators: 1: number found, 2: number looked for, 3: number that could not be checked. */
- $summary = sprintf( __( '%1$d of %2$d found, %3$d not checked', 'woocommerce' ), $found, count( $items ), $unknown );
- } else {
- /* translators: 1: number found, 2: number looked for. */
- $summary = sprintf( __( '%1$d of %2$d found', 'woocommerce' ), $found, count( $items ) );
- }
- echo '<div class="wc-agentic-commerce-card__section wc-agentic-commerce-declared-section"><h3>' . esc_html__( 'What this store declares to agents', 'woocommerce' ) . '</h3>';
- echo '<p>' . esc_html__( 'For information. Most stores don\'t need these, and none of them counts as a problem.', 'woocommerce' ) . '</p>';
- echo '<details><summary>' . esc_html( $summary ) . '</summary><table class="widefat striped wc-agentic-commerce-declared"><tbody>';
- foreach ( $items as $item ) {
- $state = null !== ( $item['found'] ?? null ) ? ( $item['found'] ? __( 'Found', 'woocommerce' ) : __( 'Not found', 'woocommerce' ) ) : __( 'Not checked', 'woocommerce' );
- echo '<tr><td>' . esc_html( (string) ( $item['name'] ?? '' ) ) . '</td><td>' . esc_html( $state ) . '</td></tr>';
- }
- echo '</tbody></table></details></div>';
- }
-
- /**
- * One line on where a question stands.
- *
- * @param string $group Question id.
- * @param array<int, array{id:string,ok:bool|null,level:string,pending?:bool}> $checks The question's checks. Pending ones don't count as unchecked.
- * @param bool $scanned Whether a scan has run.
- * @param int $product_problems Failing product checks under the question.
- * @param bool $ucp_scanned Whether the last scan checked UCP.
- * @param bool $ucp_enabled Whether UCP is on.
- */
- private static function group_summary( string $group, array $checks, bool $scanned, int $product_problems, bool $ucp_scanned, bool $ucp_enabled ): string {
- $fix = count( array_filter( $checks, static fn( array $check ): bool => false === $check['ok'] && StoreConditions::shows_required( $check ) ) );
- $check = $product_problems + count( array_filter( $checks, static fn( array $check ): bool => false === $check['ok'] && ! StoreConditions::shows_required( $check ) ) );
- $unknown = count( array_filter( $checks, static fn( array $check ): bool => null === $check['ok'] && empty( $check['pending'] ) ) );
- $parts = array();
- if ( $fix > 0 ) {
- /* translators: %d: number of checks. */
- $parts[] = sprintf( _n( '%d to fix', '%d to fix', $fix, 'woocommerce' ), $fix );
- }
- if ( $check > 0 ) {
- /* translators: %d: number of checks. */
- $parts[] = sprintf( _n( '%d to check', '%d to check', $check, 'woocommerce' ), $check );
- }
- if ( $unknown > 0 ) {
- /* translators: %d: number of checks. */
- $parts[] = sprintf( _n( '%d couldn\'t be checked', '%d couldn\'t be checked', $unknown, 'woocommerce' ), $unknown );
- }
- if ( 'access' === $group && ! $ucp_enabled ) {
- array_unshift( $parts, __( 'Agent shopping is off', 'woocommerce' ) );
- }
- if ( array() !== $parts ) {
- return implode( ', ', $parts );
- }
- $ran = array_filter( $checks, static fn( array $check ): bool => empty( $check['pending'] ) );
- if ( array() === $ran && array() !== $checks ) {
- return __( 'Coming soon', 'woocommerce' );
- }
- // Rows from before UCP was turned on, or a report without store checks, don't answer the question.
- $answered = $scanned && array() !== $ran && ( 'access' !== $group || $ucp_scanned );
- return $answered ? __( 'Yes', 'woocommerce' ) : __( 'Run check to find out', 'woocommerce' );
- }
-
- /**
- * A table of store checks.
- *
- * @param array<int, array{id:string,ok:bool|null,blocks:string,level:string,name:string,why:string,fix:string,fix_url:string,conflict?:bool,pending?:bool,seen_at?:string}> $checks Checks.
- * @param bool|null $launched Whether the store is launched.
- */
- private function render_check_rows( array $checks, ?bool $launched ): void {
- if ( array() === $checks ) {
- return;
- }
- ?>
- <table class="widefat striped wc-agentic-commerce-checks">
- <tbody>
- <?php foreach ( $checks as $check ) : ?>
- <?php
- $conflict = ! empty( $check['conflict'] );
- if ( ! empty( $check['pending'] ) ) {
- $badge = array( 'off', __( 'Coming soon', 'woocommerce' ) );
- } elseif ( null === $check['ok'] ) {
- $badge = array( 'check', __( 'Couldn\'t check', 'woocommerce' ) );
- } elseif ( $check['ok'] ) {
- $badge = array( 'pass', __( 'Pass', 'woocommerce' ) );
- } elseif ( $conflict ) {
- $badge = array( 'check', __( 'Likely conflict', 'woocommerce' ) );
- } elseif ( StoreConditions::shows_required( $check ) ) {
- $badge = array( 'fix', __( 'Fix', 'woocommerce' ) );
- } else {
- $badge = array( 'check', __( 'Check', 'woocommerce' ) );
+ <?php
+ if ( array() !== $open ) {
+ echo '<ul class="wc-agentic-commerce-items">';
+ foreach ( $open as $check ) {
+ $action = self::check_action( $check );
+ $required = StoreConditions::shows_required( $check );
+ $lines = array( esc_html( $action[1] ) );
+ if ( '' !== $action[4] ) {
+ $lines[] = esc_html( $action[4] );
}
- ?>
- <tr>
- <td><mark class="wc-agentic-commerce-badge wc-agentic-commerce-badge--<?php echo esc_attr( $badge[0] ); ?>"><?php echo esc_html( $badge[1] ); ?></mark></td>
- <td>
- <?php echo esc_html( $check['name'] ); ?>
- <?php if ( false === $check['ok'] ) : ?>
- <br /><span class="description"><?php echo esc_html( trim( ( $conflict ? __( 'Something on your store may be replacing this. If you just changed it, a page cache may show the old page for a while.', 'woocommerce' ) . ' ' : '' ) . $check['why'] . ' ' . self::blocks_text( $check['blocks'] ) ) ); ?></span>
- <?php if ( $conflict && ! empty( $check['seen_at'] ) ) : ?>
- <br /><span class="description"><?php esc_html_e( 'Seen on:', 'woocommerce' ); ?> <a href="<?php echo esc_url( $check['seen_at'] ); ?>"><?php echo esc_html( $check['seen_at'] ); ?></a></span>
- <?php endif; ?>
- <?php endif; ?>
- </td>
- <td>
- <?php if ( ! empty( $check['pending'] ) ) : ?>
- <?php esc_html_e( 'Coming in a WooCommerce update.', 'woocommerce' ); ?>
- <?php elseif ( null === $check['ok'] ) : ?>
- <?php
- if ( $launched ) {
- esc_html_e( 'This couldn\'t be checked. The next check tries again.', 'woocommerce' );
- } else {
- esc_html_e( 'Launch your store to run this check.', 'woocommerce' );
- }
- ?>
- <?php elseif ( ! $check['ok'] && '' === $check['fix_url'] ) : ?>
- <?php echo esc_html( $check['fix'] ); ?>
- <?php elseif ( ! $check['ok'] ) : ?>
- <a href="<?php echo esc_url( $check['fix_url'] ); ?>"><?php echo str_starts_with( $check['fix_url'], admin_url() ) ? esc_html__( 'Open settings', 'woocommerce' ) : esc_html__( 'Learn how', 'woocommerce' ); ?></a>
- <?php endif; ?>
- </td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php
- }
-
- /**
- * What a failing store check stops, from its `blocks` value.
- *
- * @param string $blocks listing, discovery, ucp or checkout.
- */
- private static function blocks_text( string $blocks ): string {
- $texts = array(
- 'listing' => __( 'Affects every product on every channel.', 'woocommerce' ),
- 'discovery' => __( 'Makes your store harder for agents to find and read.', 'woocommerce' ),
- 'ucp' => __( 'Affects agents that use UCP.', 'woocommerce' ),
- 'checkout' => __( 'Affects agent checkout.', 'woocommerce' ),
- );
- return $texts[ $blocks ] ?? '';
- }
-
- /**
- * Agent readiness: the checks the last scan ran on what the store returns, under the
- * merchant question each answers, with a one-line answer per question. They never
- * affect the switch, so they sit apart from the setup checks in Status. Run check is
- * at the top, and the product checks sit under "Do they understand your products?".
- *
- * @param array<int, array{id:string,ok:bool|null,blocks:string,group?:string,level:string,name:string,why:string,fix:string,fix_url:string,conflict?:bool,pending?:bool,seen_at?:string}> $checks Scanned checks.
- * @param bool $launched Whether the store is launched.
- * @param array<string, mixed>|null $report Stored report, or null before the first scan.
- */
- private function render_readiness( array $checks, bool $launched, ?array $report ): void {
- $results = array_column( $checks, 'ok', 'id' );
- $checks = array_filter(
- $checks,
- static function ( array $check ) use ( $results ): bool {
- // With UCP off nothing is served; the switch already says so.
- if ( ! UcpUtils::is_enabled() && 'ucp' === $check['blocks'] ) {
- return false;
+ // Other steps say Review. The connection URL step says Change permalinks, and only when permalinks are one of the fixes.
+ $label = 'ucp_discovery' === $check['id'] && '' !== $action[3] ? $action[3] : __( 'Review', 'woocommerce' );
+ $review = '' === $action[2] ? '' : '<a class="button wc-agentic-commerce-review" href="' . esc_url( $action[2] ) . '">' . esc_html( $label ) . '</a>';
+ self::render_item( $required ? 'required' : 'open', esc_html( $action[0] ) . ( $required ? ' ' . self::required_badge() : '' ), $lines, $review );
}
- $needs = self::CHECK_NEEDS[ $check['id'] ] ?? null;
- return null === $needs || false !== ( $results[ $needs ] ?? null );
+ echo '</ul>';
}
- );
- $groups = array(
- 'access' => array( __( 'Can agents get in?', 'woocommerce' ), array() ),
- 'find' => array( __( 'Can they find your store?', 'woocommerce' ), array() ),
- 'understand' => array( __( 'Do they understand your products?', 'woocommerce' ), array() ),
- 'buy' => array( __( 'Can they buy?', 'woocommerce' ), array() ),
- );
- foreach ( $checks as $check ) {
- // A report from before checks named their question has no group; the next scan fills it in.
- if ( isset( $groups[ $check['group'] ?? '' ] ) ) {
- $groups[ $check['group'] ][1][] = $check;
+ if ( array() !== $done ) {
+ /* translators: %d: number of completed setup steps. */
+ self::open_more( sprintf( _n( 'Show %d completed step', 'Show %d completed steps', count( $done ), 'woocommerce' ), count( $done ) ) );
+ echo '<ul class="wc-agentic-commerce-items">';
+ foreach ( $done as $check ) {
+ self::render_item( 'pass', esc_html( $check['name'] ), array() );
+ }
+ echo '</ul></details>';
}
- }
- $product_problems = 0;
- foreach ( is_array( $report['checks'] ?? null ) ? $report['checks'] : array() as $product_check ) {
- $product_problems += is_array( $product_check ) && (int) ( $product_check['count'] ?? 0 ) > 0 ? 1 : 0;
- }
- ?>
- <div class="wc-agentic-commerce-card wc-agentic-commerce-readiness">
- <div class="wc-agentic-commerce-card__header">
- <h2><?php esc_html_e( 'Agent readiness', 'woocommerce' ); ?></h2>
- <p><?php esc_html_e( 'What agents get when they visit your store, from the last check.', 'woocommerce' ); ?></p>
- <?php $this->render_run( $report ); ?>
- </div>
- <?php if ( null === $report ) : ?>
- <p class="wc-agentic-commerce-card__body"><?php esc_html_e( 'Results appear after the first agent readiness check.', 'woocommerce' ); ?></p>
- <?php else : ?>
- <ul class="wc-agentic-commerce-summary">
- <?php foreach ( $groups as $id => $group ) : ?>
- <li>
- <a href="#wc-agentic-commerce-group-<?php echo esc_attr( $id ); ?>"><?php echo esc_html( $group[0] ); ?></a>
- <?php
- $summary = static fn( bool $ucp_enabled ): string => self::group_summary( $id, $group[1], true, 'understand' === $id ? $product_problems : 0, array_key_exists( 'ucp_profile', $results ), $ucp_enabled );
- if ( 'access' === $id ) {
- // The switch script swaps these, so the line follows the switch without a reload.
- printf( '<span class="wc-agentic-commerce-access-summary" data-on="%1$s" data-off="%2$s">%3$s</span>', esc_attr( $summary( true ) ), esc_attr( $summary( false ) ), esc_html( $summary( UcpUtils::is_enabled() ) ) );
- } else {
- echo esc_html( $summary( UcpUtils::is_enabled() ) );
- }
- ?>
- </li>
- <?php endforeach; ?>
- </ul>
- <?php foreach ( $groups as $id => $group ) : ?>
- <div class="wc-agentic-commerce-card__section" id="wc-agentic-commerce-group-<?php echo esc_attr( $id ); ?>">
- <h3><?php echo esc_html( $group[0] ); ?></h3>
- <?php
- $open = array_filter( $group[1], static fn( array $check ): bool => true !== $check['ok'] );
- $passed = array_filter( $group[1], static fn( array $check ): bool => true === $check['ok'] );
- $this->render_check_rows( $open, $launched );
- if ( array() !== $passed ) {
- /* translators: %d: number of checks that passed. */
- echo '<details><summary>' . esc_html( sprintf( _n( '%d check passed', '%d checks passed', count( $passed ), 'woocommerce' ), count( $passed ) ) ) . '</summary>';
- $this->render_check_rows( $passed, $launched );
- echo '</details>';
- }
- ?>
- </div>
- <?php
- if ( 'understand' === $id ) {
- $this->render_product_checks( $report );
- }
- ?>
- <?php endforeach; ?>
- <?php $this->render_declared( is_array( $report['declared'] ?? null ) ? $report['declared'] : array() ); ?>
- <?php endif; ?>
+ $this->render_readiness_link( $report, $checks );
+ ?>
</div>
<?php
}
/**
- * What an open check asks the merchant to do: the action, the button text and where it goes.
- * A policy page that is chosen but not published links to its editor; a published store page asks for another page.
+ * The last row of Status: a link to Sales readiness with how many issues it found.
*
- * @param array{id:string,label:string,fix?:string,fix_url:string} $check Store condition.
- * @return array{0:string,1:string,2:string}
- */
- private function check_action( array $check ): array {
- // The UCP row's text is the specific fix (delete the file, fix permissions, or change permalinks).
- if ( 'ucp_discovery' === $check['id'] ) {
- $fix = (string) ( $check['fix'] ?? '' );
- return array(
- '' !== $fix ? $fix : __( 'Fix your connection URL', 'woocommerce' ),
- __( 'Change permalinks', 'woocommerce' ),
- (string) ( $check['fix_url'] ?? '' ),
- );
- }
- $policies = array(
- 'privacy_page' => array( AgenticCommerceSettings::PRIVACY_PAGE_OPTION, __( 'Publish your privacy policy page', 'woocommerce' ), __( 'Choose a privacy policy page', 'woocommerce' ) ),
- 'terms_page' => array( AgenticCommerceSettings::TERMS_PAGE_OPTION, __( 'Publish your terms and conditions page', 'woocommerce' ), __( 'Choose a terms and conditions page', 'woocommerce' ) ),
- 'refund_returns_page' => array( AgenticCommerceSettings::REFUND_RETURNS_PAGE_OPTION, __( 'Publish your refund and returns policy page', 'woocommerce' ), __( 'Choose a refund and returns policy page', 'woocommerce' ) ),
- 'shipping_policy_page' => array( AgenticCommerceSettings::SHIPPING_POLICY_PAGE_OPTION, __( 'Publish your shipping policy page', 'woocommerce' ), __( 'Choose a shipping policy page', 'woocommerce' ) ),
- );
- if ( isset( $policies[ $check['id'] ] ) ) {
- $page_id = (int) get_option( $policies[ $check['id'] ][0] );
- $edit = $page_id > 0 && get_post( $page_id ) && 'publish' !== get_post_status( $page_id ) ? (string) get_edit_post_link( $page_id, 'raw' ) : '';
- return '' !== $edit
- ? array( $policies[ $check['id'] ][1], __( 'Review and publish', 'woocommerce' ), $edit )
- : array( $policies[ $check['id'] ][2], __( 'Choose a page', 'woocommerce' ), $check['fix_url'] );
- }
- $actions = array(
- 'launched' => array( __( 'Take your store out of coming soon mode', 'woocommerce' ), __( 'Go to Site visibility', 'woocommerce' ) ),
- 'https' => array( __( 'Move your store to HTTPS', 'woocommerce' ), __( 'Learn how', 'woocommerce' ) ),
- 'search_visible' => array( __( 'Let search engines index your store', 'woocommerce' ), __( 'Open settings', 'woocommerce' ) ),
- 'guest_checkout' => array( __( 'Allow guest checkout', 'woocommerce' ), __( 'Open settings', 'woocommerce' ) ),
- 'order_emails' => array( __( 'Turn on order confirmation emails', 'woocommerce' ), __( 'Open settings', 'woocommerce' ) ),
- 'payment_method' => array( __( 'Turn on a payment method', 'woocommerce' ), __( 'Open settings', 'woocommerce' ) ),
+ * @param array<string, mixed>|null $report Stored report, or null before the first scan.
+ * @param array<int, array{id:string,ok:bool,blocks:string,level:string,name:string,label:string,why:string,fix:string,fix_url:string}> $checks Store conditions.
+ */
+ private function render_readiness_link( ?array $report, array $checks ): void {
+ $badge = $this->readiness_page->badge( $report, $checks );
+ printf(
+ '<ul class="wc-agentic-commerce-results"><li><a href="%1$s">%2$s</a> <mark class="wc-agentic-commerce-badge wc-agentic-commerce-badge--%3$s">%4$s</mark></li></ul>',
+ esc_url( ReadinessCheckPage::url() ),
+ esc_html__( 'Sales readiness', 'woocommerce' ),
+ esc_attr( $badge[0] ),
+ esc_html( $badge[1] )
);
- $action = $actions[ $check['id'] ] ?? array( $check['label'], __( 'Open settings', 'woocommerce' ) );
- return array( $action[0], $action[1], $check['fix_url'] );
}
/**
- * The store address agents start from, and Test your setup (WOOAI-1619, not built yet).
+ * The connection URL AI assistants start from, with a copy button.
*/
- private function render_address_and_test(): void {
+ private function render_address(): void {
?>
- <div class="wc-agentic-commerce-card wc-agentic-commerce-card--split">
- <div>
- <h3><label for="wc-agentic-commerce-ucp-url"><?php esc_html_e( 'Store address for agents', 'woocommerce' ); ?></label></h3>
- <input type="text" id="wc-agentic-commerce-ucp-url" class="regular-text code" readonly value="<?php echo esc_attr( home_url( '/.well-known/ucp' ) ); ?>" />
- <button type="button" class="button wc-agentic-commerce-copy" data-copy-target="wc-agentic-commerce-ucp-url"><?php esc_html_e( 'Copy', 'woocommerce' ); ?></button>
- </div>
- <div class="wc-agentic-commerce-placeholder">
- <h3><?php esc_html_e( 'Test your setup', 'woocommerce' ); ?></h3>
- <p><?php esc_html_e( 'Coming in a WooCommerce update.', 'woocommerce' ); ?></p>
- </div>
- </div>
- <?php
- }
-
- /**
- * Security (WOOAI-1620, not built yet). Keys are set up automatically, so there is nothing to do here today.
- */
- private function render_security(): void {
- ?>
- <div class="wc-agentic-commerce-card wc-agentic-commerce-placeholder">
+ <div class="wc-agentic-commerce-card">
<div class="wc-agentic-commerce-card__header">
- <h2><?php esc_html_e( 'Security', 'woocommerce' ); ?></h2>
- <p><?php esc_html_e( 'Set up automatically. Nothing to do here.', 'woocommerce' ); ?></p>
+ <h2><label for="wc-agentic-commerce-ucp-url"><?php esc_html_e( 'Connection URL', 'woocommerce' ); ?></label></h2>
+ <p><?php esc_html_e( 'A separate address, just for AI assistants to connect to your store. It was created automatically.', 'woocommerce' ); ?></p>
</div>
- <p class="wc-agentic-commerce-card__footer"><?php esc_html_e( 'Signing key details are coming in a WooCommerce update.', 'woocommerce' ); ?></p>
+ <p class="wc-agentic-commerce-card__body wc-agentic-commerce-address">
+ <input type="text" id="wc-agentic-commerce-ucp-url" class="regular-text code" readonly value="<?php echo esc_attr( home_url( '/.well-known/ucp' ) ); ?>" />
+ <button type="button" class="button wc-agentic-commerce-copy" data-copy-target="wc-agentic-commerce-ucp-url"><?php esc_html_e( 'Copy', 'woocommerce' ); ?></button>
+ </p>
</div>
<?php
}
-
- /**
- * Status badge text, by UcpSwitch status.
- *
- * @return array<string, string>
- */
- private static function status_labels(): array {
- return array(
- UcpSwitch::STATUS_ACTIVE => __( 'Active', 'woocommerce' ),
- UcpSwitch::STATUS_OFF => __( 'Off', 'woocommerce' ),
- UcpSwitch::STATUS_NEEDS_ATTENTION => __( 'Action needed', 'woocommerce' ),
- );
- }
-
- /**
- * Product type slugs agents don't support yet, for the product list filter.
- *
- * @return array<int, string>
- */
- private function unsupported_product_types(): array {
- $slugs = get_terms(
- array(
- 'taxonomy' => 'product_type',
- 'hide_empty' => false,
- 'fields' => 'slugs',
- )
- );
- if ( ! is_array( $slugs ) ) {
- return array( ProductType::GROUPED, ProductType::EXTERNAL );
- }
- return array_values( array_diff( array_map( 'strval', $slugs ), array( ProductType::SIMPLE, ProductType::VARIABLE ) ) );
- }
-
- /**
- * Load the script for the switch, Run check and the copy button.
- *
- * @param int $failing_required Number of failing required setup checks, for the message shown after turning UCP on.
- */
- private function enqueue_script( int $failing_required ): void {
- wp_enqueue_script(
- self::SCRIPT_HANDLE,
- plugins_url( 'assets/js/admin/wc-agentic-commerce-settings' . $this->get_script_suffix() . '.js', WC_PLUGIN_FILE ),
- array( 'wp-api-fetch' ),
- WC_VERSION,
- true
- );
- wp_localize_script(
- self::SCRIPT_HANDLE,
- 'wcAgenticCommerceSettings',
- array(
- 'path' => '/wc/v3/agent-readiness/ucp',
- 'scanPath' => '/wc/v3/agent-readiness/scan',
- 'i18n' => array(
- 'on' => self::on_message( $failing_required ),
- 'error' => __( 'The setting could not be changed. Reload the page and try again.', 'woocommerce' ),
- 'copied' => __( 'Copied', 'woocommerce' ),
- 'running' => __( 'Checking your store in the background. Reload this page in a minute to see the result.', 'woocommerce' ),
- 'statusLabel' => self::status_labels(),
- ),
- )
- );
- }
}
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/Checks/SimpleCheck.php b/plugins/woocommerce/src/Internal/AgentReadiness/Checks/SimpleCheck.php
index 7a872a84a71..a66d5f56de9 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/Checks/SimpleCheck.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/Checks/SimpleCheck.php
@@ -206,15 +206,8 @@ final class SimpleCheck extends AbstractReadinessCheck {
* @param \WC_Product $product Published product.
*/
private static function has_unset_variation_option( \WC_Product $product ): bool {
- if ( ! $product instanceof \WC_Product_Variable ) {
- return false;
- }
- $variation_attributes = array_filter(
- $product->get_attributes(),
- static fn( $attribute ): bool => $attribute instanceof \WC_Product_Attribute && $attribute->get_variation()
- );
- if ( empty( $variation_attributes ) ) {
- return true;
+ if ( array() === self::variation_attributes( $product ) ) {
+ return $product instanceof \WC_Product_Variable;
}
foreach ( ProductFields::variations( $product ) as $variation ) {
if ( self::has_unset_option( $variation ) ) {
@@ -224,6 +217,22 @@ final class SimpleCheck extends AbstractReadinessCheck {
return false;
}
+ /**
+ * Attributes the parent uses for variations.
+ *
+ * @param \WC_Product $product Product.
+ * @return array<int, \WC_Product_Attribute>
+ */
+ private static function variation_attributes( \WC_Product $product ): array {
+ if ( ! $product instanceof \WC_Product_Variable ) {
+ return array();
+ }
+ return array_filter(
+ $product->get_attributes(),
+ static fn( $attribute ): bool => $attribute instanceof \WC_Product_Attribute && $attribute->get_variation()
+ );
+ }
+
/**
* Whether a variation has an option set to "any".
*
@@ -251,7 +260,11 @@ final class SimpleCheck extends AbstractReadinessCheck {
*/
public function failing_variations( \WC_Product $product, ProductScan $scan ): ?array {
unset( $scan );
- return null === $this->variation_test ? null : self::variation_ids_where( $product, $this->variation_test );
+ // No variation attribute on the parent fails the whole product. A child that still stores a blank option must not shrink that to one variation's sales.
+ if ( null === $this->variation_test || ( 'variation_attributes_not_set' === $this->id && array() === self::variation_attributes( $product ) ) ) {
+ return null;
+ }
+ return self::variation_ids_where( $product, $this->variation_test );
}
/**
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/FeedChannels.php b/plugins/woocommerce/src/Internal/AgentReadiness/FeedChannels.php
index 9557194930a..f94676e3a8c 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/FeedChannels.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/FeedChannels.php
@@ -36,7 +36,7 @@ final class FeedChannels {
'url' => 'https://support.google.com/merchants/answer/7052112',
),
self::COPILOT => array(
- 'name' => 'Microsoft Copilot',
+ 'name' => 'Copilot',
'spec' => 'Microsoft Merchant Center product data',
'url' => 'https://learn.microsoft.com/en-us/advertising/shopping-content/products-resource',
),
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ProductSales.php b/plugins/woocommerce/src/Internal/AgentReadiness/ProductSales.php
index cbc1c120299..4e94356691f 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/ProductSales.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ProductSales.php
@@ -110,10 +110,12 @@ class ProductSales {
/**
* How many orders the store holds since a date, with the statuses Analytics counts. Analytics
- * holds fewer while its import of past orders hasn't run or finished. WCPay test-mode orders
- * are left out the same way OrdersScheduler skips them (meta `_wcpay_mode=test`). They are
- * counted in a second query and subtracted, because the posts order store doesn't support
- * `meta_query`. A custom `woocommerce_analytics_is_test_order` callback is not applied.
+ * holds fewer while its import of past orders hasn't run or finished. Child orders are left
+ * out (`parent` 0): a multivendor sub-order is not a separate order Analytics imports.
+ * WCPay test-mode orders are left out the same way OrdersScheduler skips them (meta
+ * `_wcpay_mode=test`). They are counted in a second query and subtracted, because the posts
+ * order store doesn't support `meta_query`. A custom `woocommerce_analytics_is_test_order`
+ * callback is not applied.
*
* @param \DateTimeImmutable $since Start of the period.
* @param array<int, string> $excluded Statuses Analytics leaves out.
@@ -127,6 +129,7 @@ class ProductSales {
$orders = wc_get_orders(
array(
'type' => 'shop_order',
+ 'parent' => 0,
'status' => array_values( $statuses ),
'date_created' => '>=' . $since->getTimestamp(),
'limit' => 1,
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/README.md b/plugins/woocommerce/src/Internal/AgentReadiness/README.md
index 8edd27f6347..e6d23ef1d1c 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/README.md
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/README.md
@@ -12,7 +12,7 @@ The checks read product data and store settings, because most gaps are empty fie
| --- | --- | --- |
| `chatgpt` | ChatGPT | [OpenAI product feed spec](https://developers.openai.com/commerce/specs/feed) |
| `google` | Google (Shopping, AI Mode, Gemini) | [Google Merchant Center product data spec](https://support.google.com/merchants/answer/7052112) |
-| `copilot` | Microsoft Copilot | [Microsoft Merchant Center product data](https://learn.microsoft.com/en-us/advertising/shopping-content/products-resource) |
+| `copilot` | Copilot | [Microsoft Merchant Center product data](https://learn.microsoft.com/en-us/advertising/shopping-content/products-resource) |
## Checks
@@ -47,9 +47,9 @@ Two Google exceptions, per product: `missing_brand` leaves Google out when Googl
## Scope
-Only published simple and variable products are checked, the types agents support today. Two groups are counted instead of checked, so the merchant sees them without being asked to fix them:
+Only published simple and variable products are checked, the types agents can buy today. Agents find other types through the UCP catalog, but its cart sends only a product and a quantity: grouped and external products aren't purchasable, and subscriptions, bookings and bundles need a plan, a date or options it doesn't send. Two groups are counted instead of checked, so the merchant sees them without being asked to fix them:
-- Products hidden from the shop catalog (catalog visibility "Search results only" or "Hidden"). Agents see the products shoppers see in the shop, so hiding one is the merchant's choice, not a problem.
+- Products with catalog visibility "Hidden". Agents see the products shoppers see in the shop, so hiding one is the merchant's choice, not a problem. "Search results only" products are checked, since agents find them by search.
- Products of any other type: grouped, external, subscription, booking, bundle and so on. A product keeps its stored type when its plugin is inactive, so it stays in this group.
Store-wide conditions (`StoreConditions`) are reported first because they affect every product: coming soon mode and "Discourage search engines" hide the products, UCP off, no HTTPS and a `/.well-known/ucp` the store can't serve (Plain permalinks without a static file, a file WooCommerce didn't write in the way, or WooCommerce's file with an outdated profile; see `UcpDiscovery::serve_status()`, which picks the fix shown) hide the catalog from UCP agents, no payment method turned on stops agents placing orders, and guest checkout off stops UCP checkout while agents can still build carts. Missing policy pages and order emails off weaken agent orders. Each condition's `blocks` says which, so a reader can tell a hidden store from one agents can't buy from.
@@ -88,10 +88,10 @@ Store-wide conditions (`StoreConditions`) are reported first because they affect
| `product_review_markup` | The newest visible published product with reviews (of the five newest with reviews) has `aggregateRating` or `review` in its JSON-LD. Passes when reviews are off or no product has any. |
| `policy_pages_linked` | The home page links to the privacy policy and refund and returns pages the store set. Skipped when neither is set. |
| `ucp_profile` | With UCP on: `/.well-known/ucp` is served and names a REST endpoint. |
-| `ucp_endpoints_live` | With UCP on: a POST to `{endpoint}/catalog/search`, the route agents call, answers with JSON. A 200 or a 400 both count: an empty body is refused because a query or a filter is required. The endpoint is the one the profile names, or WooCommerce's when there is no profile. |
+| `ucp_endpoints_live` | With UCP on: a POST to `{endpoint}/catalog/search`, the route agents call, answers with JSON. A 200 or a 400 both count: an empty body is refused because a query or a filter is required. The endpoint is the one the profile names, or WooCommerce's when there is no profile. A failed answer is asked once more before the check fails, and the report's `source` keeps the last answer's status and content type (`403 text/html`). |
| `ucp_profile_version` | With UCP on: the served profile declares the UCP version WooCommerce implements (`UcpUtils::VERSION`). A different version usually means another plugin serves its own profile. |
-| `ucp_checkout` | With UCP on: the served profile declares `dev.ucp.shopping.checkout`. Pending (WOOAI-1435). |
-| `product_return_policy_schema` | A product offer in the product page's JSON-LD has `hasMerchantReturnPolicy`. Pending (WOOPRD-3912). |
+| `ucp_checkout` | With UCP on: the served profile declares `dev.ucp.shopping.checkout`. Pending until this WooCommerce serves UCP checkout; not shown while guest checkout is off, since the profile then offers none. |
+| `product_return_policy_schema` | A product offer, or the store's OnlineStore or Organization item, in the product page's JSON-LD has `hasMerchantReturnPolicy`. |
| `product_shipping_schema` | A product offer has `shippingDetails`. "Couldn't check" for a product that doesn't ship. Pending (WOOPRD-3908). |
| `product_buy_action_schema` | The product or an offer has a `BuyAction` in `potentialAction`. "Couldn't check" for a variable product without one: WooCommerce links only a chosen variation to checkout (WOOPRD-3946, after the ProductGroup work in WOOPRD-3907). Pending (WOOPRD-3918). |
@@ -106,7 +106,9 @@ The checks judge what the store returns, whoever provides it. Some things they c
A check listed in `StoreOutputChecks::PENDING` tests output WooCommerce doesn't build yet. It doesn't run: it's reported with `ok` null and `pending` true, so it reads as coming soon, not as failed or couldn't check. Remove its entry when that output ships.
-robots.txt is loaded from the host root, only to find the sitemaps it lists. Its crawler rules aren't checked: a host or CDN can rewrite the file or block crawlers without it, and the store's request to itself skips both, so they wait for an outside view of the store (WOOPRD-3953). The sitemap check is "couldn't check" when robots.txt could not be read, or a candidate sitemap could not be loaded or answered other than 200, 404 or 410, and no fetched sitemap names products. A category sitemap does not count. When an index does not name products, its child sitemaps on this host are checked, nested indexes included (Jetpack serves one past 1,000 URLs), up to five child requests in all. Sitemap lines on another host, or written as `//host/path`, are skipped and do not use up the five listed slots. Checks on the home and product page read the ones that loaded. The product structured data checks also read the variants a ProductGroup lists in `hasVariant`, where a variable product's offers sit once it is printed as a ProductGroup (WOOPRD-3907). The category page is one of the sampled product's categories, or the largest category when it has none. The home page loads first; when it can't be reached, the scan makes no more requests, so a store that can't reach itself waits for one timeout. The product checks load one product page: among the five newest published simple or variable products in the shop catalog, the newest with a price and no password, or the newest without a password when none of them has a price. With no such product, or when its page doesn't answer 200, they are "couldn't check".
+A check listed in `ReadinessCheckPage::SAME_CAUSE` isn't shown while the setup step it names fails, so one cause shows once: `no_noindex_directives` while "Discourage search engines" is on, `product_return_policy_schema` while no published refund and returns page is chosen, and `ucp_checkout` while guest checkout is off. A stock store creates that page as a draft, so the setup step shows instead.
+
+robots.txt is loaded from the host root, only to find the sitemaps it lists. Its crawler rules aren't checked: a host or CDN can rewrite the file or block crawlers without it, and the store's request to itself skips both, so they wait for an outside view of the store (WOOPRD-3953). The sitemap check is "couldn't check" when robots.txt could not be read, or a candidate sitemap could not be loaded or answered other than 200, 404 or 410, and no fetched sitemap names products. A category sitemap does not count. When an index does not name products, its child sitemaps on this host are checked, nested indexes included (Jetpack serves one past 1,000 URLs), up to five child requests in all. Sitemap lines on another host, or written as `//host/path`, are skipped and do not use up the five listed slots. Checks on the home and product page read the ones that loaded. The product structured data checks also read the variants a ProductGroup lists in `hasVariant`, where a variable product's offers sit once it is printed as a ProductGroup (WOOPRD-3907). The category page is one of the sampled product's categories, or the largest category when it has none. The home page loads first; when it can't be reached, the scan makes no more requests, so a store that can't reach itself waits for one timeout. The product checks load one product page: among the five newest published simple or variable products not set to Hidden, the newest with a price and no password, or the newest without a password when none of them has a price. With no such product, or when its page doesn't answer 200, they are "couldn't check".
The checks from `no_noindex_directives` down pass on a stock store today. They stay as regression guards, so a merchant hears when a host, theme or plugin breaks one.
@@ -116,7 +118,7 @@ The checks from `no_noindex_directives` down pass on a stock store today. They s
## What the store declares to agents
-`DeclaredToAgents` lists protocols and files as found or not found, for information. Each has a path or signal from its spec, and a JSON document has to have the fields its spec requires. Its results go into the report's `declared` and never count as a problem.
+`DeclaredToAgents` lists protocols and files as found or not found, for information. Each has a path or signal from its spec, and a JSON document has to have the fields its spec requires. Its results go into the report's `declared` and never count as a problem. It lists only what the scan reads, so nothing is "not checked" on every store. Sales readiness lists only the items found, and has no declared card when none is.
Markdown is asked for on the product page, or the home page without a product: with `Accept: text/markdown`. An HTML answer doesn't count. A copy at the page's `.md` address isn't requested: each declared item reads a response the scan already loads. `Vary: Accept` isn't listed: hosts and CDNs set it, and the store's request to itself skips them.
@@ -128,7 +130,7 @@ Markdown is asked for on the product page, or the home page without a product: w
array(
'generated_at' => '2026-10-28T12:00:00+00:00',
'products' => 120, // Published simple and variable products checked.
- 'hidden_from_catalog' => 4, // Not checked: catalog visibility "Search results only" or "Hidden", the merchant's choice.
+ 'hidden_from_catalog' => 4, // Not checked: catalog visibility "Hidden", the merchant's choice.
'unsupported_types' => 6, // Not checked: grouped, external, subscription, bundle and other types agents can find but can't add to a cart yet.
'store_checks' => array(
// blocks: 'listing' (every product on every channel), 'discovery' (harder to find and read), 'ucp' (the catalog for UCP agents) or 'checkout' (agent orders).
@@ -174,7 +176,7 @@ array(
Channel specs change faster than WooCommerce releases, so each background scan first fetches a published rules file (`RemoteRules`). Only a GET of the file is made; the request's user agent includes the site URL, as other WooCommerce.com polls do. The `woocommerce_agent_readiness_rules_url` filter changes the URL; an empty URL turns the fetch off. With no stored file, or a failed fetch, the bundled checks run.
-The file has a `version` and a `checks` object. The ids in `checks` are the checks that run, and each one has to match a check shipped in code. An id the file leaves out does not run. An id code does not know, or an unknown channel, is dropped. A check whose entry has a known channel with a missing field, an effect other than `not_listable` or `gaps`, or a bad `effect_from` runs with its bundled channels, so a typo never turns a check off. With no stored file, or a file that names nothing this code can run, the bundled checks run. A failed or malformed fetch keeps the last good copy (option `woocommerce_agent_readiness_remote_rules`).
+The file has a `version` (the date of its last change, `Y-m-d`), a `checks` object and an optional `store_checks` object. `store_checks` changes store checks by id: `"required": true` or `false` sets whether a setup step or output check is shown as Required (badge, Fix first, Setup checklist), and `"off": true` stops it running and leaves it out of the report. An id it leaves out keeps its bundled behaviour (`StoreConditions::SHOWN_REQUIRED`). Shown as Required still doesn't keep AI shopping from being turned on; only `launched` and `https` do, and those two are always Required and can't be turned off. The ids in `checks` are the checks that run, and each one has to match a check shipped in code. An id the file leaves out does not run. An id code does not know, or an unknown channel, is dropped. A check whose entry has a known channel with a missing field, an effect other than `not_listable` or `gaps`, or a bad `effect_from` runs with its bundled channels, so a typo never turns a check off. With no stored file, or a file that names nothing this code can run, the bundled checks run. A failed or malformed fetch keeps the last good copy (option `woocommerce_agent_readiness_remote_rules`).
Per check, `channels` maps a channel id to the feed field and the effect, the same shape as the `woocommerce_agent_readiness_rules` filter. A channel entry may carry `effect_from` (`{ "2027-01-31": "not_listable" }`) for a spec change announced ahead. The filter runs last, so it can still drop a check or put a bundled one back. The file cannot add a check the code has never seen: that still needs a class.
@@ -182,15 +184,15 @@ Per check, `channels` maps a channel id to the feed field and the effect, the sa
## Background scan and REST
-"Run check" on the Agentic commerce settings page, or `POST wc/v3/agent-readiness/scan`, queues the scan in Action Scheduler (`ScheduledScan`). The report is stored in the `woocommerce_agent_readiness_report` option (not autoloaded). Each run schedules the next one a day later, before scanning, so a failed scan doesn't stop the daily refresh; a run that finds the feature disabled does. If a queued scan still hasn't started 10 minutes after it was due and no other scheduled action has finished, failed or started in that time (Action Scheduler isn't running), the settings page says so and the scan stays queued. The scan never runs in a page or REST request; splitting the product pass into one action per batch is WOOAI-1661.
+"Run checks" on WooCommerce > Sales readiness, or `POST wc/v3/agent-readiness/scan`, queues the scan in Action Scheduler (`ScheduledScan`). The report is stored in the `woocommerce_agent_readiness_report` option (not autoloaded). Each run schedules the next one a day later, before scanning, so a failed scan doesn't stop the daily refresh; a run that finds the feature disabled does. If a queued scan still hasn't started 10 minutes after it was due and no other scheduled action has finished, failed or started in that time (Action Scheduler isn't running), the Sales readiness page says so and the scan stays queued. The scan never runs in a page or REST request; splitting the product pass into one action per batch is WOOAI-1661.
On a store with 11,000 products, a scan (stopping at 5,000) took about 4 seconds and 144 MB. A product saved since the scan is already reflected in the counts, as described under Failures per product.
-`GET wc/v3/agent-readiness` returns `{ "report": <report or null>, "scan_pending": <bool>, "scan_stalled": <bool> }` from `AgentReadiness::get_served_report()`, so `store_checks` are read now; `scan_stalled` is true while a queued scan waits on a stalled Action Scheduler. Both routes need `manage_woocommerce` and exist only while the feature is enabled.
+`GET wc/v3/agent-readiness` returns `{ "report": <report or null>, "scan_pending": <bool>, "scan_stalled": <bool> }` from `AgentReadiness::get_served_report()`, so `store_checks` are read now; `scan_stalled` is true while a queued scan waits on a stalled Action Scheduler. `GET wc/v3/agent-readiness/view` returns what the Sales readiness page and the AI tools Overview show (`ReadinessCheckPage::view()`): text, badges and links only, so the React views render it without knowing the checks. All three routes need `manage_woocommerce` and exist only while the feature is enabled.
-The same shape is meant for every consumer: the Agentic commerce settings page, an outside scan of a store, and extensions that rank the findings by sales or offer fixes. Check and channel ids are stable keys.
+The same shape is meant for every consumer: WooCommerce > Sales readiness and AI shopping, an outside scan of a store, and extensions that rank the findings by sales or offer fixes. Check and channel ids are stable keys.
-The scan walks published simple and variable products shown in the shop catalog in batches of 200, most recently modified first, primes meta, terms, images and variations per batch, and stops at 5,000 products.
+The scan walks published simple and variable products not set to Hidden in batches of 200, most recently modified first, primes meta, terms, images and variations per batch, and stops at 5,000 products.
## Abilities
@@ -199,17 +201,23 @@ While the feature is enabled, `AbilitiesLoader` registers these abilities in the
- `woocommerce/get-agent-readiness` and `GET wc/v3/agent-readiness` both return `{ report, scan_pending, scan_stalled }` from `AgentReadiness::get_served_report()`: settings changed since the scan show their current state, and store output checks come from the stored report.
- `woocommerce/run-agent-readiness-check` with `product_id` checks that product now (`check_product()`) and returns its failing checks with label and fix, and its status per channel. Without one it queues the background scan, like `POST wc/v3/agent-readiness/scan`, and returns `scan_pending`, `scan_stalled` and `report_generated_at`, so the agent knows when to read the report again, or that it won't change until scheduled actions run.
-## Agentic commerce settings page
+## AI tools and Sales readiness
+
+WooCommerce > Settings > AI tools (`AgenticCommerceSettings`, `AgenticCommerceSettingsPage`; the tab id stays `agentic-commerce`) and WooCommerce > Sales readiness (`ReadinessCheckPage`, a WooCommerce Admin page at `admin.php?page=wc-admin&path=/sales-readiness`, between Reports and Settings in the menu) show while the feature is enabled. They follow the WOOPRD-3796 and WOOPRD-3947 designs. Both are React views on `@wordpress/ui` in `client/admin/client/sales-readiness/`, fed by `GET wc/v3/agent-readiness/view`; every string, badge and ranking is built in `ReadinessCheckPage::view()`, where the tests are. AI tools opens on the Overview, a React root mounted by the `settings-embed` script, with two cards. The AI shopping card has the Status badge, whether AI assistants can shop the store and how many setup steps are left, and Manage, which opens AI shopping (`§ion=shopping`). Before the UCP setting is first saved, the card says what AI shopping does and offers Set up AI shopping instead; once UCP is turned off, it says AI shopping is off. The Sales readiness card has Fix first (or Run checks before the first scan) and View all checks, which opens the page. AI shopping's Status card also ends with a link to it and its issue count. The markup AI shopping still shares with the old views (check rows, badges, folds and the script) is in the `ReadinessMarkup` trait.
+
+AI shopping has one card per part:
+
+- The UCP switch, first. It saves through `POST wc/v3/agent-readiness/ucp` (`{ "enabled": true }`). A failing required check keeps it from being turned on, and that POST answers 409; turning it off still works. While it is on and the required checks pass it says "AI assistants can now find and shop your store.", and the page reloads after it changes. In coming soon mode the card says agents can't shop the store yet and links to Site visibility.
+- Product visibility: Available to AI assistants, Hidden from your catalog and Product type not supported yet, from the stored report (`products`, `hidden_from_catalog`, `unsupported_types`). Each links to the Products list filtered to those products (`ProductScan::count_query()`, the query the scan counts with), and a footnote names the supported types.
+- Status: a badge (Needs attention while a required step fails, with UCP on or off; otherwise Active or Off as UCP is), then the store conditions from `StoreConditions`, the same list the readiness report shows. Open conditions are one list, failing `required` ones first (coming soon mode, HTTPS and the UCP address), marked Fix; failing `recommended` ones, marked Check, such as a missing privacy, terms, refund and returns, or shipping policy page (policy pages are not required by the UCP spec), follow. The card says how many required steps are left to fix, or how many steps are left when none is required. Each step says why it matters and links to where to fix it; a chosen policy page that isn't published links to its editor, and a store page chosen as one asks for another page. Passing conditions fold behind "Show N completed steps", named by their passing state (`name`) and marked Pass. The last row links to Sales readiness with how many issues the store and product checks found together.
+- Store policy pages. Refund and returns, privacy and terms are the existing options, so they stay in sync with Advanced > Page setup and Settings > Privacy; shipping policy, FAQ and warranty are new. They are for the policy links a UCP checkout can carry (`links`); the UCP endpoints don't send them yet. The dropdowns list published pages other than the cart, checkout, shop and My account pages, and saving leaves a stored page in place even when it's a draft or one of those store pages, which then fails its check. A link from Status opens the page on its field, highlighted.
+- The store address AI assistants start from (`/.well-known/ucp`), with Copy.
+
+Sales readiness opens with when the last check ran and Check again ("Run checks" before the first), then Fix first, then a card per question. It shows the setup steps from `StoreConditions` (UCP aside, as the switch) under the question each answers, a failing required one marked Required, and the store output checks from the stored report, since they only run in the scan. Each check names the question it answers in `group` (`access`, `find`, `understand` or `buy`), and each question's card has a badge: how many issues, All passed, or No issues when a check couldn't run. Failing and unchecked rows come first, then passed ones; each card shows the first two and folds the rest behind "Show N more checks", with "Hide" below the opened list. Checks waiting on a later update (`pending`) aren't shown. Output checks are never required, so they don't affect the switch or Status. A failing row is named by its failing title (`label`), then what it affects ("Affects: how AI assistants summarize your store", by check, or from `blocks`), why it matters, what to do and a link. The product checks are their own question, before "Can shoppers buy through AI assistants?". The last card, "What does your store share with AI assistants?", has no badge: it says how many declared items were found ("Found 4 of 33"), with every item behind a fold.
-WooCommerce > Settings > Agentic commerce (`AgenticCommerceSettings`, `AgenticCommerceSettingsPage`) shows while the feature is enabled. It follows the WOOPRD-3796 design, one card per part:
+The product checks, under "Can AI assistants list your products?", show how many products each channel can list ("2 of 15 can be listed"), then each failing product check, titled with what to do and its count ("Add a brand to 13 products"), why it matters, and "View N products", which opens the Products list filtered to them. With up to three failing products the title names them ("Add a brand to Blue hoodie and Red cap") when their failures are stored; one product without them is "a product", and more than three are counted. The copy is in `ReadinessCopy`. Product image alt text isn't listed there, since the `images_have_alt` store check covers it.
-- The UCP switch, first. It saves through `POST wc/v3/agent-readiness/ucp` (`{ "enabled": true }`). A failing required check keeps it from being turned on, and that POST answers 409; turning it off still works. In coming soon mode the card says agents can't shop the store yet and links to Site visibility.
-- Product counts from the stored report (`products`, `hidden_from_catalog`, `unsupported_types`), each linking to a filtered product list.
-- Status: the store conditions from `StoreConditions`, the same list the readiness report shows, in three groups. Required lists failing `required` conditions (coming soon mode, HTTPS and the UCP address) and puts the status at Action needed; Recommended lists failing `recommended` ones, such as a missing privacy, terms, refund and returns, or shipping policy page (policy pages are not required by the UCP spec); Done lists the passing ones by their passing state (`name`). Each open condition says what to do and links to the screen that does it, when there is one. The UCP address row names the file to remove or the folder permissions to change, and links to permalinks only when changing them is one of the fixes. A chosen policy page that isn't published links to its editor.
-- Agent readiness: the store output checks from the stored report, since they only run in the scan. Each check names the question it answers in `group` (`access`, `find`, `understand` or `buy`), and the card shows the checks under those four questions. They are never required, so they don't affect the switch or Status. A failing row adds why it matters and what it affects (`blocks`). The card has "Run check" with the time of the last run, and the product checks from the stored report: per-channel counts, and each failing check with its channels and up to 3 example products. The stored report still keeps up to 10 ids per check.
-- Store policy pages. Refund and returns, privacy and terms are the existing options, so they stay in sync with Advanced > Page setup and Settings > Privacy; shipping policy, FAQ and warranty are new. They are for the policy links a UCP checkout can carry (`links`); the UCP endpoints don't send them yet. The dropdowns list published pages other than the cart, checkout, shop and My account pages, and saving leaves a stored page in place even when it's a draft or one of those store pages, which then fails its check.
-- The store address agents start from (`/.well-known/ucp`), with Copy.
-- Placeholders for parts that aren't built yet: Test your setup (WOOAI-1619) and Security (WOOAI-1620).
+Fix first, a card of its own, lists the required setup steps that fail, then the top three other issues. Required setup steps include the ones shown as Required (`StoreConditions::SHOWN_REQUIRED`, or `store_checks` in the rules file): `search_visible` and `payment_method`. Issues are ranked by what they stop, then by sales: store checks that block `listing` (such as structured data) and product checks that keep products off a channel (`not_listable`), then product checks that only make products harder to find. Within each, the larger share of sales on the affected products comes first, then the larger product count, then page order. Store checks with no sales link, such as a missing meta description, stay out of Fix first. `ProductSales` reads each product's net sales over the last 90 days from the Analytics lookup tables (`wc_order_product_lookup` joined with `wc_order_stats`), with the order statuses Analytics excludes left out and variations counted toward their parent and on their own. The scan adds up the sales of each check's failing products. A check a variable product fails through some of its variations (a missing price or GTIN, a missing variation image, or an option set to "any") adds only those variations' sales. An invalid GTIN, a GTIN shared with another product, and an image under 500 pixels still count the whole product's sales, which only changes the rank. The report stores each check's `sales_share` (0 to 1) and `sales` (`days`, `orders`, `imported`). While Analytics is off, `sales` is null. With fewer than `ProductSales::MIN_ORDERS` (20) orders in the period, too few to rank by, shares are null. They are null too while a store with at least 20 orders has under 90% of them in Analytics (`imported` false), as when past orders were never imported. Orders in several currencies are summed without conversion, as Analytics does. In both cases Fix first ranks by product count and says why. It says to start with the fixes that affect the most sales, over the period the figures cover, only when an issue on the card sold something; otherwise it says it ranks by product count. A share is rounded to 4 places and any sales keep at least 0.0001, so small sales never read as "No sales". A share is not shown once a check's count changes after the scan, since it was measured on the products failing then, but Fix first still ranks the check by it (`ranked_share`), so fixing one product doesn't move the issue down. Under headings for what each group stops (Required for AI shopping, Needed to list products, Helps shoppers find products), a product issue is badged by its share of sales ("38% of sales"); its line starts with the share, the first saying over which period ("38% of your sales in the last 90 days."); products that sold nothing in the period say "No sales" instead of 0%.
Tracks event: `agentic_commerce_ucp_toggled` (`enabled`), sent only when the store allows tracking.
@@ -229,4 +237,4 @@ Core's UCP catalog mapper (`src/Internal/ProductFeed/Mapping/UcpProductMapper.ph
wp option update woocommerce_feature_agent_readiness_enabled yes
```
-Then open WooCommerce > Settings > Agentic commerce and select "Run check".
+Then open WooCommerce > Sales readiness and select "Run checks". AI shopping is under WooCommerce > Settings > AI tools.
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCheckPage.php b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCheckPage.php
new file mode 100644
index 00000000000..be9c10435ee
--- /dev/null
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCheckPage.php
@@ -0,0 +1,1098 @@
+<?php
+declare( strict_types = 1 );
+
+namespace Automattic\WooCommerce\Internal\AgentReadiness;
+
+use Automattic\WooCommerce\Internal\Features\FeaturesController;
+use Automattic\WooCommerce\Internal\RegisterHooksInterface;
+use Automattic\WooCommerce\StoreApi\Utilities\Ucp\Utils as UcpUtils;
+
+defined( 'ABSPATH' ) || exit;
+
+/**
+ * Sales readiness, while the agent_readiness feature is enabled: when the store was last checked, Fix first,
+ * then a card per merchant question with the checks from the last scan. It is a WooCommerce Admin page
+ * under the WooCommerce menu, before Settings; the React page reads everything it shows from
+ * wc/v3/agent-readiness/view, which this class builds. The same builder gives the AI tools tab its
+ * Overview: the AI shopping card and the Sales readiness card with Fix first.
+ *
+ * @since 11.4.0
+ */
+class ReadinessCheckPage implements RegisterHooksInterface {
+
+ use ReadinessMarkup;
+
+ public const PAGE_ID = 'woocommerce-sales-readiness';
+
+ public const PATH = '/sales-readiness';
+
+ /**
+ * The admin_menu priority: between WooCommerce's Reports (20) and Settings (50).
+ */
+ public const MENU_PRIORITY = 30;
+
+ /**
+ * Product checks that Sales readiness leaves out: product image alt text repeats the images_have_alt store check.
+ */
+ private const HIDDEN_PRODUCT_CHECKS = array( 'image_alt_text' );
+
+ /**
+ * How many issues Fix first lists after the required steps.
+ */
+ private const FIX_FIRST_ISSUES = 3;
+
+ /**
+ * Scanned checks that are Required although they don't keep AI assistants off the store's pages:
+ * with AI shopping on, AI assistants can't connect, search or check out without them. These checks
+ * are only shown while AI shopping is on. The rules file's `store_checks` can change any scanned check's level.
+ */
+ private const REQUIRED_SCANNED = array( 'ucp_profile', 'ucp_endpoints_live', 'ucp_checkout' );
+
+ /**
+ * Checks that can only run when the check they name passed, so aren't shown when it failed.
+ */
+ private const CHECK_NEEDS = array(
+ 'product_jsonld_from_core' => 'product_jsonld_present',
+ 'product_jsonld_required_fields' => 'product_jsonld_present',
+ 'product_offer_jsonld' => 'product_jsonld_present',
+ 'product_return_policy_schema' => 'product_jsonld_present',
+ 'llms_txt_valid' => 'llms_txt_present',
+ 'llms_txt_links_resolve' => 'llms_txt_present',
+ );
+
+ /**
+ * Scanned checks left out while a setup step with the same cause fails, so it shows once: WordPress
+ * prints noindex while "Discourage search engines" is on, WooCommerce adds no returns policy
+ * to product pages until a refund and returns page is chosen, and UCP offers no checkout while
+ * guest checkout is off.
+ */
+ private const SAME_CAUSE = array(
+ 'no_noindex_directives' => 'search_visible',
+ 'product_return_policy_schema' => 'refund_returns_page',
+ 'ucp_checkout' => 'guest_checkout',
+ );
+
+ /**
+ * Badge intents of the design system, by the badge class the PHP pages use.
+ */
+ private const INTENTS = array(
+ 'check' => 'low',
+ 'info' => 'stable',
+ 'pass' => 'stable',
+ 'off' => 'none',
+ 'fix' => 'low',
+ );
+
+ /**
+ * Features controller.
+ *
+ * @var FeaturesController
+ */
+ private FeaturesController $features_controller;
+
+ /**
+ * Store conditions.
+ *
+ * @var StoreConditions
+ */
+ private StoreConditions $store_conditions;
+
+ /**
+ * Readiness service.
+ *
+ * @var AgentReadiness
+ */
+ private AgentReadiness $agent_readiness;
+
+ /**
+ * Background scan.
+ *
+ * @var ScheduledScan
+ */
+ private ScheduledScan $scheduled_scan;
+
+ /**
+ * Initialize dependencies.
+ *
+ * @internal
+ *
+ * @param FeaturesController $features_controller Features controller.
+ * @param StoreConditions $store_conditions Store conditions.
+ * @param AgentReadiness $agent_readiness Readiness service.
+ * @param ScheduledScan $scheduled_scan Background scan.
+ */
+ final public function init( FeaturesController $features_controller, StoreConditions $store_conditions, AgentReadiness $agent_readiness, ScheduledScan $scheduled_scan ): void {
+ $this->features_controller = $features_controller;
+ $this->store_conditions = $store_conditions;
+ $this->agent_readiness = $agent_readiness;
+ $this->scheduled_scan = $scheduled_scan;
+ }
+
+ /**
+ * Register hooks. The feature check waits for init, since feature definitions load translations.
+ */
+ public function register(): void {
+ add_action( 'init', array( $this, 'handle_init' ) );
+ }
+
+ /**
+ * Add the page while the feature is enabled.
+ *
+ * @internal
+ */
+ public function handle_init(): void {
+ if ( ! is_admin() || ! $this->features_controller->feature_is_enabled( AgenticCommerceSettings::FEATURE_ID ) ) {
+ return;
+ }
+ // After Reports (20) and before Settings (50), as WooCommerce adds them.
+ add_action( 'admin_menu', array( $this, 'handle_admin_menu' ), self::MENU_PRIORITY );
+ }
+
+ /**
+ * Register the WooCommerce Admin page under WooCommerce.
+ *
+ * @internal
+ */
+ public function handle_admin_menu(): void {
+ if ( ! function_exists( 'wc_admin_register_page' ) ) {
+ return;
+ }
+ wc_admin_register_page(
+ array(
+ 'id' => self::PAGE_ID,
+ 'parent' => 'woocommerce',
+ 'title' => __( 'Sales readiness', 'woocommerce' ),
+ 'path' => self::PATH,
+ 'capability' => 'manage_woocommerce',
+ )
+ );
+ }
+
+ /**
+ * Link to the page.
+ */
+ public static function url(): string {
+ return admin_url( 'admin.php?page=wc-admin&path=' . self::PATH );
+ }
+
+ /**
+ * The badge for Sales readiness as a whole, as AI shopping's Status card links to it: how many store and
+ * product checks fail, each failing product check counting as one issue.
+ *
+ * @param array<string, mixed>|null $report Stored report, or null before the first scan.
+ * @param array<int, array{id:string,ok:bool,blocks:string,level:string,name:string,label:string,why:string,fix:string,fix_url:string}> $checks Store conditions.
+ * @return array{0:string,1:string} Badge class and text.
+ */
+ public function badge( ?array $report, array $checks ): array {
+ if ( null === $report ) {
+ return array( 'off', __( 'Not checked yet', 'woocommerce' ) );
+ }
+ // Only what the page shows: setup steps that don't join Fix first live in the Setup checklist.
+ $shown = array_filter( $this->visible_store_checks( $report, $checks ), static fn( array $check ): bool => ! self::is_setup_step( $check ) || self::joins_fix_first( $check ) );
+ return self::group_badge( array_merge( $shown, array_fill( 0, count( self::failing_product_checks( $report ) ), array( 'ok' => false ) ) ) );
+ }
+
+ /**
+ * The AI shopping badge: Needs attention while a required step fails, even with UCP off,
+ * otherwise Active or Off as UCP is.
+ *
+ * @param array<int, array{id:string,ok:bool,level:string}> $checks Store conditions.
+ * @return array{0:string,1:string} Badge class and text.
+ */
+ public function shopping_badge( array $checks ): array {
+ if ( array() !== $this->store_conditions->failing_required( $checks ) ) {
+ return array( 'check', __( 'Needs attention', 'woocommerce' ) );
+ }
+ return UcpUtils::is_enabled() ? array( 'pass', __( 'Active', 'woocommerce' ) ) : array( 'off', __( 'Off', 'woocommerce' ) );
+ }
+
+ /**
+ * The setup steps still open, required ones first. UCP itself is the switch, so it is not a step.
+ *
+ * @param array<int, array{id:string,ok:bool,blocks:string,level:string,name:string,label:string,why:string,fix:string,fix_url:string}> $checks Store conditions.
+ * @return array<int, array{id:string,ok:bool,blocks:string,level:string,name:string,label:string,why:string,fix:string,fix_url:string}>
+ */
+ public static function open_steps( array $checks ): array {
+ $open = self::setup_order( array_filter( $checks, static fn( array $check ): bool => 'ucp_on' !== $check['id'] && ! $check['ok'] ) );
+ $required = array( StoreConditions::class, 'shows_required' );
+ return array_merge( array_values( array_filter( $open, $required ) ), array_values( array_filter( $open, static fn( array $check ): bool => ! $required( $check ) ) ) );
+ }
+
+ /**
+ * Setup steps in the order the pages list them: HTTPS first, then as StoreConditions lists them,
+ * which is also the order the report and the ability keep.
+ *
+ * @template T of array{id:string}
+ * @param array<int|string, T> $checks Store conditions.
+ * @return array<int, T>
+ */
+ private static function setup_order( array $checks ): array {
+ return array_merge(
+ array_values( array_filter( $checks, static fn( array $check ): bool => 'https' === $check['id'] ) ),
+ array_values( array_filter( $checks, static fn( array $check ): bool => 'https' !== $check['id'] ) )
+ );
+ }
+
+ /**
+ * Everything the Sales readiness page and the AI tools Overview show, as data for the React views:
+ * when the store was last checked and the check button, Fix first, a section per question, the
+ * declared items, and the Overview's AI shopping card.
+ *
+ * @return array<string, mixed>
+ */
+ public function view(): array {
+ // Pending on either side of the report read: a scan that finishes during the read must not
+ // pair an old report with pending false, and a scan queued during the read must not be hidden.
+ $pending = $this->scheduled_scan->is_pending();
+ $report = $this->agent_readiness->get_cached_report();
+ $pending = $pending || $this->scheduled_scan->is_pending();
+ $stalled = $pending && $this->scheduled_scan->is_stalled();
+ $checks = $this->store_conditions->all();
+ $launched = (bool) ( array_column( $checks, 'ok', 'id' )['launched'] ?? true );
+ $visible = $this->visible_store_checks( $report, $checks );
+ $message = '';
+ if ( $stalled ) {
+ $message = __( 'The check can’t start because scheduled actions aren’t running on this site.', 'woocommerce' );
+ } elseif ( $pending ) {
+ $message = __( 'Checking your store.', 'woocommerce' );
+ }
+ $truncated = null;
+ if ( null !== $report && ! empty( $report['truncated'] ) ) {
+ $available = (int) ( $report['available'] ?? 0 );
+ $truncated = $available > ProductScan::PRODUCT_LIMIT
+ /* translators: 1: number of products checked, 2: number of products in the store. */
+ ? sprintf( __( 'Checked the %1$s products you changed most recently, out of %2$s.', 'woocommerce' ), number_format_i18n( ProductScan::PRODUCT_LIMIT ), number_format_i18n( $available ) )
+ /* translators: %s: number of products checked. Reports from before the total was stored. */
+ : sprintf( __( 'Checked the %s products you changed most recently.', 'woocommerce' ), number_format_i18n( ProductScan::PRODUCT_LIMIT ) );
+ }
+ return array(
+ 'title' => __( 'Sales readiness', 'woocommerce' ),
+ 'description' => __( 'Check how well AI assistants can find and shop your store, and what to improve first.', 'woocommerce' ),
+ 'last_checked' => self::last_checked( $report ),
+ 'checked_note' => $truncated,
+ 'intro' => null === $report ? __( 'Run a check to see what AI assistants get when they visit your store and read your products.', 'woocommerce' ) : null,
+ 'run' => array(
+ 'label' => null === $report ? __( 'Run checks', 'woocommerce' ) : __( 'Check again', 'woocommerce' ),
+ 'pending' => $pending,
+ 'stalled' => $stalled,
+ 'message' => $message,
+ 'link' => $stalled ? array(
+ 'href' => admin_url( 'admin.php?page=wc-status&tab=action-scheduler&status=pending' ),
+ 'text' => __( 'Go to Scheduled Actions', 'woocommerce' ),
+ ) : null,
+ ),
+ 'fix_first' => null === $report ? null : $this->fix_first( $visible, $report ),
+ // Setup steps belong to the Setup checklist, so the question cards show only scanned checks.
+ 'sections' => null === $report ? array() : $this->sections( array_values( array_filter( $visible, static fn( array $check ): bool => ! self::is_setup_step( $check ) ) ), $launched, $report ),
+ 'declared' => null === $report ? null : self::declared( is_array( $report['declared'] ?? null ) ? $report['declared'] : array() ),
+ 'overview' => array(
+ 'shopping' => $this->shopping_card( $checks ),
+ // After the description, when the last check stopped at the product limit.
+ 'based_on' => null === $truncated ? null : sprintf(
+ /* translators: %s: number of products checked. */
+ __( 'Based on your %s most recently changed products.', 'woocommerce' ),
+ number_format_i18n( ProductScan::PRODUCT_LIMIT )
+ ),
+ 'view_all' => array(
+ 'href' => self::url(),
+ 'text' => __( 'View all checks', 'woocommerce' ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * The Overview's AI shopping card: its badge once AI shopping is on, whether AI assistants can shop the store and how
+ * many setup steps are left, and Manage. Before the UCP setting is first saved, it invites the merchant to set up AI
+ * shopping instead; once it has been turned off, it says so.
+ *
+ * @param array<int, array{id:string,ok:bool,blocks:string,level:string,name:string,label:string,why:string,fix:string,fix_url:string}> $checks Store conditions.
+ * @return array{title:string,badge:array{intent:string,text:string}|null,text:string,button:array{href:string,text:string}}
+ */
+ private function shopping_card( array $checks ): array {
+ $enabled = UcpUtils::is_enabled();
+ $left = count( self::open_steps( $checks ) );
+ $badge = $this->shopping_badge( $checks );
+ $can_shop = $enabled && array() === $this->store_conditions->failing_required( $checks );
+ $set_up = $enabled || false !== get_option( $this->features_controller->feature_enable_option_name( UcpUtils::FEATURE_ID ) );
+ if ( ! $set_up ) {
+ $text = __( 'Let shoppers find and buy your products through AI assistants.', 'woocommerce' );
+ } elseif ( ! $enabled ) {
+ $text = __( 'AI shopping is off.', 'woocommerce' );
+ } elseif ( 0 === $left ) {
+ $text = __( 'AI assistants can shop your store.', 'woocommerce' );
+ } else {
+ $text = sprintf(
+ /* translators: %d: number of setup steps left. */
+ $can_shop ? _n( 'AI assistants can shop your store. %d step left.', 'AI assistants can shop your store. %d steps left.', $left, 'woocommerce' ) : _n( 'AI assistants can\'t shop your store yet. %d step left.', 'AI assistants can\'t shop your store yet. %d steps left.', $left, 'woocommerce' ),
+ $left
+ );
+ }
+ return array(
+ 'title' => __( 'AI shopping', 'woocommerce' ),
+ 'badge' => ! $set_up || 'off' === $badge[0] ? null : self::badge_data( $badge ),
+ 'text' => $text,
+ 'button' => array(
+ 'href' => AgenticCommerceSettings::url( AgenticCommerceSettings::SHOPPING_SECTION ),
+ 'text' => $set_up ? __( 'Manage', 'woocommerce' ) : __( 'Set up AI shopping', 'woocommerce' ),
+ ),
+ );
+ }
+
+ /**
+ * A badge for the React views: the design system intent and the text.
+ *
+ * @param array{0:string,1:string} $badge Badge class and text.
+ * @return array{intent:string,text:string}
+ */
+ private static function badge_data( array $badge ): array {
+ return array(
+ 'intent' => self::INTENTS[ $badge[0] ] ?? 'none',
+ 'text' => $badge[1],
+ );
+ }
+
+ /**
+ * Whether a store check is a setup step (a setting, from StoreConditions) rather than a scanned
+ * check from the stored report. Setup steps are worded as actions and can be Required; scanned
+ * checks keep the report's wording. Only scanned checks carry a conflict flag: AgentReadiness
+ * sets it on every one of them, so its absence is what marks a setup step.
+ *
+ * @param array<string, mixed> $check Store check.
+ */
+ private static function is_setup_step( array $check ): bool {
+ return ! array_key_exists( 'conflict', $check );
+ }
+
+ /**
+ * What a failing store check says: what to do, why it matters and what was found, the fix line,
+ * and where to fix it. A setup step is worded as in Status; a scanned check takes its copy from
+ * ReadinessCopy, or from the report for a check that has none there.
+ *
+ * @param array{id:string,name:string,label?:string,why:string,fix?:string,fix_url:string,conflict?:bool} $check Store check.
+ * @return array{title:string,text:string,fix:string,url:string,link?:string}
+ */
+ private static function failing_copy( array $check ): array {
+ if ( self::is_setup_step( $check ) ) {
+ $action = self::check_action( $check );
+ return array(
+ 'title' => $action[0],
+ 'text' => $action[1],
+ 'fix' => $action[4],
+ 'url' => $action[2],
+ 'link' => $action[3],
+ );
+ }
+ $copy = ReadinessCopy::store_check( $check['id'], (string) ( $check['source'] ?? '' ) );
+ if ( null !== $copy ) {
+ return array(
+ 'title' => $copy['action'],
+ 'text' => $copy['found'],
+ 'fix' => $copy['fix'],
+ 'url' => '' !== $copy['url'] ? $copy['url'] : $check['fix_url'],
+ );
+ }
+ return array(
+ 'title' => '' !== ( $check['label'] ?? '' ) ? (string) $check['label'] : $check['name'],
+ 'text' => $check['why'],
+ 'fix' => (string) ( $check['fix'] ?? '' ),
+ 'url' => $check['fix_url'],
+ );
+ }
+
+ /**
+ * Whether a failing store check blocks every sale, so it is marked Required: a required setup step,
+ * a scanned check that keeps AI assistants off the store's pages, or one in REQUIRED_SCANNED.
+ *
+ * @param array{id:string,blocks:string,group?:string,level:string,conflict?:bool} $check Store check.
+ */
+ private static function is_required( array $check ): bool {
+ if ( self::is_setup_step( $check ) ) {
+ return StoreConditions::shows_required( $check );
+ }
+ return RemoteRules::store_check( $check['id'] )['required'] ?? ( in_array( $check['id'], self::REQUIRED_SCANNED, true ) || ( 'listing' === $check['blocks'] && 'access' === ( $check['group'] ?? '' ) ) );
+ }
+
+ /**
+ * Whether a store check joins Fix first when it fails: it is Required or keeps products from being
+ * listed. The rest are store-wide problems with no sales to rank by.
+ *
+ * @param array{id:string,blocks:string,group?:string,level:string,conflict?:bool} $check Store check.
+ */
+ private static function joins_fix_first( array $check ): bool {
+ return self::is_required( $check ) || 'listing' === $check['blocks'];
+ }
+
+ /**
+ * The Required badge.
+ *
+ * @return array{0:string,1:string} Badge class and text.
+ */
+ private static function required_badge(): array {
+ return array( 'fix', __( 'Required', 'woocommerce' ) );
+ }
+
+ /**
+ * When the last check ran: "today at 10:42", or the date for an older one.
+ *
+ * @param array<string, mixed>|null $report Stored report.
+ */
+ private static function last_checked( ?array $report ): string {
+ $time = null === $report ? false : strtotime( (string) ( $report['generated_at'] ?? '' ) );
+ if ( ! $time ) {
+ return __( 'Not checked yet', 'woocommerce' );
+ }
+ if ( wp_date( 'Y-m-d', $time ) === wp_date( 'Y-m-d' ) ) {
+ /* translators: %s: time of day, such as 10:42 am. */
+ return sprintf( __( 'Last checked today at %s', 'woocommerce' ), wp_date( (string) get_option( 'time_format' ), $time ) );
+ }
+ /* translators: %s: date and time, such as November 3, 2026 10:42 am. */
+ return sprintf( __( 'Last checked %s', 'woocommerce' ), wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time ) );
+ }
+
+
+ /**
+ * The store checks the page shows: the setup steps (UCP itself is the switch, so not a step),
+ * then the scanned checks. With UCP off nothing is served, so the scanned UCP checks are left
+ * out; a check whose prerequisite failed can't say anything, and checks waiting on a later
+ * update (`pending`) aren't shown or counted.
+ *
+ * @param array<string, mixed>|null $report Stored report, or null before the first scan.
+ * @param array<int, array{id:string,ok:bool,blocks:string,level:string,name:string,label:string,why:string,fix:string,fix_url:string}> $checks Store conditions.
+ * @return array<int, array{id:string,ok:bool|null,blocks:string,group?:string,level:string,name:string,label?:string,why:string,fix:string,fix_url:string,conflict?:bool,pending?:bool,seen_at?:string}>
+ */
+ private function visible_store_checks( ?array $report, array $checks ): array {
+ $scanned = array_slice( $this->agent_readiness->get_store_checks( $report, $checks ), count( $checks ) );
+ $results = array_column( $scanned, 'ok', 'id' );
+ $setup = array_filter( $checks, static fn( array $check ): bool => 'ucp_on' !== $check['id'] );
+ $steps = array_column( $checks, 'ok', 'id' );
+ return array_merge(
+ self::setup_order( $setup ),
+ array_filter(
+ $scanned,
+ static function ( array $check ) use ( $results, $steps ): bool {
+ if ( ! empty( $check['pending'] ) || ( ! UcpUtils::is_enabled() && 'ucp' === $check['blocks'] ) ) {
+ return false;
+ }
+ if ( false === ( $steps[ self::SAME_CAUSE[ $check['id'] ] ?? '' ] ?? null ) ) {
+ return false;
+ }
+ $needs = self::CHECK_NEEDS[ $check['id'] ] ?? null;
+ return null === $needs || false !== ( $results[ $needs ] ?? null );
+ }
+ )
+ );
+ }
+
+ /**
+ * Failing product checks from the report, without the ones this page leaves out.
+ *
+ * @param array<string, mixed>|null $report Stored report.
+ * @return array<int, array<string, mixed>>
+ */
+ private static function failing_product_checks( ?array $report ): array {
+ return array_values(
+ array_filter(
+ is_array( $report['checks'] ?? null ) ? $report['checks'] : array(),
+ static fn( $check ): bool => is_array( $check ) && (int) ( $check['count'] ?? 0 ) > 0 && ! in_array( $check['id'] ?? '', self::HIDDEN_PRODUCT_CHECKS, true )
+ )
+ );
+ }
+
+ /**
+ * The product question: how many products each channel can list, then each failing product
+ * check with what to do and a link to its products.
+ *
+ * @param array<string, mixed> $report Stored report.
+ * @return array<string, mixed>
+ */
+ private function product_section( array $report ): array {
+ $failing = self::failing_product_checks( $report );
+ $channels = array_filter( is_array( $report['channels'] ?? null ) ? $report['channels'] : array(), 'is_array' );
+ $linked = ! empty( $report['failures_stored'] );
+ $rows = array();
+ foreach ( $failing as $check ) {
+ $issue = self::product_issue( $check, $linked );
+ $rows[] = self::row( (string) ( $check['id'] ?? '' ), 'open', $issue['title'], $issue['why'], $issue['fix'], self::products_link( (int) $check['count'], (string) ( $check['id'] ?? '' ), $linked ) );
+ }
+ $listed = array();
+ foreach ( $channels as $channel_id => $channel ) {
+ $listed[] = array(
+ 'name' => (string) ( $channel['name'] ?? $channel_id ),
+ 'listable' => number_format_i18n( (int) ( $channel['listable'] ?? 0 ) ),
+ /* translators: %s: number of products checked. */
+ 'of' => sprintf( __( 'of %s can be listed', 'woocommerce' ), number_format_i18n( (int) ( $report['products'] ?? 0 ) ) ),
+ );
+ }
+ return array(
+ 'id' => 'products',
+ 'title' => self::products_question(),
+ 'badge' => self::badge_data( array() === $failing ? array( 'info', __( 'All passed', 'woocommerce' ) ) : self::group_badge( array_fill( 0, count( $failing ), array( 'ok' => false ) ) ) ),
+ 'note' => null,
+ 'channels' => $listed,
+ 'rows' => $rows,
+ 'folded' => array(),
+ 'empty' => array() === $failing ? array(
+ 'title' => __( 'Every product passed every check.', 'woocommerce' ),
+ 'text' => '',
+ 'link' => null,
+ ) : null,
+ );
+ }
+
+ /**
+ * A product card when the scan checked nothing: an empty store, or products it cannot read yet.
+ *
+ * @param string $id Section id.
+ * @param string $title Section title.
+ * @param bool $unreadable True when the store has products, but only hidden or unsupported ones.
+ * @return array<string, mixed>
+ */
+ private static function no_products_section( string $id, string $title, bool $unreadable = false ): array {
+ return array(
+ 'id' => $id,
+ 'title' => $title,
+ 'badge' => self::badge_data( array( 'off', $unreadable ? __( 'Not checked', 'woocommerce' ) : __( 'No products', 'woocommerce' ) ) ),
+ 'note' => null,
+ 'channels' => array(),
+ 'rows' => array(),
+ 'folded' => array(),
+ 'empty' => $unreadable ? array(
+ 'title' => __( 'None of your products can be checked yet', 'woocommerce' ),
+ 'text' => __( 'They are hidden from the catalog, or a type AI assistants can’t list yet.', 'woocommerce' ),
+ 'link' => array(
+ 'href' => AgenticCommerceSettings::url( AgenticCommerceSettings::SHOPPING_SECTION ) . '#wc-agentic-commerce-visibility',
+ 'text' => __( 'View product visibility', 'woocommerce' ),
+ ),
+ ) : array(
+ 'title' => __( 'You don’t have any products yet', 'woocommerce' ),
+ 'text' => __( 'Product checks start once you add products.', 'woocommerce' ),
+ 'link' => array(
+ 'href' => admin_url( 'post-new.php?post_type=product' ),
+ 'text' => __( 'Add a product', 'woocommerce' ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * Whether a scan ran none of these checks, and none is still waiting for one: the store showed
+ * its coming soon page, or its host stopped it from opening its own pages.
+ *
+ * @param array<int, array{ok:bool|null,pending?:bool}> $checks The question's checks.
+ */
+ private static function none_ran( array $checks ): bool {
+ return array() !== $checks && array() === array_filter( $checks, static fn( array $check ): bool => null !== $check['ok'] || ! empty( $check['pending'] ) );
+ }
+
+ /**
+ * The row that stands in for a question's scanned checks when none of them could run, saying why.
+ *
+ * @param bool $launched Whether the store is launched.
+ * @return array<string, mixed>
+ */
+ private static function cant_check_row( bool $launched ): array {
+ return self::row(
+ 'cant_check',
+ 'unknown',
+ __( 'We couldn’t check your pages', 'woocommerce' ),
+ $launched ? __( 'Your host stopped the store from opening its own pages. Try again later, or ask your host.', 'woocommerce' ) : __( 'They show your coming soon page until the store is live.', 'woocommerce' )
+ );
+ }
+
+ /**
+ * One check row for the React views.
+ *
+ * @param string $id The check's id.
+ * @param string $state open, required, unknown or pass.
+ * @param string $title Title: what to do while it fails.
+ * @param string $text Why it matters, and what was found while it fails.
+ * @param string $fix What to do, or '' when the title says it.
+ * @param array{href:string,text:string}|null $link Where to fix it, or the products it affects.
+ * @param array{0:string,1:string}|null $badge Badge class and text: Required, or Likely conflict.
+ * @param array{href:string,text:string}|null $seen_at The page a conflict was seen on.
+ * @return array<string, mixed>
+ */
+ private static function row( string $id, string $state, string $title, string $text, string $fix = '', ?array $link = null, ?array $badge = null, ?array $seen_at = null ): array {
+ return array(
+ 'id' => $id,
+ 'state' => $state,
+ 'title' => $title,
+ 'badge' => null === $badge ? null : self::badge_data( $badge ),
+ 'text' => trim( $text ),
+ 'fix' => trim( $fix ),
+ 'link' => $link,
+ 'seen_at' => $seen_at,
+ );
+ }
+
+ /**
+ * Fix first: the required steps that fail, then the top FIX_FIRST_ISSUES other issues, ranked by
+ * what they stop (listing, then findability) and, within that, by the share of sales on the
+ * products they affect, then by how many products, then in page order.
+ *
+ * @param array<int, array{id:string,ok:bool|null,blocks:string,group?:string,level:string,name:string,label?:string,why:string,fix:string,fix_url:string,conflict?:bool,pending?:bool,seen_at?:string}> $checks Store checks shown on the page.
+ * @param array<string, mixed> $report Stored report.
+ * @return array<int, array{id:string,tier:int,title:string,why:string,link:array{href:string,text:string}|null,share:float|null,rank:float,count:int}>
+ */
+ private function fix_first_items( array $checks, array $report ): array {
+ $required = array();
+ $issues = array();
+ foreach ( $checks as $check ) {
+ if ( false !== $check['ok'] ) {
+ continue;
+ }
+ if ( ! self::joins_fix_first( $check ) ) {
+ continue;
+ }
+ $copy = self::failing_copy( $check );
+ $is_required = self::is_required( $check );
+ $item = array(
+ 'id' => $check['id'],
+ 'tier' => $is_required ? 0 : 2,
+ 'title' => $copy['title'],
+ 'why' => $copy['text'],
+ 'link' => self::fix_link( $copy['url'], $copy['link'] ?? '' ),
+ 'share' => null,
+ // A store-wide issue affects every product, so it ranks as all sales.
+ 'rank' => 1.0,
+ 'count' => PHP_INT_MAX,
+ );
+ if ( $is_required ) {
+ $required[] = $item;
+ } else {
+ $issues[] = $item;
+ }
+ }
+ $linked = ! empty( $report['failures_stored'] );
+ foreach ( self::failing_product_checks( $report ) as $check ) {
+ $blocks_listing = in_array( ReadinessRule::EFFECT_NOT_LISTABLE, array_column( (array) ( $check['channels'] ?? array() ), 'effect' ), true );
+ $share = is_numeric( $check['sales_share'] ?? null ) ? (float) $check['sales_share'] : null;
+ // A share dropped because the count changed since the scan still ranks, so fixing one product doesn't move the issue down.
+ $rank = $share ?? ( is_numeric( $check['ranked_share'] ?? null ) ? (float) $check['ranked_share'] : 0.0 );
+ $count = (int) $check['count'];
+ $issue = self::product_issue( $check, $linked );
+ $issues[] = array(
+ 'id' => (string) ( $check['id'] ?? '' ),
+ 'tier' => $blocks_listing ? 2 : 3,
+ 'title' => $issue['title'],
+ 'why' => $issue['why'],
+ 'link' => self::products_link( $count, (string) ( $check['id'] ?? '' ), $linked ),
+ 'share' => $share,
+ 'rank' => $rank,
+ 'count' => $count,
+ );
+ }
+ // Tier first, then the larger share of sales, then more products, then page order (usort isn't stable before PHP 8).
+ $order = array_flip( array_keys( $issues ) );
+ uksort( $issues, static fn( int $a, int $b ): int => array( $issues[ $a ]['tier'], $issues[ $b ]['rank'], $issues[ $b ]['count'], $order[ $a ] ) <=> array( $issues[ $b ]['tier'], $issues[ $a ]['rank'], $issues[ $a ]['count'], $order[ $b ] ) );
+ return array_merge( $required, array_slice( $issues, 0, self::FIX_FIRST_ISSUES ) );
+ }
+
+ /**
+ * The Fix first card: items under a heading for what each group of issues stops, with a line on
+ * how it is ranked. A product issue's line starts with its share of sales. Null when there is
+ * nothing to fix.
+ *
+ * @param array<int, array{id:string,ok:bool|null,blocks:string,group?:string,level:string,name:string,label?:string,why:string,fix:string,fix_url:string,conflict?:bool,pending?:bool,seen_at?:string}> $checks Store checks shown on the page.
+ * @param array<string, mixed> $report Stored report.
+ * @return array{title:string,ranking:string,items:array<int, array{id:string,tier:string,badge:array{intent:string,text:string}|null,title:string,why:string,link:array{href:string,text:string}|null}>}|null
+ */
+ private function fix_first( array $checks, array $report ): ?array {
+ $items = $this->fix_first_items( $checks, $report );
+ if ( array() === $items ) {
+ return null;
+ }
+ $tiers = array(
+ 0 => __( 'Required for AI shopping', 'woocommerce' ),
+ 2 => __( 'Needed to list products', 'woocommerce' ),
+ 3 => __( 'Helps shoppers find products', 'woocommerce' ),
+ );
+ $days = (int) ( is_array( $report['sales'] ?? null ) ? ( $report['sales']['days'] ?? 0 ) : 0 );
+ $first = true;
+ $list = array();
+ foreach ( $items as $item ) {
+ $why = $item['why'];
+ if ( null !== $item['share'] ) {
+ // The first share says over which period; the rest only give the share.
+ $why = trim( self::sales_text( $item['share'], $first ? $days : 0 ) . ' ' . $why );
+ $first = false;
+ }
+ $list[] = array(
+ 'id' => $item['id'],
+ 'tier' => $tiers[ $item['tier'] ],
+ 'badge' => 0 === $item['tier'] ? self::badge_data( self::required_badge() ) : null,
+ 'title' => $item['title'],
+ 'why' => $why,
+ 'link' => $item['link'],
+ );
+ }
+ return array(
+ 'title' => __( 'Fix first', 'woocommerce' ),
+ 'ranking' => self::ranking_text( $report, $items ),
+ 'items' => $list,
+ );
+ }
+
+ /**
+ * How Fix first is ranked, and what the sales shares compare. Sales are named only when an issue
+ * on the card has sales to compare.
+ *
+ * @param array<string, mixed> $report Stored report.
+ * @param array<int, array{share:float|null}> $items Fix first items.
+ */
+ private static function ranking_text( array $report, array $items ): string {
+ // A report from before sales were read has no `sales` key; the next check fills it in.
+ if ( ! array_key_exists( 'sales', $report ) ) {
+ return __( 'Ranked by how many products each issue affects.', 'woocommerce' );
+ }
+ $sales = is_array( $report['sales'] ) ? $report['sales'] : null;
+ if ( null === $sales ) {
+ return __( 'Ranked by how many products each issue affects. Turn on Analytics to rank by sales instead.', 'woocommerce' );
+ }
+ if ( false === ( $sales['imported'] ?? true ) ) {
+ return __( 'Analytics hasn\'t imported all your past orders yet, so issues are ranked by how many products they affect. Import them in Analytics > Settings.', 'woocommerce' );
+ }
+ $orders = (int) ( $sales['orders'] ?? 0 );
+ $days = (int) ( $sales['days'] ?? 0 );
+ if ( 0 === $orders ) {
+ /* translators: %d: number of days. */
+ return sprintf( _n( 'No sales in the last %d day, so issues are ranked by how many products they affect.', 'No sales in the last %d days, so issues are ranked by how many products they affect.', $days, 'woocommerce' ), $days );
+ }
+ if ( $orders < ProductSales::MIN_ORDERS ) {
+ return sprintf(
+ /* translators: 1: number of orders, 2: number of days. */
+ _n( 'Only %1$s order in the last %2$d days, too few to rank by sales, so issues are ranked by how many products they affect.', 'Only %1$s orders in the last %2$d days, too few to rank by sales, so issues are ranked by how many products they affect.', $orders, 'woocommerce' ),
+ number_format_i18n( $orders ),
+ $days
+ );
+ }
+ // No issue on the card with sales: the products sold nothing, store-wide issues filled the card, or counts changed since the check.
+ if ( array() === array_filter( $items, static fn( array $item ): bool => ( $item['share'] ?? 0.0 ) > 0.0 ) ) {
+ return __( 'Ranked by how many products each issue affects.', 'woocommerce' );
+ }
+ /* translators: %d: number of days. */
+ return sprintf( _n( 'Start with the fixes that affect the most sales. Sales figures are from the last %d day.', 'Start with the fixes that affect the most sales. Sales figures are from the last %d days.', $days, 'woocommerce' ), $days );
+ }
+
+ /**
+ * "18% of your sales in the last 90 days.", or "18% of your sales." without the period.
+ *
+ * @param float $share Share of sales, from 0 to 1.
+ * @param int $days Days the share covers, or 0 to leave the period out.
+ */
+ private static function sales_text( float $share, int $days ): string {
+ if ( 0.0 === $share ) {
+ /* translators: %d: number of days. */
+ return $days > 0 ? sprintf( __( 'No sales in the last %d days.', 'woocommerce' ), $days ) : __( 'No sales.', 'woocommerce' );
+ }
+ if ( $days > 0 ) {
+ /* translators: 1: share of sales, such as 18%, 2: number of days. */
+ return sprintf( __( '%1$s of your sales in the last %2$d days.', 'woocommerce' ), self::percent( $share ), $days );
+ }
+ /* translators: %s: share of sales, such as 18%. */
+ return sprintf( __( '%s of your sales.', 'woocommerce' ), self::percent( $share ) );
+ }
+
+
+ /**
+ * A share as a whole percentage; under 1% but above none reads "under 1%".
+ *
+ * @param float $share Share from 0 to 1.
+ */
+ private static function percent( float $share ): string {
+ if ( $share > 0 && $share < 0.005 ) {
+ return __( 'under 1%', 'woocommerce' );
+ }
+ /* translators: %s: a whole number percentage. */
+ return sprintf( __( '%s%%', 'woocommerce' ), number_format_i18n( (int) round( $share * 100 ) ) );
+ }
+
+ /**
+ * "View N products", linked to the Products list filtered to them when each product's failures
+ * are stored; "N products" with no link otherwise.
+ *
+ * @param int $count Number of products.
+ * @param string $value Stored failure value.
+ * @param bool $linked Whether the list can be filtered.
+ * @return array{href:string,text:string}
+ */
+ private static function products_link( int $count, string $value, bool $linked ): array {
+ if ( ! $linked ) {
+ return array(
+ 'href' => '',
+ /* translators: %s: number of products. */
+ 'text' => sprintf( _n( '%s product', '%s products', $count, 'woocommerce' ), number_format_i18n( $count ) ),
+ );
+ }
+ return array(
+ 'href' => ProductsList::url( $value ),
+ /* translators: %s: number of products. */
+ 'text' => sprintf( _n( 'View %s product', 'View %s products', $count, 'woocommerce' ), number_format_i18n( $count ) ),
+ );
+ }
+
+ /**
+ * A failing product check's copy: what to do ("Add a brand to 13 products"), why it matters, and the
+ * fix line. A check ReadinessCopy has no copy for keeps the report's.
+ *
+ * @param array<string, mixed> $check Failing product check from the report.
+ * @param bool $linked Whether each product's failures are stored, so a few failing products can be named.
+ * @return array{title:string,why:string,fix:string}
+ */
+ private static function product_issue( array $check, bool $linked ): array {
+ $count = (int) ( $check['count'] ?? 0 );
+ $id = (string) ( $check['id'] ?? '' );
+ $names = $count <= ReadinessCopy::NAMED_MAX && $linked ? self::failing_product_names( $id ) : array();
+ $copy = ReadinessCopy::product_check( $id, $count, $names );
+ if ( null === $copy ) {
+ return array(
+ 'title' => (string) ( $check['label'] ?? '' ),
+ 'why' => (string) ( $check['why'] ?? '' ),
+ 'fix' => (string) ( $check['fix'] ?? '' ),
+ );
+ }
+ return array(
+ 'title' => $copy['action'],
+ 'why' => $copy['why'],
+ 'fix' => $copy['fix'],
+ );
+ }
+
+ /**
+ * Names of the products that fail a check, from their stored failures: up to one more than
+ * ReadinessCopy::NAMED_MAX, so a count that changed since the scan doesn't match and the title
+ * falls back to the count.
+ *
+ * @param string $check_id Check id.
+ * @return string[]
+ */
+ private static function failing_product_names( string $check_id ): array {
+ $posts = get_posts(
+ array(
+ 'post_type' => 'product',
+ 'post_status' => 'any',
+ 'posts_per_page' => ReadinessCopy::NAMED_MAX + 1,
+ 'no_found_rows' => true,
+ 'suppress_filters' => true,
+ 'meta_key' => ProductFailures::META_KEY, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
+ 'meta_value' => $check_id, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
+ )
+ );
+ return array_map(
+ static fn( \WP_Post $post ): string => html_entity_decode( wp_strip_all_tags( get_the_title( $post ) ), ENT_QUOTES, 'UTF-8' ),
+ $posts
+ );
+ }
+
+ /**
+ * Protocols and files the store serves to agents, as information, never pass or fail: how many were
+ * found, then every item. Null with no items in the report.
+ *
+ * @param array $items Items from the report.
+ * @return array{title:string,badge:array{intent:string,text:string},text:string,items:array<int, array{name:string,found:bool}>}|null
+ */
+ private static function declared( array $items ): ?array {
+ $items = array_values( array_filter( $items, 'is_array' ) );
+ if ( array() === $items ) {
+ return null;
+ }
+ $found = array_filter( $items, static fn( array $item ): bool => true === ( $item['found'] ?? null ) );
+ return array(
+ 'title' => __( 'What does your store share with AI assistants?', 'woocommerce' ),
+ 'badge' => self::badge_data( array( 'off', __( 'Optional', 'woocommerce' ) ) ),
+ 'text' => sprintf(
+ /* translators: %s: how many items were found, such as "Found 4 of 33". */
+ __( 'Optional files that some AI assistants look for. You don’t need to fix anything. %s.', 'woocommerce' ),
+ /* translators: 1: number of items found, 2: number of items looked for. */
+ sprintf( __( 'Found %1$s of %2$s', 'woocommerce' ), number_format_i18n( count( $found ) ), number_format_i18n( count( $items ) ) )
+ ),
+ 'items' => array_map(
+ static fn( array $item ): array => array(
+ 'name' => (string) ( $item['name'] ?? '' ),
+ 'found' => true === ( $item['found'] ?? null ),
+ ),
+ $items
+ ),
+ );
+ }
+
+ /**
+ * The badge on a question: how many issues, or that everything passed. A check that
+ * couldn't run isn't an issue.
+ *
+ * @param array<int, array{ok:bool|null}> $checks The question's checks.
+ * @return array{0:string,1:string} Badge class and text.
+ */
+ private static function group_badge( array $checks ): array {
+ $issues = count( array_filter( $checks, static fn( array $check ): bool => false === $check['ok'] ) );
+ if ( $issues > 0 ) {
+ /* translators: %d: number of issues. */
+ return array( 'check', sprintf( _n( '%d issue', '%d issues', $issues, 'woocommerce' ), $issues ) );
+ }
+ $passed = count( array_filter( $checks, static fn( array $check ): bool => true === $check['ok'] ) );
+ if ( 0 === $passed ) {
+ return array( 'off', __( 'Not checked yet', 'woocommerce' ) );
+ }
+ return count( $checks ) === $passed ? array( 'info', __( 'All passed', 'woocommerce' ) ) : array( 'off', __( 'No issues', 'woocommerce' ) );
+ }
+
+ /**
+ * Store checks as rows. A failing check is headed by what to do, then why it matters and what was
+ * found, the fix line when there is one, and a link when WooCommerce has a screen for it; a check
+ * that blocks every sale is marked Required. One that couldn't run says why; a passed one keeps its
+ * passing title and why it matters.
+ *
+ * @param array<int, array{id:string,ok:bool|null,blocks:string,level:string,name:string,label?:string,why:string,fix:string,fix_url:string,conflict?:bool,seen_at?:string}> $checks Checks.
+ * @param bool|null $launched Whether the store is launched.
+ * @return array<int, array<string, mixed>>
+ */
+ private static function check_rows( array $checks, ?bool $launched ): array {
+ $rows = array();
+ foreach ( $checks as $check ) {
+ $copy = self::is_setup_step( $check ) ? null : ReadinessCopy::store_check( $check['id'] );
+ if ( null === $check['ok'] ) {
+ $rows[] = self::row( $check['id'], 'unknown', $copy['title'] ?? $check['name'], $launched ? __( 'This couldn\'t be checked. The next check tries again.', 'woocommerce' ) : __( 'Launch your store to run this check.', 'woocommerce' ) );
+ continue;
+ }
+ if ( $check['ok'] ) {
+ // A setup step's why describes the failure, so a passed one shows only its name, as in Status.
+ $rows[] = self::row( $check['id'], 'pass', $copy['title'] ?? $check['name'], $copy['why'] ?? '' );
+ continue;
+ }
+ $failing = self::failing_copy( $check );
+ $required = self::is_required( $check );
+ $conflict = ! empty( $check['conflict'] );
+ // The URL comes from the stored report, so only http(s) links reach the page.
+ $seen_url = $conflict && ! empty( $check['seen_at'] ) ? esc_url_raw( (string) $check['seen_at'], array( 'http', 'https' ) ) : '';
+ $seen_at = '' !== $seen_url
+ ? array(
+ 'href' => $seen_url,
+ 'text' => (string) $check['seen_at'],
+ )
+ : null;
+ $badge = $required ? self::required_badge() : ( $conflict ? array( 'off', __( 'Likely conflict', 'woocommerce' ) ) : null );
+ $rows[] = self::row( $check['id'], $required ? 'required' : 'open', $failing['title'], $failing['text'], $failing['fix'], self::fix_link( $failing['url'], $failing['link'] ?? '' ), $badge, $seen_at );
+ }
+ return $rows;
+ }
+
+ /**
+ * A failing check's fix link: where it goes, or null without a URL.
+ *
+ * @param string $url Fix URL.
+ * @param string $text Link text, or '' to name where the URL goes.
+ * @return array{href:string,text:string}|null
+ */
+ private static function fix_link( string $url, string $text = '' ): ?array {
+ // Scanned checks' URLs come from the stored report, so only http(s) and relative links reach the page.
+ $url = esc_url_raw( $url, array( 'http', 'https' ) );
+ if ( '' === $url ) {
+ return null;
+ }
+ return array(
+ 'href' => $url,
+ 'text' => '' !== $text ? $text : self::fix_link_text( $url ),
+ );
+ }
+
+ /**
+ * The text of a failing check's fix link: where it goes.
+ *
+ * @param string $url Fix URL.
+ */
+ private static function fix_link_text( string $url ): string {
+ $targets = array(
+ 'upload.php' => __( 'Go to Media library', 'woocommerce' ),
+ 'post.php' => __( 'Edit page', 'woocommerce' ),
+ 'admin.php?page=wc-settings&tab=site-visibility' => __( 'Change site visibility', 'woocommerce' ),
+ 'options-reading.php' => __( 'Change Reading settings', 'woocommerce' ),
+ 'admin.php?page=wc-settings&tab=account' => __( 'Go to Accounts & Privacy', 'woocommerce' ),
+ 'admin.php?page=wc-settings&tab=checkout' => __( 'Go to Payments', 'woocommerce' ),
+ 'admin.php?page=wc-settings&tab=email' => __( 'Go to Emails', 'woocommerce' ),
+ 'site-health.php' => __( 'View Site Health', 'woocommerce' ),
+ 'plugins.php' => __( 'View plugins', 'woocommerce' ),
+ );
+ foreach ( $targets as $path => $text ) {
+ if ( str_starts_with( $url, admin_url( $path ) ) ) {
+ return $text;
+ }
+ }
+ if ( str_starts_with( $url, AgenticCommerceSettings::url( AgenticCommerceSettings::SHOPPING_SECTION ) . '#' ) ) {
+ return __( 'Choose a page', 'woocommerce' );
+ }
+ return str_starts_with( $url, admin_url() ) ? __( 'Open settings', 'woocommerce' ) : __( 'Learn how', 'woocommerce' );
+ }
+
+ /**
+ * The sections under Fix first: one per merchant question with the checks the last scan ran on
+ * what the store returns, the product checks before the buying question. Inside a section,
+ * problems come first and passed checks are folded.
+ *
+ * @param array<int, array{id:string,ok:bool|null,blocks:string,group?:string,level:string,name:string,label?:string,why:string,fix:string,fix_url:string,conflict?:bool,pending?:bool,seen_at?:string}> $checks Scanned checks to show.
+ * @param bool $launched Whether the store is launched.
+ * @param array<string, mixed> $report Stored report.
+ * @return array<int, array<string, mixed>>
+ */
+ private function sections( array $checks, bool $launched, array $report ): array {
+ $sections = array();
+ // products counts only what the scan can check. Hidden and unsupported products are counted apart, so they are not an empty store.
+ $no_products = isset( $report['products'] ) && 0 === (int) $report['products'];
+ $unreadable = $no_products && ( (int) ( $report['hidden_from_catalog'] ?? 0 ) > 0 || (int) ( $report['unsupported_types'] ?? 0 ) > 0 );
+ foreach ( self::question_groups( $checks ) as $id => $group ) {
+ if ( 'buy' === $id ) {
+ $sections[] = $no_products ? self::no_products_section( 'products', self::products_question(), $unreadable ) : $this->product_section( $report );
+ }
+ if ( $no_products && 'understand' === $id ) {
+ $sections[] = self::no_products_section( $id, $group[0], $unreadable );
+ continue;
+ }
+ // When no scanned check could run, one row says why in their place; setup steps still show.
+ $scanned = array_filter( $group[1], static fn( array $check ): bool => ! self::is_setup_step( $check ) );
+ $cant = array() !== $report && self::none_ran( $scanned );
+ $checks = $cant ? array_diff_key( $group[1], $scanned ) : $group[1];
+ $folded = array_filter( $checks, static fn( array $check ): bool => true === $check['ok'] );
+ $rows = self::check_rows( array_values( array_diff_key( $checks, $folded ) ), $launched );
+ $sections[] = array(
+ 'id' => $id,
+ 'title' => $group[0],
+ 'badge' => self::badge_data( $cant && array() === $rows ? array( 'off', __( 'Couldn’t check', 'woocommerce' ) ) : self::group_badge( $checks ) ),
+ 'note' => 'access' === $id && ! UcpUtils::is_enabled() ? __( 'AI shopping is off, so we didn’t check your connection URL.', 'woocommerce' ) : null,
+ 'channels' => array(),
+ 'rows' => $cant ? array_merge( $rows, array( self::cant_check_row( $launched ) ) ) : $rows,
+ 'folded' => self::check_rows( array_values( $folded ), $launched ),
+ 'empty' => null,
+ );
+ }
+ return $sections;
+ }
+
+ /**
+ * The store checks by the merchant question they answer, with each question's title.
+ *
+ * @param array<int, array{id:string,ok:bool|null,blocks:string,group?:string,level:string,name:string,label?:string,why:string,fix:string,fix_url:string,conflict?:bool,pending?:bool,seen_at?:string}> $checks Scanned checks to show.
+ * @return array<string, array{0:string,1:array<int, array{id:string,ok:bool|null,blocks:string,group?:string,level:string,name:string,label?:string,why:string,fix:string,fix_url:string,conflict?:bool,pending?:bool,seen_at?:string}>}>
+ */
+ private static function question_groups( array $checks ): array {
+ $groups = array(
+ 'access' => array( __( 'Store access', 'woocommerce' ), array() ),
+ 'find' => array( __( 'Can AI assistants find your store?', 'woocommerce' ), array() ),
+ 'understand' => array( __( 'Can AI assistants read your product details?', 'woocommerce' ), array() ),
+ 'buy' => array( __( 'Can shoppers buy through AI assistants?', 'woocommerce' ), array() ),
+ );
+ foreach ( $checks as $check ) {
+ // A report from before checks named their question has no group; the next scan fills it in.
+ if ( isset( $groups[ $check['group'] ?? '' ] ) ) {
+ $groups[ $check['group'] ][1][] = $check;
+ }
+ }
+ return $groups;
+ }
+
+ /**
+ * The product question's title.
+ */
+ private static function products_question(): string {
+ return __( 'Can AI assistants list your products?', 'woocommerce' );
+ }
+}
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCopy.php b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCopy.php
new file mode 100644
index 00000000000..662d65127bc
--- /dev/null
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessCopy.php
@@ -0,0 +1,425 @@
+<?php
+declare( strict_types = 1 );
+
+namespace Automattic\WooCommerce\Internal\AgentReadiness;
+
+defined( 'ABSPATH' ) || exit;
+
+/**
+ * What Sales readiness says about each check, by check id. A failing check is headed by what to do
+ * ("Add an llms.txt file"), then why it matters and what the scan found, then the fix line, which every
+ * store check has so a failed row always says where to look, and a link only when WooCommerce has a screen for it.
+ * Reports keep the copy the scan stored, so the page reads it from here and falls back to the report
+ * for a check this class doesn't name.
+ *
+ * @since 11.4.0
+ */
+final class ReadinessCopy {
+
+ /**
+ * Up to how many failing products a fix title names; more are given as a count.
+ */
+ public const NAMED_MAX = 3;
+
+
+ /**
+ * A store check's copy.
+ *
+ * @param string $id Check id.
+ * @param string $source What the store serves for the check (the report's source), or ''.
+ * @return array{title:string,action:string,why:string,found:string,fix:string,url:string}|null Passed title, failing title, why it matters (shown when passed), why and what was found (shown when failing), the fix line or '', and where to fix it or ''. Null for a check without copy here.
+ */
+ public static function store_check( string $id, string $source = '' ): ?array {
+ $checks = self::store_checks();
+ if ( ! isset( $checks[ $id ] ) ) {
+ return null;
+ }
+ $check = $checks[ $id ];
+ if ( 'ucp_profile_version' === $id && '' !== $source ) {
+ /* translators: %s: UCP version the store serves, a date such as 2026-04-08. */
+ $check[3] = sprintf( __( 'Your store uses an older version of the Universal Commerce Protocol (UCP %s).', 'woocommerce' ), $source );
+ }
+ return array(
+ 'title' => $check[0],
+ 'action' => $check[1],
+ 'why' => $check[2],
+ 'found' => $check[3],
+ 'fix' => $check[4] ?? '',
+ 'url' => $check[5] ?? '',
+ );
+ }
+
+ /**
+ * A failing product check's copy: what to do, why it matters, and the fix line. With up to three
+ * products the title names them ("Add a brand to Blue hoodie and Red cap"); one product without a
+ * known name is "a product".
+ *
+ * @param string $id Check id.
+ * @param int $count Number of products.
+ * @param string[] $names Names of the failing products when known, or none.
+ * @return array{action:string,why:string,fix:string}|null Null for a check without copy here.
+ */
+ public static function product_check( string $id, int $count, array $names = array() ): ?array {
+ $n = number_format_i18n( $count );
+ switch ( $id ) {
+ case 'missing_brand':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Add a brand to %s', 'Add a brand to %s', $count, 'woocommerce' ), __( 'Add a brand to a product', 'woocommerce' ), sprintf( _n( 'Add a brand to %s product', 'Add a brand to %s products', $count, 'woocommerce' ), $n ) ),
+ __( 'ChatGPT only lists products that have a brand. In Google and Copilot, a brand makes products easier to find.', 'woocommerce' )
+ );
+ case 'missing_gtin':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Add a barcode number to %s', 'Add barcode numbers to %s', $count, 'woocommerce' ), __( 'Add a barcode number to a product', 'woocommerce' ), sprintf( _n( 'Add a barcode number to %s product', 'Add barcode numbers to %s products', $count, 'woocommerce' ), $n ) ),
+ __( 'Barcode numbers, like a UPC, EAN, or ISBN, help AI assistants match your products to what shoppers search for.', 'woocommerce' ),
+ __( 'Use the number from the packaging or supplier. Never make one up.', 'woocommerce' )
+ );
+ case 'invalid_gtin':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Fix the barcode number of %s', 'Fix the barcode numbers of %s', $count, 'woocommerce' ), __( 'Fix the barcode number of a product', 'woocommerce' ), sprintf( _n( 'Fix the barcode number of %s product', 'Fix the barcode numbers of %s products', $count, 'woocommerce' ), $n ) ),
+ __( 'Google doesn’t list products with a barcode number that isn’t valid. In ChatGPT and Copilot, a valid one makes products easier to find.', 'woocommerce' ),
+ __( 'A barcode number has 8, 12, 13 or 14 digits. Use the number from the packaging or supplier.', 'woocommerce' )
+ );
+ case 'duplicate_gtin':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Give %s its own barcode number', 'Give %s their own barcode numbers', $count, 'woocommerce' ), __( 'Give a product its own barcode number', 'woocommerce' ), sprintf( _n( 'Give %s product its own barcode number', 'Give %s products their own barcode numbers', $count, 'woocommerce' ), $n ) ),
+ __( 'Products that share a barcode number look like one product, so AI assistants may show the wrong one.', 'woocommerce' )
+ );
+ case 'missing_regular_price':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Add a price to %s', 'Add a price to %s', $count, 'woocommerce' ), __( 'Add a price to a product', 'woocommerce' ), sprintf( _n( 'Add a price to %s product', 'Add a price to %s products', $count, 'woocommerce' ), $n ) ),
+ __( 'AI assistants only list products that have a price.', 'woocommerce' )
+ );
+ case 'missing_images':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Add a main image to %s', 'Add a main image to %s', $count, 'woocommerce' ), __( 'Add a main image to a product', 'woocommerce' ), sprintf( _n( 'Add a main image to %s product', 'Add a main image to %s products', $count, 'woocommerce' ), $n ) ),
+ __( 'AI assistants only list products that have a main image.', 'woocommerce' )
+ );
+ case 'image_too_small':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Use a larger main image on %s', 'Use a larger main image on %s', $count, 'woocommerce' ), __( 'Use a larger main image on a product', 'woocommerce' ), sprintf( _n( 'Use a larger main image on %s product', 'Use a larger main image on %s products', $count, 'woocommerce' ), $n ) ),
+ __( 'Google asks for images of at least 500 x 500 pixels.', 'woocommerce' )
+ );
+ case 'missing_product_text':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Add a description to %s', 'Add a description to %s', $count, 'woocommerce' ), __( 'Add a description to a product', 'woocommerce' ), sprintf( _n( 'Add a description to %s product', 'Add a description to %s products', $count, 'woocommerce' ), $n ) ),
+ __( 'ChatGPT only lists products that have a description. In Google and Copilot, a description makes products easier to find.', 'woocommerce' )
+ );
+ case 'uncategorised':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Choose a category for %s', 'Choose a category for %s', $count, 'woocommerce' ), __( 'Choose a category for a product', 'woocommerce' ), sprintf( _n( 'Choose a category for %s product', 'Choose a category for %s products', $count, 'woocommerce' ), $n ) ),
+ __( 'AI assistants narrow a search by category first, so products with only the default category are harder to find.', 'woocommerce' )
+ );
+ case 'variation_attributes_not_set':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Choose an option for each variation of %s', 'Choose an option for each variation of %s', $count, 'woocommerce' ), __( 'Choose an option for each variation of a product', 'woocommerce' ), sprintf( _n( 'Choose an option for each variation of %s product', 'Choose an option for each variation of %s products', $count, 'woocommerce' ), $n ) ),
+ __( 'Variations need a specific option, like “Small” instead of “Any size,” to be listed on their own.', 'woocommerce' )
+ );
+ case 'missing_variation_images':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Add an image to each variation of %s', 'Add an image to each variation of %s', $count, 'woocommerce' ), __( 'Add an image to each variation of a product', 'woocommerce' ), sprintf( _n( 'Add an image to each variation of %s product', 'Add an image to each variation of %s products', $count, 'woocommerce' ), $n ) ),
+ __( 'Each variation is listed on its own. Without its own image, it shows the main image, which may not match its color.', 'woocommerce' )
+ );
+ case 'title_too_long':
+ return self::product(
+ /* translators: %s: names of up to three products, such as "Blue hoodie and Red cap", or number of products. */
+ self::title( $count, $names, _n( 'Shorten the title of %s', 'Shorten the titles of %s', $count, 'woocommerce' ), __( 'Shorten the title of a product', 'woocommerce' ), sprintf( _n( 'Shorten the title of %s product', 'Shorten the titles of %s products', $count, 'woocommerce' ), $n ) ),
+ __( 'AI assistants cut titles over 150 characters.', 'woocommerce' ),
+ __( 'Keep the brand and product type first.', 'woocommerce' )
+ );
+ }
+ return null;
+ }
+
+ /**
+ * A fix title: with the products' names when up to NAMED_MAX products fail and every name is
+ * known, "a product" for one without a name, and the count otherwise.
+ *
+ * @param int $count Number of products.
+ * @param string[] $names Names of the failing products, or none.
+ * @param string $named Title with a %s for the names, singular or plural to match the count.
+ * @param string $any Title for one product without its name.
+ * @param string $many Title with the count.
+ */
+ private static function title( int $count, array $names, string $named, string $any, string $many ): string {
+ if ( $count <= self::NAMED_MAX && count( $names ) === $count ) {
+ return sprintf( $named, wp_sprintf_l( '%l', $names ) );
+ }
+ return 1 === $count ? $any : $many;
+ }
+
+ /**
+ * A product check's copy.
+ *
+ * @param string $action What to do.
+ * @param string $why Why it matters.
+ * @param string $fix Fix line, or ''.
+ * @return array{action:string,why:string,fix:string}
+ */
+ private static function product( string $action, string $why, string $fix = '' ): array {
+ return array(
+ 'action' => $action,
+ 'why' => $why,
+ 'fix' => $fix,
+ );
+ }
+
+ /**
+ * Store checks: passed title, failing title, why (passed), why and what was found (failing), then the fix line, and where to fix it when WooCommerce has a screen for it.
+ *
+ * @return array<string, array<int, string>>
+ */
+ private static function store_checks(): array {
+ $plugin_settings = __( 'Look for it in your SEO plugin’s settings.', 'woocommerce' );
+ return array(
+ // Can AI assistants visit your store?
+ 'no_noindex_directives' => array(
+ __( 'Search engines and AI assistants can show your pages', 'woocommerce' ),
+ __( 'Let search engines and AI assistants show your pages', 'woocommerce' ),
+ __( 'AI assistants follow the same rules as search engines to decide which pages they can show.', 'woocommerce' ),
+ __( 'Your store is set to hide its pages from search engines, so AI assistants can’t find them. Check whether “Discourage search engines from indexing this site” is selected.', 'woocommerce' ),
+ __( 'If it isn’t selected, check the robots settings in your SEO plugin, or ask your host.', 'woocommerce' ),
+ admin_url( 'options-reading.php' ),
+ ),
+ 'pages_public' => array(
+ __( 'Store pages open without logging in', 'woocommerce' ),
+ __( 'Let shoppers open store pages without logging in', 'woocommerce' ),
+ __( 'AI assistants don’t log in, so store pages need to be open to everyone.', 'woocommerce' ),
+ __( 'Your store asks everyone to log in before they can see its pages. AI assistants don’t log in, so they can’t see your products.', 'woocommerce' ),
+ __( 'Check your membership, private store or maintenance plugin, which can ask visitors to log in.', 'woocommerce' ),
+ admin_url( 'admin.php?page=wc-settings&tab=site-visibility' ),
+ ),
+ 'ucp_profile' => array(
+ __( 'AI assistants can connect to your store', 'woocommerce' ),
+ __( 'Check why AI assistants can’t connect', 'woocommerce' ),
+ __( 'They use your connection URL to find your products.', 'woocommerce' ),
+ __( 'AI assistants can’t reach your connection URL, so they can’t find your products. Test it in UCP Playground, or ask your host.', 'woocommerce' ),
+ __( 'Save your settings under Settings › Permalinks once. If AI assistants still can’t connect, ask your host whether caching or a firewall blocks your connection URL.', 'woocommerce' ),
+ ),
+ 'ucp_profile_version' => array(
+ __( 'Your store’s connection is up to date', 'woocommerce' ),
+ __( 'Update your store’s connection', 'woocommerce' ),
+ __( 'AI assistants check its version to see what your store supports.', 'woocommerce' ),
+ __( 'Your store uses an older version of the Universal Commerce Protocol (UCP).', 'woocommerce' ),
+ __( 'Another plugin may add its own connection. Turn off AI shopping (also called UCP or agentic commerce) in that plugin, or deactivate it.', 'woocommerce' ),
+ ),
+ 'ucp_endpoints_live' => array(
+ __( 'AI assistants can search your catalog', 'woocommerce' ),
+ __( 'Check why AI assistants can’t search your catalog', 'woocommerce' ),
+ __( 'This is how they find products and add them to a shopper’s cart.', 'woocommerce' ),
+ __( 'AI assistants can’t search your products or add them to carts. A firewall or security plugin can cause this, so check those first or ask your host.', 'woocommerce' ),
+ __( 'Ask your host or security plugin to allow requests to /wp-json/wc/ucp/.', 'woocommerce' ),
+ ),
+ 'ucp_checkout' => array(
+ __( 'AI assistants can send shoppers to your checkout', 'woocommerce' ),
+ __( 'Let AI assistants send shoppers to your checkout', 'woocommerce' ),
+ __( 'Shoppers who build a cart with an AI assistant finish buying on your checkout.', 'woocommerce' ),
+ __( 'Another plugin changed your store’s connection, so AI assistants can’t send shoppers to your checkout. Shoppers can still find your products.', 'woocommerce' ),
+ __( 'Turn off AI shopping (also called UCP or agentic commerce) in the other plugin, or deactivate it.', 'woocommerce' ),
+ ),
+ // Can AI assistants find your store?
+ 'sitemap_lists_products' => array(
+ __( 'A sitemap lists your products', 'woocommerce' ),
+ __( 'Add a sitemap that lists your products', 'woocommerce' ),
+ __( 'Crawlers use the sitemap to find new and changed products.', 'woocommerce' ),
+ __( 'A sitemap is a list of your pages. Crawlers use it to find new and changed products. We found no sitemap that lists your products.', 'woocommerce' ),
+ __( 'Turn on the sitemap in your SEO plugin and include products. Without an SEO plugin, check whether another plugin turns off the WordPress sitemap.', 'woocommerce' ),
+ ),
+ 'llms_txt_present' => array(
+ __( 'Your store has an llms.txt file', 'woocommerce' ),
+ __( 'Add an llms.txt file', 'woocommerce' ),
+ __( 'llms.txt gives AI assistants a short summary of your store and links to its main pages.', 'woocommerce' ),
+ __( 'llms.txt is a short summary of your store with links to its main pages, which AI assistants use to describe your store. We found no file at /llms.txt.', 'woocommerce' ),
+ __( 'Turn it on in your SEO plugin, or add the file to your site’s root folder.', 'woocommerce' ),
+ ),
+ 'llms_txt_valid' => array(
+ __( 'llms.txt starts with your store’s name', 'woocommerce' ),
+ __( 'Start llms.txt with your store’s name', 'woocommerce' ),
+ __( 'AI assistants use it to know whose file they read.', 'woocommerce' ),
+ __( 'AI assistants use the first heading to know whose file they read. We found no “# Store name” heading at the top.', 'woocommerce' ),
+ __( 'Add a first line such as “# Your store name” in your SEO plugin, or in the llms.txt file in your site’s root folder.', 'woocommerce' ),
+ ),
+ 'llms_txt_links_resolve' => array(
+ __( 'Links in llms.txt open', 'woocommerce' ),
+ __( 'Fix the broken links in llms.txt', 'woocommerce' ),
+ __( 'A broken link wastes the visit.', 'woocommerce' ),
+ __( 'A broken link wastes the AI assistant’s visit. We found links in llms.txt that don’t open.', 'woocommerce' ),
+ __( 'Update or remove the broken links in your SEO plugin, or in the llms.txt file in your site’s root folder.', 'woocommerce' ),
+ ),
+ 'open_graph_tags' => array(
+ __( 'Your pages have preview details', 'woocommerce' ),
+ __( 'Add preview details to your pages', 'woocommerce' ),
+ __( 'AI assistants use og:title and og:image to show a page as a card.', 'woocommerce' ),
+ __( 'AI assistants use them (Open Graph tags) to show a page as a card with a title and image. We found pages without them.', 'woocommerce' ),
+ __( 'WooCommerce adds them to product, shop and category pages. For other pages, turn on social or Open Graph tags in your SEO plugin.', 'woocommerce' ),
+ ),
+ 'open_graph_from_core' => array(
+ __( 'Product pages keep WooCommerce’s preview details', 'woocommerce' ),
+ __( 'Restore WooCommerce’s preview details on product pages', 'woocommerce' ),
+ __( 'AI assistants read these tags to show your product with its WooCommerce name, price and image.', 'woocommerce' ),
+ __( 'AI assistants read them (Open Graph tags) to show your product with its WooCommerce name, price and image. We found other values on a recent product page.', 'woocommerce' ),
+ __( 'An SEO, social or caching plugin, or your theme, can change them. Look at its social or Open Graph settings.', 'woocommerce' ),
+ ),
+ 'meta_description' => array(
+ __( 'Store pages have a short description', 'woocommerce' ),
+ __( 'Add a short description to each store page', 'woocommerce' ),
+ __( 'Search engines and AI answers often quote the meta description to say what a page is about.', 'woocommerce' ),
+ __( 'AI answers often quote a page’s short description (meta description) to say what it’s about. We found store pages without one.', 'woocommerce' ),
+ __( 'Add them in your SEO plugin.', 'woocommerce' ),
+ ),
+ 'canonical_url' => array(
+ __( 'Store pages name their main address', 'woocommerce' ),
+ __( 'Tell AI assistants the main address of each page', 'woocommerce' ),
+ __( 'The canonical link tells AI assistants which address to show.', 'woocommerce' ),
+ __( 'When a page has several addresses, the canonical URL tells AI assistants which one to show. We found store pages without one.', 'woocommerce' ),
+ $plugin_settings,
+ ),
+ 'organization_schema' => array(
+ __( 'Your home page has your store’s details', 'woocommerce' ),
+ __( 'Add your store’s name, logo and contact details to your home page', 'woocommerce' ),
+ __( 'Gives AI assistants your store’s name, logo and contact details in one place.', 'woocommerce' ),
+ __( 'AI assistants read them in one place, as organization structured data. We found none on your home page.', 'woocommerce' ),
+ $plugin_settings,
+ ),
+ 'ai_snippet_directives' => array(
+ __( 'AI assistants can quote your pages', 'woocommerce' ),
+ __( 'Let AI assistants quote your pages', 'woocommerce' ),
+ __( 'A nosnippet rule keeps AI answers from quoting your pages.', 'woocommerce' ),
+ __( 'A nosnippet rule keeps AI answers from quoting your pages. We found one on your store pages.', 'woocommerce' ),
+ __( 'Remove nosnippet and max-snippet from the robots settings in your SEO plugin, or ask your host.', 'woocommerce' ),
+ ),
+ 'sitemap_lastmod' => array(
+ __( 'Your sitemap says when pages change', 'woocommerce' ),
+ __( 'Tell AI assistants when pages change', 'woocommerce' ),
+ __( 'Crawlers come back for changed prices and stock first.', 'woocommerce' ),
+ __( 'Your sitemap has no lastmod dates, which say when a page last changed. With them, crawlers come back for new prices and stock first.', 'woocommerce' ),
+ __( 'WooCommerce can’t add this.', 'woocommerce' ),
+ ),
+ 'rss_feed' => array(
+ __( 'Your home page links to a feed', 'woocommerce' ),
+ __( 'Link to a feed from your home page', 'woocommerce' ),
+ __( 'Some AI assistants follow your feed to see what is new.', 'woocommerce' ),
+ __( 'A feed lists your newest content. Some AI assistants follow it to see what’s new. We found no feed link on your home page.', 'woocommerce' ),
+ __( 'Check whether your theme or a plugin removes the feed links WordPress adds.', 'woocommerce' ),
+ ),
+ // Can AI assistants read your product details?
+ 'product_jsonld_present' => array(
+ __( 'Product pages have product details AI assistants can read', 'woocommerce' ),
+ __( 'Add product details AI assistants can read', 'woocommerce' ),
+ __( 'Crawlers read the product’s JSON-LD to get its name, price and stock.', 'woocommerce' ),
+ __( 'WooCommerce adds the name, price and stock to product pages as structured data, so AI assistants don’t have to guess. A theme or SEO plugin may have removed it. We found none on a recent product page.', 'woocommerce' ),
+ __( 'Test a product page in Google’s Rich Results Test, then look for a theme or plugin setting that turns off WooCommerce structured data.', 'woocommerce' ),
+ ),
+ 'product_jsonld_from_core' => array(
+ __( 'Product details come from WooCommerce, once', 'woocommerce' ),
+ __( 'Check why product details appear twice', 'woocommerce' ),
+ __( 'AI assistants may read a different name or price than your product shows.', 'woocommerce' ),
+ __( 'AI assistants may read a different name or price than your product shows. We found two sets of structured data, or another set than WooCommerce’s, on a recent product page.', 'woocommerce' ),
+ __( 'Look at the schema settings in your SEO plugin or theme. If you set this up on purpose, you can ignore it.', 'woocommerce' ),
+ ),
+ 'product_jsonld_required_fields' => array(
+ __( 'Product details have a name, image and price', 'woocommerce' ),
+ __( 'Add the name, image and price to your product details', 'woocommerce' ),
+ __( 'Without these, AI assistants can’t show the product as something to buy.', 'woocommerce' ),
+ __( 'Without them in the structured data, AI assistants can’t show the product as something to buy. We found a recent product page without one of them.', 'woocommerce' ),
+ __( 'Give the product a name, an image and a price. If it has them, look at the schema settings in your SEO plugin or theme.', 'woocommerce' ),
+ ),
+ 'product_offer_jsonld' => array(
+ __( 'Product details have price and stock', 'woocommerce' ),
+ __( 'Add price and stock to your product details', 'woocommerce' ),
+ __( 'AI assistants compare price and availability before they suggest a product.', 'woocommerce' ),
+ __( 'AI assistants compare price and availability before they suggest a product. We found a recent product page without one of them.', 'woocommerce' ),
+ __( 'Set a price and stock status on the product. If it has them, look at the schema settings in your SEO plugin or theme.', 'woocommerce' ),
+ ),
+ 'product_gtin_jsonld' => array(
+ __( 'Product details have the barcode number', 'woocommerce' ),
+ __( 'Check why product details have no barcode number', 'woocommerce' ),
+ __( 'AI assistants match products by their barcode number.', 'woocommerce' ),
+ __( 'AI assistants match products by their barcode number. Your product has one, but we found none, or an invalid one, in its structured data.', 'woocommerce' ),
+ __( 'Look at the schema settings in your SEO plugin or theme.', 'woocommerce' ),
+ ),
+ 'product_brand_jsonld' => array(
+ __( 'Product details have the brand', 'woocommerce' ),
+ __( 'Check why product details have no brand', 'woocommerce' ),
+ __( 'AI assistants use the brand to match and compare products.', 'woocommerce' ),
+ __( 'AI assistants use the brand to match and compare products. Your product has one, but we found none in its structured data.', 'woocommerce' ),
+ __( 'Look at the schema settings in your SEO plugin or theme.', 'woocommerce' ),
+ ),
+ 'content_in_raw_html' => array(
+ __( 'Product name and price show without JavaScript', 'woocommerce' ),
+ __( 'Make product name and price visible without JavaScript', 'woocommerce' ),
+ __( 'Most AI crawlers don’t run JavaScript.', 'woocommerce' ),
+ __( 'Most AI crawlers don’t run JavaScript, so they miss what loads with it. We found a recent product page that shows its name or price only with JavaScript.', 'woocommerce' ),
+ __( 'Ask your theme or page builder’s developer, or try another theme.', 'woocommerce' ),
+ ),
+ 'viewport_meta' => array(
+ __( 'Your home page fits small screens', 'woocommerce' ),
+ __( 'Make your home page fit small screens', 'woocommerce' ),
+ __( 'Without it, the layout can break for browser AI assistants.', 'woocommerce' ),
+ __( 'Your home page has no viewport tag, which tells browsers how to size the page. Without it, the layout can break for AI assistants that browse like people.', 'woocommerce' ),
+ __( 'Ask your theme’s developer, or try another theme.', 'woocommerce' ),
+ ),
+ 'html_lang_and_charset' => array(
+ __( 'Your home page sets its language', 'woocommerce' ),
+ __( 'Set your home page’s language', 'woocommerce' ),
+ __( 'AI assistants answer shoppers in their language without garbled text.', 'woocommerce' ),
+ __( 'Your home page doesn’t declare its language or text encoding. AI assistants use them to answer shoppers in the right language, without garbled text.', 'woocommerce' ),
+ __( 'Ask your theme’s developer, or try another theme.', 'woocommerce' ),
+ ),
+ 'images_have_alt' => array(
+ __( 'Your images are described', 'woocommerce' ),
+ __( 'Describe your product images', 'woocommerce' ),
+ __( 'AI assistants that can’t see images rely on alt text to know what a picture shows.', 'woocommerce' ),
+ __( 'AI assistants that can’t see images rely on alt text, a short description of each picture, to understand them. We found product images with no alt text.', 'woocommerce' ),
+ __( 'Add alt text to images in the media library and to product images.', 'woocommerce' ),
+ admin_url( 'upload.php' ),
+ ),
+ 'single_h1' => array(
+ __( 'Product pages have one main heading', 'woocommerce' ),
+ __( 'Use one main heading on product pages', 'woocommerce' ),
+ __( 'AI assistants read the H1 as the name of the product.', 'woocommerce' ),
+ __( 'AI assistants read the main heading (H1) as the product name. We found a recent product page with none, or more than one.', 'woocommerce' ),
+ __( 'Ask your theme’s developer, or try another theme.', 'woocommerce' ),
+ ),
+ 'schema_matches_product' => array(
+ __( 'Product details match the product page', 'woocommerce' ),
+ __( 'Make product details match the product page', 'woocommerce' ),
+ __( 'Otherwise shoppers may see a price your store doesn’t charge.', 'woocommerce' ),
+ __( 'Your structured data shows a different name or price than the product page, so shoppers may see a price you don’t charge.', 'woocommerce' ),
+ __( 'Look for a plugin that changes WooCommerce structured data.', 'woocommerce' ),
+ ),
+ 'product_review_markup' => array(
+ __( 'Product details include reviews', 'woocommerce' ),
+ __( 'Add product reviews to your product details', 'woocommerce' ),
+ __( 'AI assistants compare ratings between stores.', 'woocommerce' ),
+ __( 'AI assistants compare ratings between stores. We found a reviewed product with no reviews in its structured data.', 'woocommerce' ),
+ __( 'WooCommerce adds ratings to product details. Check whether your theme or SEO plugin removes them.', 'woocommerce' ),
+ ),
+ // Can shoppers buy through AI assistants?
+ 'product_return_policy_schema' => array(
+ __( 'Product details link your returns policy', 'woocommerce' ),
+ __( 'Add your returns policy to your product details', 'woocommerce' ),
+ __( 'AI assistants tell shoppers whether they can return an item before they buy.', 'woocommerce' ),
+ __( 'AI assistants tell shoppers whether they can return an item before they buy. We found no returns policy in the structured data of a recent product page.', 'woocommerce' ),
+ __( 'WooCommerce adds it once you choose a refund and returns page. If you have, check the schema settings in your SEO plugin or theme.', 'woocommerce' ),
+ ),
+ 'policy_pages_linked' => array(
+ __( 'Your home page links to your privacy and returns pages', 'woocommerce' ),
+ __( 'Link to your privacy and returns pages from your home page', 'woocommerce' ),
+ __( 'AI assistants look for policy links before they send a shopper to your checkout.', 'woocommerce' ),
+ __( 'AI assistants look for them before they send a shopper to your checkout. We found no link to one of them on your home page.', 'woocommerce' ),
+ __( 'Add your privacy policy and refund and returns pages to your footer or a menu.', 'woocommerce' ),
+ ),
+ );
+ }
+}
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessMarkup.php b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessMarkup.php
new file mode 100644
index 00000000000..e12eb23a4f0
--- /dev/null
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessMarkup.php
@@ -0,0 +1,143 @@
+<?php
+declare( strict_types = 1 );
+
+namespace Automattic\WooCommerce\Internal\AgentReadiness;
+
+use Automattic\WooCommerce\Internal\Traits\ScriptDebug;
+
+defined( 'ABSPATH' ) || exit;
+
+/**
+ * Markup of the AI tools tab's AI shopping section, and the wording of setup steps that Sales
+ * readiness shares: check rows, their badges and actions, folds, and the script for the switch and the
+ * copy button.
+ *
+ * @since 11.4.0
+ */
+trait ReadinessMarkup {
+
+ use ScriptDebug;
+
+ /**
+ * One row: an icon for its state, the title, the lines under it, then a button when there is one.
+ *
+ * @param string $state open, required, unknown, pass or off.
+ * @param string $title Escaped title HTML.
+ * @param array<int, string> $lines Escaped HTML lines; empty ones are skipped.
+ * @param string $action Escaped HTML at the end of the row, such as a Review button.
+ */
+ private static function render_item( string $state, string $title, array $lines, string $action = '' ): void {
+ $states = array(
+ 'open' => __( 'Issue:', 'woocommerce' ),
+ 'required' => __( 'Issue:', 'woocommerce' ),
+ 'pass' => __( 'Passed:', 'woocommerce' ),
+ );
+ echo '<li class="wc-agentic-commerce-item wc-agentic-commerce-item--' . esc_attr( $state ) . '"><span class="wc-agentic-commerce-item__icon" aria-hidden="true"></span><div>';
+ echo '<p class="wc-agentic-commerce-item__title"><span class="screen-reader-text">' . esc_html( $states[ $state ] ?? '' ) . ' </span>' . wp_kses_post( $title ) . '</p>';
+ foreach ( array_filter( $lines, static fn( string $line ): bool => '' !== trim( $line ) ) as $line ) {
+ echo '<p class="description">' . wp_kses_post( $line ) . '</p>';
+ }
+ echo '</div>' . wp_kses_post( $action ) . '</li>';
+ }
+
+ /**
+ * The badge on a setup step AI assistants can't shop the store without.
+ *
+ * @return string Badge HTML.
+ */
+ private static function required_badge(): string {
+ return '<mark class="wc-agentic-commerce-badge wc-agentic-commerce-badge--check">' . esc_html__( 'Required', 'woocommerce' ) . '</mark>';
+ }
+
+ /**
+ * Open a fold: "Show …" while closed, "Hide completed steps" while open. The caller closes the details element.
+ *
+ * @param string $show Text while closed.
+ */
+ private static function open_more( string $show ): void {
+ printf(
+ '<details class="wc-agentic-commerce-more"><summary><span class="wc-agentic-commerce-more__show">%1$s</span><span class="wc-agentic-commerce-more__hide">%2$s</span></summary>',
+ esc_html( $show ),
+ esc_html__( 'Hide completed steps', 'woocommerce' )
+ );
+ }
+
+ /**
+ * What an open check asks the merchant to do: the action, why it matters and where to do it.
+ * A policy page that is chosen but not published links to its editor; a published store page asks for another page.
+ *
+ * @param array{id:string,label?:string,why:string,fix?:string,fix_url:string} $check Store condition.
+ * @return array{0:string,1:string,2:string,3:string,4:string} The action, why, where to do it, the link text when the URL alone doesn't say it, and the fix line.
+ */
+ private static function check_action( array $check ): array {
+ // The connection URL step names its cause in the fix line: Plain permalinks, or a file in the way.
+ if ( 'ucp_discovery' === $check['id'] ) {
+ return array( $check['label'] ?? '', $check['why'], $check['fix_url'], '' !== $check['fix_url'] ? __( 'Change permalinks', 'woocommerce' ) : '', (string) ( $check['fix'] ?? '' ) );
+ }
+ // The privacy field is a WordPress setting. A user who can open this page but not manage
+ // privacy options would otherwise get a Review link to a field this page does not render.
+ if ( 'privacy_page' === $check['id'] && ! current_user_can( 'manage_privacy_options' ) ) {
+ $page_id = (int) get_option( AgenticCommerceSettings::PRIVACY_PAGE_OPTION );
+ $draft = $page_id > 0 && get_post( $page_id ) && 'publish' !== get_post_status( $page_id ) && current_user_can( 'edit_post', $page_id );
+ if ( ! $draft ) {
+ return array(
+ __( 'Choose a privacy policy page', 'woocommerce' ),
+ __( 'Someone who can manage privacy options needs to select a published privacy policy page under Settings > Privacy.', 'woocommerce' ),
+ '',
+ '',
+ '',
+ );
+ }
+ }
+ $policies = array(
+ 'privacy_page' => array( AgenticCommerceSettings::PRIVACY_PAGE_OPTION, __( 'Publish your privacy policy page', 'woocommerce' ), __( 'Choose a privacy policy page', 'woocommerce' ), __( 'Shoppers can read how you handle their information before they buy.', 'woocommerce' ), __( 'Edit privacy policy', 'woocommerce' ) ),
+ 'terms_page' => array( AgenticCommerceSettings::TERMS_PAGE_OPTION, __( 'Publish your terms and conditions page', 'woocommerce' ), __( 'Choose a terms and conditions page', 'woocommerce' ), __( 'Terms and conditions set out what shoppers agree to when they place an order.', 'woocommerce' ), __( 'Edit terms and conditions', 'woocommerce' ) ),
+ 'refund_returns_page' => array( AgenticCommerceSettings::REFUND_RETURNS_PAGE_OPTION, __( 'Publish your refund and returns policy page', 'woocommerce' ), __( 'Choose a refund and returns policy page', 'woocommerce' ), __( 'AI assistants link to it so customers can read it before they buy.', 'woocommerce' ), __( 'Edit refund policy', 'woocommerce' ), __( 'A refund policy needs to be available for AI assistants to share with shoppers.', 'woocommerce' ) ),
+ 'shipping_policy_page' => array( AgenticCommerceSettings::SHIPPING_POLICY_PAGE_OPTION, __( 'Publish your shipping policy page', 'woocommerce' ), __( 'Choose a shipping policy page', 'woocommerce' ), __( 'AI assistants share it so shoppers can check how and when you deliver before they buy.', 'woocommerce' ), __( 'Edit shipping policy', 'woocommerce' ) ),
+ );
+ if ( isset( $policies[ $check['id'] ] ) ) {
+ $policy = $policies[ $check['id'] ];
+ $page_id = (int) get_option( $policy[0] );
+ $edit = $page_id > 0 && get_post( $page_id ) && 'publish' !== get_post_status( $page_id ) ? (string) get_edit_post_link( $page_id, 'raw' ) : '';
+ return '' !== $edit
+ ? array( $policy[1], $policy[5] ?? __( 'It\'s still a draft. AI assistants only link to published pages.', 'woocommerce' ), $edit, $policy[4], '' )
+ : array( $policy[2], $policy[3], $check['fix_url'], '', '' );
+ }
+ $actions = array(
+ 'launched' => array( __( 'Make your store live', 'woocommerce' ), __( 'AI assistants can only find your products when your store is live.', 'woocommerce' ) ),
+ 'https' => array( __( 'Use a secure connection (HTTPS)', 'woocommerce' ), __( 'AI assistants only connect to stores with a secure connection.', 'woocommerce' ) ),
+ 'search_visible' => array( __( 'Let search engines index your store', 'woocommerce' ), __( 'AI assistants use search engines to find stores and products.', 'woocommerce' ) ),
+ 'guest_checkout' => array( __( 'Allow guest checkout', 'woocommerce' ), __( 'Guest checkout lets shoppers from AI assistants pay without creating an account.', 'woocommerce' ) ),
+ 'order_emails' => array( __( 'Turn on order confirmation emails', 'woocommerce' ), __( 'An email lets customers know their order went through.', 'woocommerce' ) ),
+ 'payment_method' => array( __( 'Set up payments', 'woocommerce' ), __( 'A payment method is needed so shoppers can pay on your checkout.', 'woocommerce' ) ),
+ );
+ $action = $actions[ $check['id'] ] ?? array( $check['label'] ?? '', $check['why'] );
+ // Site Health says how to move to HTTPS, and offers to do it where the host allows.
+ return array( $action[0], $action[1], 'https' === $check['id'] ? admin_url( 'site-health.php' ) : $check['fix_url'], '', '' );
+ }
+
+ /**
+ * Load the script for the switch and the copy button.
+ */
+ private function enqueue_script(): void {
+ wp_enqueue_script(
+ 'wc-agentic-commerce-settings',
+ plugins_url( 'assets/js/admin/wc-agentic-commerce-settings' . $this->get_script_suffix() . '.js', WC_PLUGIN_FILE ),
+ array( 'wp-api-fetch' ),
+ WC_VERSION,
+ true
+ );
+ wp_localize_script(
+ 'wc-agentic-commerce-settings',
+ 'wcAgenticCommerceSettings',
+ array(
+ 'path' => '/wc/v3/agent-readiness/ucp',
+ 'i18n' => array(
+ 'error' => __( 'The setting didn’t save. Reload the page and try again.', 'woocommerce' ),
+ 'unsaved' => __( 'Save your changes to see the updated status.', 'woocommerce' ),
+ 'copied' => __( 'Copied', 'woocommerce' ),
+ ),
+ )
+ );
+ }
+}
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessRestController.php b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessRestController.php
index 73adc04c05d..f759f691554 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessRestController.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/ReadinessRestController.php
@@ -14,8 +14,9 @@ defined( 'ABSPATH' ) || exit;
* wc/v3/agent-readiness/scan queues a new scan. Both answer with the report
* (null before the first scan) and whether a scan is pending, so a settings
* page can show the last result and poll while a scan runs. POST
- * wc/v3/agent-readiness/ucp turns UCP on or off for the Agentic commerce
- * settings page.
+ * wc/v3/agent-readiness/ucp turns UCP on or off for the AI tools settings
+ * page, and GET wc/v3/agent-readiness/view gives the Sales readiness page and
+ * the AI tools Overview what they show.
*
* Registered only while the agent_readiness feature is enabled.
*
@@ -51,6 +52,13 @@ class ReadinessRestController extends RestApiControllerBase {
*/
private UcpSwitch $ucp_switch;
+ /**
+ * Sales readiness, which builds the view.
+ *
+ * @var ReadinessCheckPage
+ */
+ private ReadinessCheckPage $readiness_page;
+
/**
* Initialize dependencies.
*
@@ -60,12 +68,14 @@ class ReadinessRestController extends RestApiControllerBase {
* @param AgentReadiness $agent_readiness Readiness service.
* @param ScheduledScan $scheduled_scan Background scan.
* @param UcpSwitch $ucp_switch UCP switch.
+ * @param ReadinessCheckPage $readiness_page Sales readiness.
*/
- final public function init( FeaturesController $features_controller, AgentReadiness $agent_readiness, ScheduledScan $scheduled_scan, UcpSwitch $ucp_switch ): void {
+ final public function init( FeaturesController $features_controller, AgentReadiness $agent_readiness, ScheduledScan $scheduled_scan, UcpSwitch $ucp_switch, ReadinessCheckPage $readiness_page ): void {
$this->features_controller = $features_controller;
$this->agent_readiness = $agent_readiness;
$this->scheduled_scan = $scheduled_scan;
$this->ucp_switch = $ucp_switch;
+ $this->readiness_page = $readiness_page;
}
/**
@@ -106,6 +116,18 @@ class ReadinessRestController extends RestApiControllerBase {
'schema' => array( $this, 'get_status_schema' ),
)
);
+ register_rest_route(
+ $this->route_namespace,
+ '/agent-readiness/view',
+ array(
+ array(
+ 'methods' => \WP_REST_Server::READABLE,
+ 'callback' => fn( $request ) => $this->run( $request, 'get_view' ),
+ 'permission_callback' => fn( $request ) => $this->check_permission( $request, 'manage_woocommerce' ),
+ ),
+ 'schema' => array( $this, 'get_view_schema' ),
+ )
+ );
register_rest_route(
$this->route_namespace,
'/agent-readiness/ucp',
@@ -142,6 +164,19 @@ class ReadinessRestController extends RestApiControllerBase {
);
}
+ /**
+ * The Sales readiness page and the AI tools Overview as data: text, badges and links, built by
+ * ReadinessCheckPage from the stored report and the store's settings.
+ *
+ * @param WP_REST_Request $request Request.
+ * @phpstan-param WP_REST_Request<array<string, mixed>> $request
+ * @return array<string, mixed>
+ */
+ protected function get_view( WP_REST_Request $request ): array {
+ unset( $request );
+ return $this->readiness_page->view();
+ }
+
/**
* Queue a scan, then answer like GET.
*
@@ -184,6 +219,63 @@ class ReadinessRestController extends RestApiControllerBase {
return $result;
}
+ /**
+ * Schema of the view: the keys ReadinessCheckPage::view() builds.
+ *
+ * @internal
+ */
+ public function get_view_schema(): array {
+ $schema = $this->get_base_schema();
+ $schema['title'] = 'agent_readiness_view';
+ $schema['properties'] = array(
+ 'title' => array(
+ 'type' => 'string',
+ 'context' => array( 'view' ),
+ ),
+ 'description' => array(
+ 'type' => 'string',
+ 'context' => array( 'view' ),
+ ),
+ 'last_checked' => array(
+ 'description' => __( 'When the store was last checked, as text.', 'woocommerce' ),
+ 'type' => 'string',
+ 'context' => array( 'view' ),
+ ),
+ 'checked_note' => array(
+ 'type' => array( 'string', 'null' ),
+ 'context' => array( 'view' ),
+ ),
+ 'intro' => array(
+ 'type' => array( 'string', 'null' ),
+ 'context' => array( 'view' ),
+ ),
+ 'run' => array(
+ 'description' => __( 'The check button: its label, whether a check is pending or stalled, and a status message.', 'woocommerce' ),
+ 'type' => 'object',
+ 'context' => array( 'view' ),
+ ),
+ 'fix_first' => array(
+ 'type' => array( 'object', 'null' ),
+ 'context' => array( 'view' ),
+ ),
+ 'sections' => array(
+ 'description' => __( 'One section per merchant question, with its badge and check rows.', 'woocommerce' ),
+ 'type' => 'array',
+ 'context' => array( 'view' ),
+ ),
+ 'declared' => array(
+ 'type' => array( 'object', 'null' ),
+ 'context' => array( 'view' ),
+ ),
+ 'overview' => array(
+ 'description' => __( 'The AI tools Overview: the AI shopping card and the link to every check.', 'woocommerce' ),
+ 'type' => 'object',
+ 'context' => array( 'view' ),
+ ),
+ );
+ return $schema;
+ }
+
/**
* Response schema. The report's shape is documented in this directory's README.
*
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/StoreConditions.php b/plugins/woocommerce/src/Internal/AgentReadiness/StoreConditions.php
index d556c937259..5cf712126ab 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/StoreConditions.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/StoreConditions.php
@@ -72,9 +72,8 @@ class StoreConditions {
'name' => $name,
'label' => $label,
'why' => $why,
- // The AI shopping section lands with #70590; until then the tab has one page.
- 'fix' => __( 'Choose a published page under WooCommerce > Settings > Agentic commerce.', 'woocommerce' ),
- 'fix_url' => AgenticCommerceSettings::url() . '#' . $option,
+ 'fix' => __( 'Choose a published page under WooCommerce > Settings > AI tools > AI shopping.', 'woocommerce' ),
+ 'fix_url' => AgenticCommerceSettings::url( AgenticCommerceSettings::SHOPPING_SECTION ) . '#' . $option,
);
$conditions = array(
@@ -111,8 +110,8 @@ class StoreConditions {
'name' => __( 'Universal Commerce Protocol (UCP) is on', 'woocommerce' ),
'label' => __( 'Universal Commerce Protocol (UCP) is off', 'woocommerce' ),
'why' => __( 'Shopping agents that use UCP cannot read your catalog.', 'woocommerce' ),
- 'fix' => __( 'Turn on "Allow AI assistants to shop your store" under WooCommerce > Settings > Agentic commerce.', 'woocommerce' ),
- 'fix_url' => AgenticCommerceSettings::url(),
+ 'fix' => __( 'Turn on "Allow AI assistants to shop your store" under WooCommerce > Settings > AI tools > AI shopping.', 'woocommerce' ),
+ 'fix_url' => AgenticCommerceSettings::url( AgenticCommerceSettings::SHOPPING_SECTION ),
),
array(
'id' => 'https',
diff --git a/plugins/woocommerce/src/Internal/AgentReadiness/StoreOutputChecks.php b/plugins/woocommerce/src/Internal/AgentReadiness/StoreOutputChecks.php
index f04207dfd80..dbe29d2bdf3 100644
--- a/plugins/woocommerce/src/Internal/AgentReadiness/StoreOutputChecks.php
+++ b/plugins/woocommerce/src/Internal/AgentReadiness/StoreOutputChecks.php
@@ -1903,12 +1903,17 @@ class StoreOutputChecks {
* @param StoreResponses $responses Store responses.
*/
private function reviews_marked_up( StoreResponses $responses ): ?bool {
+ // The passes below load no page. Without a product page the rest of the card couldn't run, so neither does this.
+ if ( null === $responses->product_page() ) {
+ return null;
+ }
// WooCommerce prints a rating only when ratings are on and the product has rated reviews; the rating count is stored per star, the average as a number.
if ( ! wc_review_ratings_enabled() ) {
return true;
}
// wc_get_products() ignores meta_query, so the reviewed product is looked up as a post.
- $ids = get_posts(
+ // The same products the scan checks: Search results only included, Hidden left out.
+ $ids = get_posts(
array(
'post_type' => 'product',
'post_status' => ProductStatus::PUBLISH,
@@ -1919,14 +1924,7 @@ class StoreOutputChecks {
'order' => 'DESC',
'suppress_filters' => false,
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Five rows, once per background scan.
- 'tax_query' => array(
- array(
- 'taxonomy' => 'product_visibility',
- 'field' => 'slug',
- 'terms' => array( 'exclude-from-catalog' ),
- 'operator' => 'NOT IN',
- ),
- ),
+ 'tax_query' => ProductScan::count_query( ProductScan::COUNT_AVAILABLE ),
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Five rows, once per background scan.
'meta_query' => array(
array(
@@ -1953,9 +1951,6 @@ class StoreOutputChecks {
$sampled = $responses->product();
if ( null !== $sampled && $sampled->get_id() === $product->get_id() ) {
$page = $responses->product_page();
- if ( null === $page ) {
- return null;
- }
} else {
$page = $responses->get( (string) $product->get_permalink() );
if ( null === $page || 200 !== $page['status'] ) {
diff --git a/plugins/woocommerce/src/Internal/Features/FeaturesController.php b/plugins/woocommerce/src/Internal/Features/FeaturesController.php
index 737f9205ff5..cd3374390a3 100644
--- a/plugins/woocommerce/src/Internal/Features/FeaturesController.php
+++ b/plugins/woocommerce/src/Internal/Features/FeaturesController.php
@@ -665,7 +665,7 @@ class FeaturesController {
'agent_readiness' => array(
'name' => __( 'Agent readiness', 'woocommerce' ),
'description' => __(
- 'Check products against the product data specs of AI shopping channels, and set up agentic commerce, under WooCommerce > Settings > Agentic commerce.',
+ 'Check products against the product data specs of AI shopping channels, and set up agentic commerce, under WooCommerce > Settings > AI tools.',
'woocommerce'
),
'enabled_by_default' => false,
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgentReadinessTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgentReadinessTest.php
index d2c8730c388..ed1dc33e232 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgentReadinessTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgentReadinessTest.php
@@ -460,4 +460,24 @@ class AgentReadinessTest extends WC_Unit_Test_Case {
$this->assertSame( 1, $calls );
}
+
+ /**
+ * @testdox A stored output check keeps the detail of what the store served.
+ */
+ public function test_get_store_checks_keeps_the_served_detail(): void {
+ $checks = $this->sut->get_store_checks(
+ array(
+ 'store_checks' => array(
+ array(
+ 'id' => 'ucp_endpoints_live',
+ 'name' => 'Catalog search answers',
+ 'ok' => false,
+ 'source' => '403 text/html',
+ ),
+ ),
+ )
+ );
+
+ $this->assertSame( '403 text/html', array_column( $checks, 'source', 'id' )['ucp_endpoints_live'] );
+ }
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php
index fc81c6d81b0..1a9bf40158e 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/AgenticCommerceSettingsTest.php
@@ -6,7 +6,13 @@ namespace Automattic\WooCommerce\Tests\Internal\AgentReadiness;
use Automattic\WooCommerce\Internal\AgentReadiness\AgenticCommerceSettings;
use Automattic\WooCommerce\Internal\AgentReadiness\AgenticCommerceSettingsPage;
use Automattic\WooCommerce\Internal\AgentReadiness\AgentReadiness;
+use Automattic\WooCommerce\Internal\AgentReadiness\ProductScan;
+use Automattic\WooCommerce\Internal\AgentReadiness\ReadinessCheckPage;
+use Automattic\WooCommerce\Internal\AgentReadiness\ReadinessCopy;
+use Automattic\WooCommerce\Internal\AgentReadiness\ReadinessRule;
+use Automattic\WooCommerce\Internal\AgentReadiness\RemoteRules;
use Automattic\WooCommerce\Internal\AgentReadiness\ScheduledScan;
+use Automattic\WooCommerce\Internal\AgentReadiness\StoreConditions;
use WC_Admin_Settings;
use WC_Helper_Product;
use WC_Unit_Test_Case;
@@ -23,6 +29,13 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
*/
private $sut;
+ /**
+ * Gateways and emails a test turned on, with the enabled value to put back.
+ *
+ * @var array<int, array{0:object,1:string}>
+ */
+ private array $restore = array();
+
/**
* Load the settings page base class and act as an admin in wp-admin.
*/
@@ -35,7 +48,7 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
set_current_screen( 'dashboard' );
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
update_option( 'woocommerce_feature_agent_readiness_enabled', 'yes' );
- update_option( 'woocommerce_feature_ucp_enabled', 'no' );
+ delete_option( 'woocommerce_feature_ucp_enabled' );
$this->sut = wc_get_container()->get( AgenticCommerceSettings::class );
}
@@ -45,6 +58,9 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
public function tearDown(): void {
try {
set_current_screen( 'front' );
+ foreach ( array_reverse( $this->restore ) as $item ) {
+ $item[0]->enabled = $item[1];
+ }
} finally {
parent::tearDown();
}
@@ -69,6 +85,53 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
$this->assertSame( 'agentic-commerce', $pages[0]->get_id() );
}
+ /**
+ * @testdox The AI tools tab, and only that tab, gets its body class for the white panel.
+ */
+ public function test_body_class_only_on_the_tab(): void {
+ global $current_tab;
+ $previous = $current_tab;
+ try {
+ $current_tab = AgenticCommerceSettings::TAB; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+ $this->assertStringContainsString( 'woocommerce-settings-agentic-commerce-tab', $this->sut->handle_admin_body_class( 'wp-admin' ) );
+
+ $current_tab = 'checkout'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+ $this->assertSame( 'wp-admin', $this->sut->handle_admin_body_class( 'wp-admin' ) );
+ } finally {
+ $current_tab = $previous; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+ }
+ }
+
+ /**
+ * @testdox Sales readiness is added only while the agent_readiness feature is enabled, as a WooCommerce Admin page under WooCommerce, before Settings.
+ */
+ public function test_readiness_page_only_with_feature_enabled(): void {
+ $page = wc_get_container()->get( ReadinessCheckPage::class );
+ update_option( 'woocommerce_feature_agent_readiness_enabled', 'no' );
+ remove_all_actions( 'admin_menu' );
+ $page->handle_init();
+ $this->assertFalse( has_action( 'admin_menu', array( $page, 'handle_admin_menu' ) ), 'No page with the feature off' );
+
+ update_option( 'woocommerce_feature_agent_readiness_enabled', 'yes' );
+ $page->handle_init();
+ $this->assertSame( ReadinessCheckPage::MENU_PRIORITY, has_action( 'admin_menu', array( $page, 'handle_admin_menu' ) ), 'After Reports (20), before Settings (50)' );
+
+ // The menu globals aren't rolled back between tests, so put them back after.
+ $globals = array( 'menu', 'submenu', 'admin_page_hooks', '_registered_pages', '_parent_pages', '_wp_real_parent_file', '_wp_submenu_nopriv' );
+ $saved = array_map( static fn( string $name ) => $GLOBALS[ $name ] ?? null, array_combine( $globals, $globals ) );
+ try {
+ $GLOBALS['submenu'] = array(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Start from an empty menu; restored below.
+ add_menu_page( 'WooCommerce', 'WooCommerce', 'manage_woocommerce', 'woocommerce' );
+ $page->handle_admin_menu();
+ $this->assertSame( array( 'Sales readiness', 'manage_woocommerce', 'wc-admin&path=/sales-readiness' ), array_slice( end( $GLOBALS['submenu']['woocommerce'] ), 0, 3 ) );
+ } finally {
+ foreach ( $saved as $name => $value ) {
+ $GLOBALS[ $name ] = $value; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Restoring what the test changed.
+ }
+ }
+ $this->assertSame( admin_url( 'admin.php?page=wc-admin&path=/sales-readiness' ), ReadinessCheckPage::url() );
+ }
+
/**
* @testdox Before the first scan the page asks for one instead of showing counts; dropdowns list published pages only.
*/
@@ -91,7 +154,8 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
$html = $this->render_page();
- $this->assertStringContainsString( 'Product counts appear after the first agent readiness check.', $html );
+ $this->assertStringContainsString( 'Product counts show after the first Sales readiness check.', $html );
+ $this->assertStringContainsString( 'path=/sales-readiness">Sales readiness</a> <mark class="wc-agentic-commerce-badge wc-agentic-commerce-badge--off">Not checked yet</mark>', $html, 'Status links to Sales readiness, not yet run' );
$this->assertStringNotContainsString( 'View products', $html );
$this->assertStringContainsString( 'Published returns page', $html );
$this->assertStringNotContainsString( 'Draft returns page', $html );
@@ -110,123 +174,119 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
$html = $this->render_page();
- $this->assertStringContainsString( '<span>Available to agents</span> <strong>1</strong>', $html );
- $this->assertStringContainsString( '<span>Not supported yet</span> <strong>1</strong>', $html );
- $this->assertStringContainsString( 'Simple and variable products only, for now.', $html );
- $this->assertStringNotContainsString( 'aren't shown', $html );
- $this->assertStringContainsString( '<span>Available to agents</span> <strong>1</strong></li>', $html, 'No list matches the available count, so it has no link' );
- $this->assertStringContainsString( 'product_type=simple,variable&product_visibility=exclude-from-catalog', $html, 'The hidden link matches its count' );
+ $this->assertStringContainsString( '<span>Available to AI assistants</span> <strong>1</strong> <a href="', $html );
+ $stored = get_option( AgentReadiness::REPORT_OPTION );
+ $stored['products'] = ProductScan::PRODUCT_LIMIT;
+ $stored['available'] = 8400;
+ update_option( AgentReadiness::REPORT_OPTION, $stored );
+ $this->assertStringContainsString( '<span>Available to AI assistants</span> <strong>8,400</strong> <a href="', $this->render_page(), 'The whole catalog, like the other two, not only the products the scan stopped at' );
+ $this->assertMatchesRegularExpression( '#<span>Product type not supported yet <span[^>]*woocommerce-help-tip[^>]*AI assistants can find these products, but shoppers can.{1,7}t buy them through an assistant yet\.[^>]*></span></span> <strong>1</strong>#', $html, 'The tip says what not supported means' );
+ $this->assertStringContainsString( 'agent_readiness=' . ProductScan::COUNT_UNSUPPORTED . '">View products</a>', $html, 'Each count links to its products' );
+ $this->assertMatchesRegularExpression( '#<h2>Setup checklist</h2>\s*<mark class="wc-agentic-commerce-badge wc-agentic-commerce-badge--info">\s*\d+ steps? left\s*</mark>\s*</div>\s*<p>Finish \d+ required steps? to get your store ready for AI shopping\.</p>#', $html, 'The checklist says how many steps are left, then counts the required steps first, even with UCP off' );
+ $this->assertMatchesRegularExpression( '#Use a secure connection \(HTTPS\) <mark[^>]*>Required</mark></p>.*?</div><a class="button wc-agentic-commerce-review" href="[^"]*site-health\.php">Review</a></li>#s', $html, 'A step is not a link itself: Review at the end of the row opens where to fix it' );
$this->assertStringContainsString( 'aria-checked="false"', $html );
$this->assertStringNotContainsString( 'to turn this on', $html );
- $this->assertMatchesRegularExpression( '/but \d+ required setup checks? below still needs? fixing\./', (string) wp_scripts()->get_data( 'wc-agentic-commerce-settings', 'data' ), 'Turning the switch on shows the failing checks without a reload' );
- $this->assertStringContainsString( 'wc-agentic-commerce-check--required', $html, 'Failing required checks are in the Required group' );
+ $this->assertMatchesRegularExpression( '#wc-agentic-commerce-item--required.*badge--check">Required</mark>#', $html, 'Failing required checks are marked Required' );
+ $this->assertStringNotContainsString( 'Check</mark>', $html, 'Failing recommended checks have no badge' );
+ $this->assertStringNotContainsString( 'Required.', $html, 'Policy pages are recommended, so no field is marked required' );
+ $this->assertLessThan( strpos( $html, 'wc-agentic-commerce-item--open' ), strrpos( $html, 'wc-agentic-commerce-item--required' ), 'Required steps come first' );
+ $this->assertLessThan( strpos( $html, 'AI assistants can only find your products when your store is live.' ), strpos( $html, 'Use a secure connection (HTTPS)' ), 'HTTPS is listed first, as in the design' );
$this->assertMatchesRegularExpression( '/(Choose a|Publish your) privacy policy page/', $html, 'An open check says what to do' );
- $this->assertStringContainsString( 'Test your setup', $html, 'Placeholder until WOOAI-1619' );
- $this->assertStringContainsString( '<h2>Security</h2>', $html, 'Placeholder until WOOAI-1620' );
+ $this->assertStringContainsString( 'Connection URL', $html );
+ $this->assertStringContainsString( 'page=wc-settings&tab=agentic-commerce">AI tools</a> <span aria-hidden="true">/</span> <span aria-current="page">AI shopping</span></div>', $html, 'AI shopping has a breadcrumb back to the landing page' );
+ $this->assertStringNotContainsString( '<h2>Security</h2>', $html, 'No Security card until a UCP flow signs anything (WOOAI-1620)' );
$this->assertStringNotContainsString( 'Universal Commerce Protocol (UCP) is off', $html, 'UCP is the switch, not a listed check' );
}
/**
- * @testdox The switch message counts failing required checks, singular for one, and says ready for none.
+ * @testdox With every required check passing, open checks are only Recommended and passing ones are Done.
*/
- public function test_on_message_counts(): void {
- $on_message = new \ReflectionMethod( AgenticCommerceSettingsPage::class, 'on_message' );
- $on_message->setAccessible( true );
+ public function test_output_on_a_ready_store(): void {
+ $this->make_every_step_pass();
- $this->assertStringContainsString( 'but 1 required setup check below still needs fixing.', $on_message->invoke( null, 1 ) );
- $this->assertStringContainsString( 'but 3 required setup checks below still need fixing.', $on_message->invoke( null, 3 ) );
- $this->assertSame( 'AI agents can now find and shop your store.', $on_message->invoke( null, 0 ) );
- }
+ $html = $this->render_page();
- /**
- * @testdox Status groups by shows_required(), so a recommended-level check the rules mark Required lands in Required.
- */
- public function test_status_groups_by_shows_required(): void {
- $render = new \ReflectionMethod( AgenticCommerceSettingsPage::class, 'render_status' );
- $render->setAccessible( true );
- ob_start();
- $render->invoke(
- $this->page(),
- array(
- array(
- 'id' => 'search_visible',
- 'level' => 'recommended',
- 'ok' => false,
- 'name' => 'Products can be found in search',
- 'label' => 'Search',
- 'fix_url' => '#search',
- 'fix' => 'Fix search',
- ),
- array(
- 'id' => 'canonical_url',
- 'level' => 'recommended',
- 'ok' => false,
- 'name' => 'Pages name their canonical URL',
- 'label' => 'Canonical',
- 'fix_url' => '#canonical',
- 'fix' => 'Fix canonical',
- ),
- ),
- \Automattic\WooCommerce\Internal\AgentReadiness\UcpSwitch::STATUS_OFF
- );
- $html = (string) ob_get_clean();
+ $this->assertMatchesRegularExpression( '#<p>Your store is ready for AI shopping\. (You have \d+ optional steps? left\.|Turn it on to let AI assistants find your products\.)</p>#', $html );
+ $this->assertStringNotContainsString( 'badge--pass', $html, 'Completed steps need no badge, their marker says so' );
+ $this->assertStringNotContainsString( 'wc-agentic-commerce-missing', $html );
+ $this->assertStringNotContainsString( 'wc-agentic-commerce-item--required', $html );
+ $this->assertMatchesRegularExpression( '#Show \d+ completed steps?</span>#', $html, 'Completed steps are folded' );
+ $this->assertStringContainsString( 'Privacy policy page is selected', $html, 'Done rows are named by their passing state' );
+ $this->assertStringNotContainsString( 'wc-agentic-commerce-notice', $html, 'No coming soon notice on a live store' );
- $this->assertStringContainsString( 'wc-agentic-commerce-group--required', $html );
- $this->assertStringContainsString( '1 required step to finish so agents can shop your store.', $html, 'The summary counts a Required row even when it does not block the switch' );
- $this->assertStringNotContainsString( 'Everything agents need is set up.', $html );
- $this->assertStringContainsString( 'Let search engines index your store', $html, 'search_visible shows as Required via shows_required()' );
- $this->assertMatchesRegularExpression(
- '/wc-agentic-commerce-group--required[\s\S]*Let search engines index your store[\s\S]*wc-agentic-commerce-group--recommended[\s\S]*Canonical/s',
- $html
- );
+ $shopping = $this->view()['overview']['shopping'];
+ $this->assertNull( $shopping['badge'], 'With UCP off and nothing required failing, the Overview card has no badge' );
+ $this->assertSame( 'Let shoppers find and buy your products through AI assistants.', $shopping['text'] );
+ $this->assertSame( 'Set up AI shopping', $shopping['button']['text'], 'and offers set up' );
}
/**
- * Render the page with one payment gateway turned on, since a payment method is Required.
+ * The design's five AI shopping scenarios: how the store is set up, the UCP setting, and what the Overview card and
+ * the Setup checklist say.
*
- * @return string
+ * @return array<string, array{0:string,1:string|null,2:string,3:string|null,4:string,5:string}>
*/
- private function render_with_a_payment_method(): string {
- $gateways = WC()->payment_gateways()->payment_gateways();
- $this->assertNotEmpty( $gateways, 'Core registers its gateways' );
- $gateway = reset( $gateways );
- $enabled = $gateway->enabled;
-
- $gateway->enabled = 'yes';
- try {
- return $this->render_page();
- } finally {
- $gateway->enabled = $enabled;
- }
+ public function provider_shopping_scenarios(): array {
+ return array(
+ 'not set up yet' => array( 'every_step', null, '#^Let shoppers find and buy your products through AI assistants\.$#', null, 'Set up AI shopping', '#<p>Your store is ready for AI shopping\. Turn it on to let AI assistants find your products\.</p>#' ),
+ 'steps left' => array( 'coming_soon', 'yes', '#^AI assistants can\'t shop your store yet\. \d+ steps? left\.$#', 'Needs attention', 'Manage', '#<p>Finish \d+ required steps? to get your store ready for AI shopping\.</p>#' ),
+ 'optional steps left' => array( 'optional_left', 'yes', '#^AI assistants can shop your store\. 1 step left\.$#', 'Active', 'Manage', '#<p>Your store is ready for AI shopping\. You have 1 optional step left\.</p>#' ),
+ 'all steps done' => array( 'every_step', 'yes', '#^AI assistants can shop your store\.$#', 'Active', 'Manage', '#<p>Your store is ready for AI shopping\.</p>#' ),
+ 'turned off' => array( 'every_step', 'no', '#^AI shopping is off\.$#', null, 'Manage', '#<p>Your store is ready for AI shopping\. Turn it on to let AI assistants find your products\.</p>#' ),
+ 'off, steps left' => array( 'coming_soon', 'no', '#^AI shopping is off\.$#', 'Needs attention', 'Manage', '#<p>Finish \d+ required steps? to get your store ready for AI shopping\.</p>#' ),
+ );
}
/**
- * @testdox With every required check passing, open checks are only Recommended and passing ones are Done.
+ * @testdox The AI shopping card and the Setup checklist follow the design in each scenario: $_dataName.
+ * @dataProvider provider_shopping_scenarios
+ *
+ * @param string $store How the store is set up.
+ * @param string|null $ucp The stored UCP setting, or null when it was never saved.
+ * @param string $text The card text, as a pattern.
+ * @param string|null $badge The card badge, or null for none.
+ * @param string $button The card button.
+ * @param string $checklist The Setup checklist summary, as a pattern.
*/
- public function test_output_on_a_ready_store(): void {
- StoreConditionsTest::make_store_ready();
+ public function test_shopping_scenarios( string $store, ?string $ucp, string $text, ?string $badge, string $button, string $checklist ): void {
+ if ( 'coming_soon' === $store ) {
+ remove_all_filters( 'pre_option_home' );
+ update_option( 'woocommerce_coming_soon', 'yes' );
+ update_option( 'home', 'http://example.org' );
+ } else {
+ $this->make_every_step_pass();
+ }
+ if ( 'optional_left' === $store ) {
+ foreach ( array_intersect_key( WC()->mailer()->get_emails(), array_flip( array( 'WC_Email_Customer_Processing_Order', 'WC_Email_Customer_Completed_Order' ) ) ) as $email ) {
+ $this->restore[] = array( $email, $email->enabled );
+ $email->enabled = 'no';
+ }
+ }
- $html = $this->render_with_a_payment_method();
+ $html = $this->render_page( AgenticCommerceSettings::SHOPPING_SECTION, 'yes' === $ucp );
+ if ( 'no' === $ucp ) {
+ update_option( 'woocommerce_feature_ucp_enabled', 'no' );
+ }
+ $shopping = $this->view()['overview']['shopping'];
- $this->assertStringContainsString( 'Everything agents need is set up.', $html );
- $this->assertStringNotContainsString( 'wc-agentic-commerce-check--required', $html );
- $this->assertStringContainsString( 'wc-agentic-commerce-group--done', $html );
- $this->assertStringContainsString( 'Privacy policy page is selected', $html, 'Done rows are named by their passing state' );
- $this->assertStringNotContainsString( 'wc-agentic-commerce-notice', $html, 'No coming soon notice on a live store' );
+ $this->assertMatchesRegularExpression( $checklist, $html );
+ $this->assertMatchesRegularExpression( $text, $shopping['text'] );
+ $this->assertSame( $badge, $shopping['badge']['text'] ?? null );
+ $this->assertSame( $button, $shopping['button']['text'] );
}
/**
* @testdox A missing policy page is recommended, so it does not block the switch or the required group.
*/
public function test_missing_policy_page_is_recommended(): void {
- StoreConditionsTest::make_store_ready();
+ $this->make_every_step_pass();
delete_option( AgenticCommerceSettings::PRIVACY_PAGE_OPTION );
- $html = $this->render_with_a_payment_method();
+ $html = $this->render_page();
- $this->assertStringNotContainsString( 'wc-agentic-commerce-check--required', $html );
- $this->assertMatchesRegularExpression( '/wc-agentic-commerce-group--recommended.*Choose a privacy policy page/s', $html );
- $this->assertStringContainsString( 'Everything agents need is set up.', $html );
+ $this->assertStringNotContainsString( 'wc-agentic-commerce-item--required', $html );
+ $this->assertMatchesRegularExpression( '#wc-agentic-commerce-item--open.*Choose a privacy policy page#s', $html );
+ $this->assertDoesNotMatchRegularExpression( '#required steps?#', $html );
$this->assertDoesNotMatchRegularExpression( '/<button[^>]*wc-agentic-commerce-ucp-switch[^>]*disabled=([\'"])disabled\\1/', $html );
}
@@ -238,7 +298,7 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
$html = $this->render_page();
- $this->assertMatchesRegularExpression( '/wc-agentic-commerce-switch-card.*wc-agentic-commerce-notice.*Go to Site visibility/s', $html );
+ $this->assertMatchesRegularExpression( '/wc-agentic-commerce-switch-card.*wc-agentic-commerce-notice.*Change site visibility/s', $html );
$this->assertLessThan( strpos( $html, 'wc-agentic-commerce-status-card' ), strpos( $html, 'wc-agentic-commerce-switch-card' ), 'The switch comes first' );
}
@@ -246,6 +306,7 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
* @testdox A chosen policy page that isn't published links to its editor.
*/
public function test_draft_policy_page_links_to_review_and_publish(): void {
+ $this->make_every_step_pass();
$draft = self::factory()->post->create(
array(
'post_type' => 'page',
@@ -257,11 +318,61 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
$html = $this->render_page();
$this->assertStringContainsString( 'Publish your refund and returns policy page', $html );
- $this->assertStringContainsString( 'Review and publish', $html );
+ $this->assertStringContainsString( 'A refund policy needs to be available for AI assistants to share with shoppers.', $html, 'The refund page says why it matters, as in the design' );
+ $this->assertMatchesRegularExpression( '#Publish your refund and returns policy page.*?href="[^"]*post=' . $draft . '&action=edit">Review</a>#s', $html, 'Review opens the page editor' );
+
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array(),
+ )
+ );
+ $view = $this->view();
+ $this->assertNull( $view['fix_first'], 'A policy page is only recommended, so it stays out of Fix first' );
+ $this->assertStringNotContainsString( 'Publish your refund and returns policy page', (string) wp_json_encode( $view['sections'] ), 'Setup steps stay in the Setup checklist' );
+ $copy = $this->step_copy( 'refund_returns_page' );
+ $this->assertStringContainsString( 'post=' . $draft . '&action=edit', $copy['url'], 'Readiness check links the step to the page editor' );
+ $this->assertSame( 'Edit refund policy', $copy['link'], 'named for the policy' );
+ $this->assertSame( 'A refund policy needs to be available for AI assistants to share with shoppers.', $copy['text'], 'The refund draft keeps its own line' );
+ }
+
+ /**
+ * @testdox Each draft policy page links to its editor with the policy's own link text.
+ */
+ public function test_draft_policy_pages_name_their_edit_link(): void {
+ $this->make_every_step_pass();
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array(),
+ )
+ );
+ $pages = array(
+ AgenticCommerceSettings::PRIVACY_PAGE_OPTION => array( 'Publish your privacy policy page', 'Edit privacy policy', 'privacy_page' ),
+ AgenticCommerceSettings::TERMS_PAGE_OPTION => array( 'Publish your terms and conditions page', 'Edit terms and conditions', 'terms_page' ),
+ AgenticCommerceSettings::SHIPPING_POLICY_PAGE_OPTION => array( 'Publish your shipping policy page', 'Edit shipping policy', 'shipping_policy_page' ),
+ );
+ foreach ( $pages as $option => $copy ) {
+ $draft = self::factory()->post->create(
+ array(
+ 'post_type' => 'page',
+ 'post_status' => 'draft',
+ )
+ );
+ update_option( $option, $draft );
+ $step = $this->step_copy( $copy[2] );
+ $this->assertSame( $copy[0], $step['title'] );
+ $this->assertStringContainsString( 'post=' . $draft . '&action=edit', $step['url'], $copy[1] );
+ $this->assertSame( $copy[1], $step['link'] );
+ $this->assertSame( 'It\'s still a draft. AI assistants only link to published pages.', $step['text'], $copy[0] . ' keeps the default draft line' );
+ wp_publish_post( $draft );
+ }
}
/**
- * @testdox A store check from the last scan that couldn't run shows "Couldn't check" and doesn't block the switch.
+ * @testdox A scanned check that couldn't run is shown as such; a stale setup result in the report is not read.
*/
public function test_output_scanned_check_couldnt_check(): void {
StoreConditionsTest::make_store_ready( $this );
@@ -277,41 +388,917 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
'fix_url' => '',
),
array(
- 'id' => 'sitemap_xml',
+ 'id' => 'robots_txt',
+ 'group' => 'find',
+ 'ok' => true,
+ 'level' => 'recommended',
+ 'name' => 'Robots file allows AI assistants',
+ 'fix_url' => '',
+ ),
+ array(
+ 'id' => 'sitemap_xml',
+ 'group' => 'find',
+ 'ok' => null,
+ 'level' => 'recommended',
+ 'name' => 'Sitemap lists your products',
+ 'fix_url' => '',
+ ),
+ ),
+ ),
+ false
+ );
+
+ $titles = $this->titles( $this->view() );
+
+ $this->assertContains( 'Sitemap lists your products', $titles );
+ $this->assertSame( 'unknown', $this->row( 'Sitemap lists your products' )['state'] );
+ $this->assertNotContains( 'Stale launched result', $titles, 'Live conditions are read now, not from the report' );
+ }
+
+ /**
+ * @testdox A check that couldn't run says why on its row; a card none of whose checks ran says why once, for coming soon mode or a host that blocks the store's own pages.
+ */
+ public function test_output_couldnt_check_message_follows_coming_soon(): void {
+ StoreConditionsTest::make_store_ready( $this );
+ $sitemap = array(
+ 'id' => 'sitemap_xml',
+ 'group' => 'find',
+ 'ok' => null,
+ 'level' => 'recommended',
+ 'name' => 'Sitemap lists your products',
+ 'fix_url' => '',
+ );
+ $robots = array(
+ 'id' => 'robots_txt',
+ 'group' => 'find',
+ 'ok' => true,
+ 'level' => 'recommended',
+ 'name' => 'Robots file allows AI assistants',
+ 'fix_url' => '',
+ );
+ update_option( AgentReadiness::REPORT_OPTION, array( 'store_checks' => array( $sitemap, $robots ) ), false );
+ $this->assertSame( 'This couldn\'t be checked. The next check tries again.', $this->row( 'Sitemap lists your products' )['text'] );
+
+ update_option( AgentReadiness::REPORT_OPTION, array( 'store_checks' => array( $sitemap, array( 'ok' => null ) + $robots ) ), false );
+ $card = array_column( $this->view()['sections'], null, 'id' )['find'];
+ $this->assertSame( 'Couldn’t check', $card['badge']['text'] );
+ $this->assertSame( array( 'We couldn’t check your pages' ), array_column( $card['rows'], 'title' ), 'One row for the card, not one per check' );
+ $this->assertSame( 'Your host stopped the store from opening its own pages. Try again later, or ask your host.', $card['rows'][0]['text'] );
+
+ update_option( 'woocommerce_coming_soon', 'yes' );
+ $card = array_column( $this->view()['sections'], null, 'id' )['find'];
+ $this->assertSame( 'They show your coming soon page until the store is live.', $card['rows'][0]['text'] );
+ }
+
+ /**
+ * @testdox With UCP already on and a required check failing, the switch stays on and the checklist asks for the required steps, without saying assistants can shop.
+ */
+ public function test_output_switch_on_with_failing_checks(): void {
+ remove_all_filters( 'pre_option_home' );
+ update_option( 'woocommerce_coming_soon', 'yes' );
+ update_option( 'home', 'http://example.org' );
+ $html = $this->render_page( AgenticCommerceSettings::SHOPPING_SECTION, true );
+
+ $this->assertStringContainsString( 'aria-checked="true"', $html );
+ $this->assertStringNotContainsString( 'AI assistants can now find and shop your store.', $html );
+ $this->assertMatchesRegularExpression( '#<p>Finish \d+ required steps? to get your store ready for AI shopping\.</p>#', $html );
+
+ $shopping = $this->view()['overview']['shopping'];
+ $this->assertSame(
+ array(
+ 'intent' => 'low',
+ 'text' => 'Needs attention',
+ ),
+ $shopping['badge'],
+ 'The Overview card says so too'
+ );
+ $this->assertMatchesRegularExpression( '#^AI assistants can\'t shop your store yet\. \d+ steps? left\.$#', $shopping['text'] );
+ $this->assertSame( 'Manage', $shopping['button']['text'], 'and Manage opens AI shopping' );
+ $this->assertStringContainsString( 'section=shopping', $shopping['button']['href'] );
+ }
+
+ /**
+ * @testdox Sales readiness badges each merchant question, marks a likely conflict with the page but names no plugin, hides checks whose prerequisite failed, and folds passed checks away.
+ */
+ public function test_output_groups_summary_and_conflict(): void {
+ $this->make_every_step_pass();
+ $row = static fn( string $id, ?bool $ok, bool $conflict = false ): array => array(
+ 'id' => $id,
+ 'ok' => $ok,
+ 'blocks' => 'discovery',
+ 'group' => str_starts_with( $id, 'product_' ) ? 'understand' : 'find',
+ 'name' => $id . ' name',
+ 'label' => $id . ' label',
+ 'why' => $id . ' why',
+ 'fix' => $id . ' fix',
+ 'fix_url' => '',
+ 'conflict' => $conflict,
+ );
+ update_option(
+ 'woocommerce_agent_readiness_report',
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array(
+ array_merge(
+ $row( 'product_jsonld_present', false, true ),
+ array(
+ 'seen_at' => 'https://example.org/product/mug/',
+ // A report stored before plugin names were dropped.
+ 'plugins' => array( 'Yoast SEO', 'Rank Math SEO' ),
+ )
+ ),
+ $row( 'product_offer_jsonld', null ),
+ $row( 'sitemap_lists_products', true ),
+ ),
+ )
+ );
+
+ $view = $this->view();
+ $sections = array_column( $view['sections'], null, 'id' );
+ $json = wp_json_encode( $view );
+
+ $this->assertSame(
+ array( 'Store access', 'Can AI assistants find your store?', 'Can AI assistants read your product details?', 'Can AI assistants list your products?', 'Can shoppers buy through AI assistants?' ),
+ array_column( $view['sections'], 'title' ),
+ 'Products come before Can shoppers buy through AI assistants?'
+ );
+ $this->assertSame( 'AI shopping is off, so we didn’t check your connection URL.', $sections['access']['note'], 'UCP is off in this test' );
+ $this->assertSame(
+ array(
+ 'intent' => 'low',
+ 'text' => '1 issue',
+ ),
+ $sections['understand']['badge'],
+ 'The failing check is the issue; the unrun one is hidden'
+ );
+ $this->assertSame(
+ array(
+ 'intent' => 'stable',
+ 'text' => 'All passed',
+ ),
+ $sections['find']['badge']
+ );
+ $conflict = $sections['understand']['rows'][0];
+ $this->assertSame( 'Add product details AI assistants can read', $conflict['title'], 'A failing check is headed by what to do' );
+ $this->assertStringEndsWith( 'We found none on a recent product page.', $conflict['text'], 'then why it matters and what the check found' );
+ $this->assertStringStartsWith( 'Test a product page in Google', $conflict['fix'], 'and the fix, since it has one' );
+ $this->assertSame(
+ array(
+ 'intent' => 'none',
+ 'text' => 'Likely conflict',
+ ),
+ $conflict['badge']
+ );
+ $this->assertSame(
+ array(
+ 'href' => 'https://example.org/product/mug/',
+ 'text' => 'https://example.org/product/mug/',
+ ),
+ $conflict['seen_at'],
+ 'A conflict names the page'
+ );
+ $report = get_option( 'woocommerce_agent_readiness_report' );
+ $report['store_checks'][0]['seen_at'] = 'javascript:alert(1)';
+ $report['store_checks'][0]['fix_url'] = 'javascript:alert(1)';
+ update_option( 'woocommerce_agent_readiness_report', $report );
+ $row = array_column( $this->view()['sections'], null, 'id' )['understand']['rows'][0];
+ $this->assertNull( $row['seen_at'], 'A stored page that is not an http(s) URL is not linked' );
+ $this->assertNull( $row['link'], 'nor is a stored fix URL' );
+ $sitemap = $this->view_with_check( 'sitemap_lists_products' )['sections'][1]['rows'][0];
+ $this->assertSame( 'Add a sitemap that lists your products', $sitemap['title'] );
+ $this->assertStringContainsString( 'SEO plugin', $sitemap['fix'], 'A failed row says where to fix it' );
+ $this->assertNull( $sitemap['badge'], 'Only a blocker is Required' );
+ $this->assertStringNotContainsString( 'Yoast SEO', $json, 'No plugin is named, even from an older stored report' );
+ $this->assertStringNotContainsString( 'product_offer_jsonld name', $json, 'Its prerequisite failed' );
+ $this->assertStringNotContainsString( 'product_jsonld_present name', $json );
+ $this->assertStringNotContainsString( 'sitemap_lists_products label', $json, 'A passed check keeps its passing title' );
+ $this->assertSame( array(), $sections['find']['rows'], 'Nothing open under find' );
+ $passed = array_column( $sections['find']['folded'], null, 'title' )['A sitemap lists your products'] ?? null;
+ $this->assertNotNull( $passed, 'Passed checks are folded, under their passing title' );
+ $this->assertSame( 'Crawlers use the sitemap to find new and changed products.', $passed['text'], 'with why it matters' );
+ $this->assertStringNotContainsString( 'sitemap_lists_products why', $json, 'A passed scanned check drops the report\'s failure-worded why' );
+ $this->assertStringNotContainsString( 'Order confirmation emails are on', (string) wp_json_encode( $sections ), 'Setup steps stay in the Setup checklist' );
+ $this->assertStringNotContainsString( 'Shoppers who buy through an agent get no confirmation from your store.', $json, 'A passed setup step drops its failure-worded why, as in Status' );
+ }
+
+ /**
+ * @testdox What the store shares is information: how many items were found, every item behind a fold, and no badge.
+ */
+ public function test_output_declared_block(): void {
+ $this->make_every_step_pass();
+ update_option(
+ 'woocommerce_agent_readiness_report',
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array(),
+ 'declared' => array(
+ array(
+ 'id' => 'ai-txt',
+ 'name' => 'ai.txt usage file',
+ 'found' => true,
+ ),
+ array(
+ 'id' => 'agents-md',
+ 'name' => 'AGENTS.md',
+ 'found' => false,
+ ),
+ array(
+ 'id' => 'tdmrep',
+ 'name' => 'TDMRep',
+ 'found' => null,
+ ),
+ ),
+ )
+ );
+
+ $view = $this->view();
+
+ $this->assertSame( 'What does your store share with AI assistants?', $view['declared']['title'] );
+ $this->assertSame( 'Optional files that some AI assistants look for. You don’t need to fix anything. Found 1 of 3.', $view['declared']['text'] );
+ $this->assertSame( 'Optional', $view['declared']['badge']['text'] );
+ $this->assertSame(
+ array(
+ array(
+ 'name' => 'ai.txt usage file',
+ 'found' => true,
+ ),
+ array(
+ 'name' => 'AGENTS.md',
+ 'found' => false,
+ ),
+ array(
+ 'name' => 'TDMRep',
+ 'found' => false,
+ ),
+ ),
+ $view['declared']['items'],
+ 'Every item, found or not'
+ );
+ $this->assertSame(
+ array(
+ 'intent' => 'none',
+ 'text' => 'Not checked yet',
+ ),
+ array_column( $view['sections'], 'badge', 'id' )['find'],
+ 'Not counted as a result; the search engine step is in the Setup checklist, so the card has no checks'
+ );
+ }
+
+ /**
+ * @testdox A bad stored entry isn't counted and doesn't break the page; with no items there is no card.
+ */
+ public function test_output_declared_none_found_and_bad_entries(): void {
+ update_option(
+ 'woocommerce_agent_readiness_report',
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array(),
+ 'declared' => array(
+ array(
+ 'id' => 'ai-txt',
+ 'name' => 'ai.txt usage file',
+ 'found' => false,
+ ),
+ 'not an array',
+ ),
+ )
+ );
+
+ $this->assertStringContainsString( 'You don’t need to fix anything. Found 0 of 1.', $this->view()['declared']['text'] );
+
+ update_option(
+ 'woocommerce_agent_readiness_report',
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array(),
+ 'declared' => array(),
+ )
+ );
+ $this->assertNull( $this->view()['declared'] );
+ }
+
+ /**
+ * @testdox Fix first keeps ranking an issue by its share after its count changes, and names sales only when an issue on the card sold something.
+ */
+ public function test_output_fix_first_stale_share_and_no_sales(): void {
+ $this->make_every_step_pass();
+ $check = static fn( string $id, int $count, ?float $share, array $extra = array() ): array => $extra + array(
+ 'id' => $id,
+ 'label' => $id . ' label',
+ 'why' => $id . ' why.',
+ 'fix' => $id . ' fix.',
+ 'channels' => array(
+ 'chatgpt' => array(
+ 'field' => 'field',
+ 'effect' => ReadinessRule::EFFECT_NOT_LISTABLE,
+ ),
+ ),
+ 'count' => $count,
+ 'product_ids' => array(),
+ 'sales_share' => $share,
+ );
+ $report = array(
+ 'generated_at' => gmdate( 'c' ),
+ 'products' => 120,
+ 'store_checks' => array(),
+ 'channels' => array( 'chatgpt' => array( 'name' => 'ChatGPT' ) ),
+ 'checks' => array(
+ $check( 'missing_brand', 30, 0.01 ),
+ $check( 'missing_images', 99, null, array( 'ranked_share' => 0.6 ) ),
+ ),
+ 'sales' => array(
+ 'days' => 90,
+ 'orders' => 30,
+ ),
+ );
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+
+ $fix_first = $this->view()['fix_first'];
+ $this->assertSame( array( 'missing_images', 'missing_brand' ), array_column( $fix_first['items'], 'id' ), 'An issue whose count changed since the check keeps the rank its sales gave it' );
+ $this->assertStringNotContainsString( 'of your sales', $fix_first['items'][0]['why'], 'Its share is not shown, since it was measured on other products' );
+ $this->assertStringStartsWith( '1% of your sales in the last 90 days.', $fix_first['items'][1]['why'], 'The first share shown says the period' );
+
+ $report['checks'][0]['sales_share'] = 0.0;
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+ $fix_first = $this->view()['fix_first'];
+ $this->assertSame( 'Ranked by how many products each issue affects.', $fix_first['ranking'], 'No issue on the card sold anything, so sales did not decide the order' );
+ $this->assertStringStartsWith( 'No sales in the last 90 days.', $fix_first['items'][1]['why'] );
+ }
+
+ /**
+ * @testdox Fix first lists the failing required steps, then the top 3 issues: what keeps products off a channel, then what makes them harder to find, each ranked by its share of sales.
+ */
+ public function test_output_fix_first_ranks_by_sales(): void {
+ $this->make_every_step_pass();
+ remove_all_filters( 'pre_option_home' );
+ update_option( 'home', 'http://example.org' );
+ $check = static fn( string $id, int $count, ?float $share, string $effect ): array => array(
+ 'id' => $id,
+ 'label' => $id . ' label',
+ 'why' => $id . ' why.',
+ 'fix' => $id . ' fix.',
+ 'channels' => array(
+ 'chatgpt' => array(
+ 'field' => 'field',
+ 'effect' => $effect,
+ ),
+ ),
+ 'count' => $count,
+ 'product_ids' => array(),
+ 'sales_share' => $share,
+ );
+ $report = array(
+ 'generated_at' => gmdate( 'c' ),
+ 'products' => 40,
+ 'store_checks' => array(),
+ 'channels' => array(
+ 'chatgpt' => array( 'name' => 'ChatGPT' ),
+ 'broken' => 'not an array',
+ ),
+ 'checks' => array(
+ $check( 'missing_gtin', 30, 0.6, ReadinessRule::EFFECT_GAPS ),
+ $check( 'missing_brand', 2, 0.05, ReadinessRule::EFFECT_NOT_LISTABLE ),
+ $check( 'missing_images', 5, 0.18, ReadinessRule::EFFECT_NOT_LISTABLE ),
+ $check( 'title_too_long', 1, 0.001, ReadinessRule::EFFECT_GAPS ),
+ ),
+ 'sales' => array(
+ 'days' => 90,
+ 'orders' => 30,
+ ),
+ );
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+
+ $fix_first = $this->view()['fix_first'];
+ $this->assertSame( 'Start with the fixes that affect the most sales. Sales figures are from the last 90 days.', $fix_first['ranking'] );
+ update_option( AgentReadiness::REPORT_OPTION, array_replace_recursive( $report, array( 'sales' => array( 'days' => 1 ) ) ) );
+ $this->assertSame( 'Start with the fixes that affect the most sales. Sales figures are from the last 1 day.', $this->view()['fix_first']['ranking'], 'One day reads in the singular' );
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+ $this->assertSame(
+ array( 'Use a secure connection (HTTPS)', 'Add a main image to 5 products', 'Add a brand to 2 products', 'Add barcode numbers to 30 products' ),
+ array_column( $fix_first['items'], 'title' ),
+ 'The required step, then 3 issues: the not listable checks by share, then GTIN, a gap, despite its larger share; the title, a smaller gap, is left out'
+ );
+ $this->assertSame( array( 'Required for AI shopping', 'Needed to list products', 'Needed to list products', 'Helps shoppers find products' ), array_column( $fix_first['items'], 'tier' ) );
+ $this->assertSame( array( 'Required', null, null, null ), array_map( static fn( array $item ): ?string => $item['badge']['text'] ?? null, $fix_first['items'] ), 'Only the Required heading has a badge' );
+ $this->assertArrayNotHasKey( 'impact', $fix_first['items'][1], 'The share of sales is in the line, so no badge repeats it' );
+ $this->assertSame( '18% of your sales in the last 90 days. AI assistants only list products that have a main image.', $fix_first['items'][1]['why'], 'The first share says over which period, then why the issue matters' );
+ $this->assertSame( '5% of your sales. ChatGPT only lists products that have a brand. In Google and Copilot, a brand makes products easier to find.', $fix_first['items'][2]['why'], 'The next ones give only the share' );
+ $this->assertNotEmpty( $fix_first['items'][0]['link']['text'] ?? '', 'A setup step links to where to fix it' );
+ $this->assertSame(
+ array(
+ 'href' => '',
+ 'text' => '5 products',
+ ),
+ $fix_first['items'][1]['link'],
+ 'A product issue names how many products it affects; no stored failures, so no list to link'
+ );
+
+ $report['checks'][1]['sales_share'] = 0.0;
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+ $json = wp_json_encode( $this->view() );
+ $this->assertStringContainsString( 'No sales. ChatGPT only lists products that have a brand.', $json, 'Products that sold nothing in the period say so, not 0%' );
+ $this->assertStringNotContainsString( '"0% of', $json );
+ $report['checks'][1]['sales_share'] = 0.003;
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+ $view = $this->view();
+ $this->assertStringContainsString( 'under 1% of your sales', wp_json_encode( $view['fix_first'] ), 'A share under 1% is not rounded to 0%' );
+ $this->assertStringNotContainsString( 'under 1%', wp_json_encode( $view['sections'] ), 'Shares are in Fix first only, not on the product card' );
+
+ $report['sales'] = null;
+ foreach ( $report['checks'] as &$row ) {
+ $row['sales_share'] = null;
+ }
+ unset( $row );
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+ $fix_first = $this->view()['fix_first'];
+ $this->assertSame( 'Ranked by how many products each issue affects. Turn on Analytics to rank by sales instead.', $fix_first['ranking'] );
+ $this->assertStringNotContainsString( 'of your sales', wp_json_encode( $fix_first ) );
+
+ $report['sales'] = array(
+ 'days' => 90,
+ 'orders' => 30,
+ );
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+ $this->assertSame( 'Ranked by how many products each issue affects.', $this->view()['fix_first']['ranking'], 'Orders with no share to rank by, such as free products or counts changed since the check' );
+
+ $report['sales'] = array(
+ 'days' => 90,
+ 'orders' => 12,
+ );
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+ $this->assertSame( 'Only 12 orders in the last 90 days, too few to rank by sales, so issues are ranked by how many products they affect.', $this->view()['fix_first']['ranking'] );
+
+ $report['sales'] = array(
+ 'days' => 90,
+ 'orders' => 0,
+ );
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+ $this->assertSame( 'No sales in the last 90 days, so issues are ranked by how many products they affect.', $this->view()['fix_first']['ranking'] );
+
+ $report['sales'] = array(
+ 'days' => 90,
+ 'orders' => 0,
+ 'imported' => false,
+ );
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+ $this->assertSame( 'Analytics hasn\'t imported all your past orders yet, so issues are ranked by how many products they affect. Import them in Analytics > Settings.', $this->view()['fix_first']['ranking'], 'Missing orders don\'t read as no sales' );
+
+ unset( $report['sales'] );
+ update_option( AgentReadiness::REPORT_OPTION, $report );
+ $this->assertSame( 'Ranked by how many products each issue affects.', $this->view()['fix_first']['ranking'], 'A report from before sales were read doesn\'t say Analytics is off' );
+ }
+
+ /**
+ * @testdox In Fix first, store pages agents can't reach stop every sale; any other check that blocks listing keeps products off a channel.
+ */
+ public function test_output_fix_first_tiers_store_checks(): void {
+ $this->make_every_step_pass();
+ $output = static fn( string $id, string $group ): array => array(
+ 'id' => $id,
+ 'ok' => false,
+ 'blocks' => 'listing',
+ 'group' => $group,
+ 'level' => 'recommended',
+ 'name' => $id . ' name',
+ 'label' => $id . ' label',
+ 'why' => $id . ' why.',
+ 'fix' => $id . ' fix.',
+ 'fix_url' => '',
+ 'conflict' => false,
+ );
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'products' => 4,
+ 'store_checks' => array( $output( 'other_listing_check', 'understand' ), $output( 'pages_public', 'access' ) ),
+ 'channels' => array(),
+ 'checks' => array(),
+ )
+ );
+
+ $items = $this->view()['fix_first']['items'];
+ $this->assertSame(
+ array(
+ array( 'Required for AI shopping', 'Let shoppers open store pages without logging in' ),
+ array( 'Needed to list products', 'other_listing_check label' ),
+ ),
+ array_map( static fn( array $item ): array => array( $item['tier'], $item['title'] ), $items ),
+ 'Store pages AI assistants can\'t reach are a blocker, so Required; a check without copy keeps the report\'s title'
+ );
+
+ update_option(
+ RemoteRules::OPTION,
+ array(
+ 'version' => '2026-11-15',
+ 'checks' => array(),
+ 'store_checks' => array(
+ 'pages_public' => array( 'required' => false ),
+ 'other_listing_check' => array( 'required' => true ),
+ ),
+ ),
+ false
+ );
+ $this->assertSame(
+ array( 'other_listing_check', 'pages_public' ),
+ array_column( $this->view()['fix_first']['items'], 'id' ),
+ 'The rules file sets which output checks are Required, as for setup steps'
+ );
+ $this->assertSame( array( 'Required for AI shopping', 'Needed to list products' ), array_column( $this->view()['fix_first']['items'], 'tier' ) );
+ }
+
+ /**
+ * @testdox A store with no products shows the product cards' No products state, with a way to add one, instead of their checks.
+ */
+ public function test_output_no_products(): void {
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'products' => 0,
+ 'store_checks' => array(),
+ 'channels' => array(),
+ 'checks' => array(),
+ )
+ );
+
+ $sections = array_column( $this->view()['sections'], null, 'id' );
+ foreach ( array( 'products', 'understand' ) as $id ) {
+ $this->assertSame( 'No products', $sections[ $id ]['badge']['text'], $id . ' says why it has no checks' );
+ $this->assertSame( array(), array_merge( $sections[ $id ]['rows'], $sections[ $id ]['folded'] ) );
+ $this->assertSame( 'You don’t have any products yet', $sections[ $id ]['empty']['title'] );
+ $this->assertSame( 'Add a product', $sections[ $id ]['empty']['link']['text'] );
+ $this->assertStringContainsString( 'post-new.php?post_type=product', $sections[ $id ]['empty']['link']['href'] );
+ }
+ $this->assertNull( $sections['find']['empty'], 'Store cards keep their checks' );
+ }
+
+ /**
+ * @testdox A store whose only product is grouped is not told it has no products.
+ */
+ public function test_output_grouped_product_is_not_an_empty_store(): void {
+ $grouped = new \WC_Product_Grouped();
+ $grouped->set_name( 'Grouped only' );
+ $grouped->save();
+
+ $report = wc_get_container()->get( AgentReadiness::class )->get_report();
+ $this->assertSame( 0, $report['products'], 'A grouped product is not one the scan checks' );
+ $this->assertGreaterThan( 0, $report['unsupported_types'] );
+ update_option( AgentReadiness::REPORT_OPTION, $report, false );
+
+ $this->assert_products_are_unreadable();
+
+ $report['unsupported_types'] = 0;
+ $report['hidden_from_catalog'] = 1;
+ update_option( AgentReadiness::REPORT_OPTION, $report, false );
+ $this->assert_products_are_unreadable();
+ }
+
+ /**
+ * The product cards when the scan checked nothing because every product is hidden or unsupported.
+ */
+ private function assert_products_are_unreadable(): void {
+ $sections = array_column( $this->view()['sections'], null, 'id' );
+ foreach ( array( 'products', 'understand' ) as $id ) {
+ $this->assertSame( 'Not checked', $sections[ $id ]['badge']['text'], $id );
+ $this->assertSame( 'None of your products can be checked yet', $sections[ $id ]['empty']['title'] );
+ $this->assertSame( 'View product visibility', $sections[ $id ]['empty']['link']['text'] );
+ $this->assertStringContainsString( 'section=' . AgenticCommerceSettings::SHOPPING_SECTION, $sections[ $id ]['empty']['link']['href'] );
+ $this->assertStringContainsString( '#wc-agentic-commerce-visibility', $sections[ $id ]['empty']['link']['href'] );
+ $this->assertStringNotContainsString( 'post-new.php', $sections[ $id ]['empty']['link']['href'] );
+ }
+ }
+
+ /**
+ * @testdox In Fix first, a store-wide listing issue ranks above product issues in the same tier, whatever their share of sales.
+ */
+ public function test_output_fix_first_store_wide_issue_ranks_first(): void {
+ $this->make_every_step_pass();
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'products' => 40,
+ 'store_checks' => array(
+ array(
+ 'id' => 'store_wide',
+ 'ok' => false,
+ 'blocks' => 'listing',
+ 'group' => 'understand',
+ 'level' => 'recommended',
+ 'name' => 'store_wide name',
+ 'label' => 'store_wide label',
+ 'why' => 'store_wide why.',
+ 'fix' => 'store_wide fix.',
+ 'fix_url' => '',
+ 'conflict' => false,
+ ),
+ ),
+ 'channels' => array( 'chatgpt' => array( 'name' => 'ChatGPT' ) ),
+ 'checks' => array(
+ array(
+ 'id' => 'missing_images',
+ 'label' => 'missing_images label',
+ 'why' => 'missing_images why.',
+ 'fix' => 'missing_images fix.',
+ 'channels' => array(
+ 'chatgpt' => array(
+ 'field' => 'field',
+ 'effect' => ReadinessRule::EFFECT_NOT_LISTABLE,
+ ),
+ ),
+ 'count' => 30,
+ 'product_ids' => array(),
+ 'sales_share' => 0.9,
+ ),
+ ),
+ 'sales' => array(
+ 'days' => 90,
+ 'orders' => 30,
+ ),
+ )
+ );
+
+ $items = $this->view()['fix_first']['items'];
+ $this->assertSame( 'store_wide label', $items[0]['title'], 'It keeps every product off, so it ranks as all sales' );
+ $this->assertStringStartsWith( '90% of your sales', $items[1]['why'], 'The product issue below it gives its share in the line' );
+ }
+
+ /**
+ * @testdox Fix first items and check rows carry the check's id, so the views can track clicks without translated titles.
+ */
+ public function test_view_items_carry_check_ids(): void {
+ $this->make_every_step_pass();
+ $output = static fn( string $id, string $group ): array => array(
+ 'id' => $id,
+ 'ok' => false,
+ 'blocks' => 'listing',
+ 'group' => $group,
+ 'level' => 'recommended',
+ 'name' => $id . ' name',
+ 'label' => $id . ' label',
+ 'why' => $id . ' why.',
+ 'fix' => $id . ' fix.',
+ 'fix_url' => '',
+ 'conflict' => false,
+ );
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'products' => 4,
+ 'store_checks' => array( $output( 'product_shipping_schema', 'buy' ), $output( 'pages_public', 'access' ) ),
+ 'channels' => array(),
+ 'checks' => array(),
+ )
+ );
+
+ $view = $this->view();
+ $this->assertSame( array( 'pages_public', 'product_shipping_schema' ), array_column( $view['fix_first']['items'], 'id' ) );
+ $ids = array();
+ foreach ( $view['sections'] as $section ) {
+ foreach ( array_merge( $section['rows'], $section['folded'] ) as $row ) {
+ $this->assertNotSame( '', $row['id'], $row['title'] . ' has no id' );
+ $ids[] = $row['id'];
+ }
+ }
+ $this->assertContains( 'pages_public', $ids );
+ }
+
+ /**
+ * @testdox Fix first is left out when nothing fails.
+ */
+ public function test_output_fix_first_hidden_when_nothing_fails(): void {
+ $this->make_every_step_pass();
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array(),
+ 'checks' => array(),
+ )
+ );
+ $this->assertNull( $this->view()['fix_first'] );
+ }
+
+ /**
+ * @testdox A question's badge counts its issues; a check that couldn't run isn't an issue, nor a pass.
+ */
+ public function test_group_badge(): void {
+ $badge = new \ReflectionMethod( ReadinessCheckPage::class, 'group_badge' );
+ $badge->setAccessible( true );
+ $text = static fn( array $checks ): string => $badge->invoke( null, $checks )[1];
+ $row = static fn( ?bool $ok ): array => array( 'ok' => $ok );
+
+ $this->assertSame( '2 issues', $text( array( $row( false ), $row( false ), $row( true ) ) ) );
+ $this->assertSame( '1 issue', $text( array( $row( false ), $row( null ) ) ) );
+ $this->assertSame( 'All passed', $text( array( $row( true ), $row( true ) ) ) );
+ $this->assertSame( 'No issues', $text( array( $row( true ), $row( null ) ) ), 'A check that could not run is not an issue, nor a pass' );
+ $this->assertSame( 'Not checked yet', $text( array() ) );
+ $this->assertSame( 'Not checked yet', $text( array( $row( null ), $row( null ) ) ), 'Nothing ran, so nothing is shown as passed' );
+
+ $map = new \ReflectionMethod( ReadinessCheckPage::class, 'badge_data' );
+ $map->setAccessible( true );
+ $this->assertSame( 'stable', $map->invoke( null, $badge->invoke( null, array( $row( true ) ) ) )['intent'], 'All passed is green, as in the design' );
+ $this->assertSame( 'low', $map->invoke( null, $badge->invoke( null, array( $row( false ) ) ) )['intent'], 'Issues are low' );
+ $this->assertSame( 'low', $map->invoke( null, array( 'fix', 'Required' ) )['intent'], 'Required is yellow, as in the design' );
+ $this->assertSame( 'stable', $map->invoke( null, array( 'pass', 'Active' ) )['intent'] );
+ }
+
+ /**
+ * @testdox A fix for two products names both, and one for more than three gives the count.
+ */
+ public function test_output_product_fix_names_a_few_products(): void {
+ $first = WC_Helper_Product::create_simple_product();
+ $second = WC_Helper_Product::create_simple_product();
+ $second->set_name( 'Red cap' );
+ $second->save();
+ wc_get_container()->get( AgentReadiness::class )->refresh_report();
+
+ $titles = array();
+ foreach ( $this->view()['sections'] as $section ) {
+ $titles = array_merge( $titles, array_column( array_merge( $section['rows'], $section['folded'] ), 'title' ) );
+ }
+ $brand = array_values( array_filter( $titles, static fn( string $title ): bool => 0 === strpos( $title, 'Add a brand to ' ) ) );
+ $this->assertCount( 1, $brand );
+ $this->assertStringContainsString( $first->get_name(), $brand[0], 'Both failing products are named' );
+ $this->assertStringContainsString( 'Red cap', $brand[0] );
+ $this->assertStringContainsString( ' and ', $brand[0], 'Two names are joined with "and", in either order' );
+ $named = array_filter( (array) $this->view()['fix_first']['items'], static fn( array $item ): bool => false !== strpos( $item['title'], 'Red cap' ) );
+ $this->assertNotEmpty( $named, 'Fix first has a product fix that names the products' );
+
+ WC_Helper_Product::create_simple_product();
+ WC_Helper_Product::create_simple_product();
+ wc_get_container()->get( AgentReadiness::class )->refresh_report();
+ $this->row( 'Add a brand to 4 products' );
+ $counted = array_filter( (array) $this->view()['fix_first']['items'], static fn( array $item ): bool => false !== strpos( $item['title'], ' 4 products' ) );
+ $this->assertNotEmpty( $counted, 'Fix first has a product fix that counts the products' );
+ }
+
+ /**
+ * @testdox Sales readiness shows what each channel can list and each failing check, naming the channel that can't list it, with a filtered list link, without the alt text check.
+ */
+ public function test_output_product_checks_and_store_check_detail(): void {
+ $product = WC_Helper_Product::create_simple_product();
+ $image = self::factory()->attachment->create( array( 'post_mime_type' => 'image/jpeg' ) );
+ $product->set_image_id( $image );
+ $product->save();
+ update_option( 'blog_public', '0' );
+ wc_get_container()->get( AgentReadiness::class )->refresh_report();
+
+ $view = $this->view();
+ $products = array_column( $view['sections'], null, 'id' )['products'];
+ $json = wp_json_encode( $view );
+
+ $this->assertGreaterThan( 0, array_column( get_option( AgentReadiness::REPORT_OPTION )['checks'], 'count', 'id' )['image_alt_text'] ?? 0, 'The scan found the missing alt text' );
+ $this->assertMatchesRegularExpression( '#^\d+ issues?$#', $products['badge']['text'], 'Products have their own question' );
+ $this->assertSame(
+ array(
+ 'name' => 'ChatGPT',
+ 'listable' => '0',
+ 'of' => 'of 1 can be listed',
+ ),
+ $products['channels'][0],
+ 'The count reads as one line, with no link of its own'
+ );
+ $this->assertStringStartsWith( 'Last checked today at ', $view['last_checked'] );
+ $this->assertNotNull( $view['fix_first'], 'When it last ran, Fix first, then a card per question' );
+ $brand = $this->row( 'Add a brand to ' . $product->get_name() );
+ $this->assertSame( 'ChatGPT only lists products that have a brand. In Google and Copilot, a brand makes products easier to find.', $brand['text'], 'One failing product is named in the title; the text says why a brand matters' );
+ $this->assertSame( '', $brand['fix'], 'Adding a brand needs no fix line' );
+ $this->assertStringNotContainsString( 'Required by', $json );
+ $this->assertStringNotContainsString( 'Harder to find on', $json, 'Only channels that can\'t list the product are tagged' );
+ $this->assertSame( 'View 1 product', $brand['link']['text'] );
+ $this->assertStringContainsString( 'agent_readiness=', $brand['link']['href'], 'The link opens the Products list filtered to the failing products' );
+ $this->assertStringNotContainsString( 'main image has no alt text', $json, 'Store readiness covers alt text' );
+ $this->assertStringNotContainsString( 'post=' . $product->get_id(), $json, 'No example products' );
+ $this->assertStringContainsString( 'Let search engines index your store', $this->render_page(), 'Hidden from search engines is a Recommended setup step' );
+ $this->assertNull( $view['checked_note'] );
+
+ $stored = get_option( AgentReadiness::REPORT_OPTION );
+ $stored['truncated'] = true;
+ update_option( AgentReadiness::REPORT_OPTION, $stored );
+ $this->assertSame(
+ sprintf( 'Checked the %s products you changed most recently.', number_format_i18n( ProductScan::PRODUCT_LIMIT ) ),
+ $this->view()['checked_note'],
+ 'A report without the total keeps the short note'
+ );
+ $stored['available'] = 8400;
+ update_option( AgentReadiness::REPORT_OPTION, $stored );
+ $this->assertSame(
+ sprintf( 'Checked the %s products you changed most recently, out of 8,400.', number_format_i18n( ProductScan::PRODUCT_LIMIT ) ),
+ $this->view()['checked_note'],
+ 'With the total from the same scan'
+ );
+ $this->assertSame(
+ sprintf( 'Based on your %s most recently changed products.', number_format_i18n( ProductScan::PRODUCT_LIMIT ) ),
+ $this->view()['overview']['based_on'],
+ 'The AI tools card says it after its description'
+ );
+ }
+
+ /**
+ * @testdox AI tools opens on the Overview, a React root; AI shopping's Status links to Sales readiness with the store and product issues counted together.
+ */
+ public function test_sections_and_status_links(): void {
+ $this->make_every_step_pass();
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array(
+ array(
+ 'id' => 'llms_txt_present',
'group' => 'find',
- 'ok' => null,
+ 'ok' => false,
+ 'blocks' => 'discovery',
'level' => 'recommended',
- 'name' => 'Sitemap lists your products',
+ 'name' => 'Store serves an llms.txt file',
+ 'label' => 'No llms.txt file',
+ 'why' => '',
+ 'fix' => '',
'fix_url' => '',
),
),
+ 'checks' => array(
+ array(
+ 'id' => 'image_alt_text',
+ 'count' => 3,
+ ),
+ array(
+ 'id' => 'missing_brand',
+ 'label' => 'Products with no brand',
+ 'count' => 2,
+ ),
+ ),
),
false
);
+ $this->assertSame( array( '', AgenticCommerceSettings::SHOPPING_SECTION ), array_keys( $this->page()->get_sections() ) );
+
+ $html = $this->render_page( '' );
+ $this->assertTrue( $this->save_hidden, 'Nothing on the Overview saves' );
+ $this->assertStringContainsString( '<div id="wc-agent-readiness-overview"', $html, 'The Overview is React, mounted by the settings-embed script' );
+ $this->assertMatchesRegularExpression( '#data-view="([^"]+)"#', $html );
+ preg_match( '#data-view="([^"]+)"#', $html, $match );
+ $this->assertSame( 'Set up AI shopping', json_decode( html_entity_decode( $match[1] ), true )['overview']['shopping']['button']['text'], 'The view comes with the page, so the cards draw without a request' );
+ $this->assertStringNotContainsString( 'No llms.txt file', $html );
+
+ $view = $this->view();
+ $this->assertSame( 'Set up AI shopping', $view['overview']['shopping']['button']['text'] );
+ $this->assertSame( 'View all checks', $view['overview']['view_all']['text'] );
+ $this->assertStringContainsString( 'path=/sales-readiness', $view['overview']['view_all']['href'] );
+ $badges = array_column( $view['sections'], 'badge', 'id' );
+ $this->assertSame( '1 issue', $badges['find']['text'] );
+ $this->assertSame(
+ array(
+ 'intent' => 'none',
+ 'text' => 'Not checked yet',
+ ),
+ $badges['access'],
+ 'With AI shopping off and setup steps in the Setup checklist, the fixture has no access check'
+ );
+ $this->assertSame( '1 issue', $badges['products']['text'] );
+ $this->assertNull( $view['declared'], 'No card when the report lists no declared items' );
+
$html = $this->render_page();
+ $this->assertMatchesRegularExpression( '#path=/sales-readiness">Sales readiness</a> <mark[^>]*>2 issues</mark>#', $html, 'One store and one product issue; the alt text check is not counted' );
+ $this->assertSame( 1, substr_count( $html, 'wc-agentic-commerce-results"><li>' ), 'One results row' );
+ $this->assertFalse( $this->save_hidden, 'AI shopping saves the store policy fields' );
+ $this->assertStringContainsString( '<span aria-current="page">AI shopping</span>', $html );
+ $this->assertStringNotContainsString( 'No llms.txt file', $html, 'The checks themselves are on Sales readiness' );
- $this->assertStringContainsString( 'Sitemap lists your products', $html );
- $this->assertStringContainsString( 'Couldn't check', $html );
- $this->assertStringNotContainsString( 'Stale launched result', $html, 'Live conditions are read now, not from the report' );
- $this->assertStringNotContainsString( 'to turn this on.', $html );
+ $this->assertSame(
+ array(
+ 'href' => '',
+ 'text' => '2 products',
+ ),
+ $this->row( 'Add a brand to 2 products' )['link'],
+ 'Product check titles say what to do and to how many; a report without stored failures has no filtered list to link to'
+ );
}
/**
- * @testdox A check that couldn't run says why: launch the store in coming soon mode, otherwise the store couldn't load its page.
+ * @testdox Status says no issues only when readiness checks ran; a scan whose checks couldn't run isn't shown as passed.
*/
- public function test_output_couldnt_check_message_follows_coming_soon(): void {
- StoreConditionsTest::make_store_ready( $this );
+ public function test_status_link_when_checks_could_not_run(): void {
+ $this->make_every_step_pass();
update_option(
AgentReadiness::REPORT_OPTION,
array(
+ 'generated_at' => gmdate( 'c' ),
'store_checks' => array(
array(
- 'id' => 'sitemap_xml',
+ 'id' => 'llms_txt_present',
'group' => 'find',
'ok' => null,
+ 'blocks' => 'discovery',
'level' => 'recommended',
- 'name' => 'Sitemap lists your products',
+ 'name' => 'Store serves an llms.txt file',
+ 'label' => 'No llms.txt file',
+ 'why' => '',
+ 'fix' => '',
'fix_url' => '',
),
),
@@ -319,201 +1306,179 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
false
);
- $live = $this->render_page();
- update_option( 'woocommerce_coming_soon', 'yes' );
- $coming_soon = $this->render_page();
-
- $this->assertStringContainsString( 'This couldn't be checked.', $live );
- $this->assertStringNotContainsString( 'Launch your store', $live );
- $this->assertStringContainsString( 'Launch your store to run this check.', $coming_soon );
- $this->assertStringNotContainsString( 'This couldn't be checked.', $coming_soon );
- }
-
- /**
- * @testdox With UCP already on and a required check failing, the switch says the checks still need fixing.
- */
- public function test_output_switch_on_with_failing_checks(): void {
- $page = $this->page();
- remove_all_filters( 'pre_option_home' );
- update_option( 'woocommerce_coming_soon', 'yes' );
- update_option( 'home', 'http://example.org' );
- update_option( 'woocommerce_feature_ucp_enabled', 'yes' );
-
- ob_start();
- $page->output();
- $html = (string) ob_get_clean();
-
- $this->assertStringContainsString( 'aria-checked="true"', $html );
- $this->assertStringContainsString( 'required setup checks below still need fixing.', $html );
- $this->assertStringNotContainsString( 'AI agents can now find and shop your store.</p>', $html );
+ $this->assertMatchesRegularExpression( '#Sales readiness</a> <mark class="wc-agentic-commerce-badge wc-agentic-commerce-badge--off">No issues</mark>#', $this->render_page() );
}
/**
- * @testdox The page answers each merchant question, marks a likely conflict with the page but names no plugin, hides checks whose prerequisite failed, and folds passed checks away.
+ * @testdox Guest checkout off is an Optional setup step and stays out of Fix first, since AI assistants can still build carts.
*/
- public function test_output_groups_summary_and_conflict(): void {
- $row = static fn( string $id, ?bool $ok, bool $conflict = false ): array => array(
- 'id' => $id,
- 'ok' => $ok,
- 'blocks' => 'discovery',
- 'group' => str_starts_with( $id, 'product_' ) ? 'understand' : 'find',
- 'name' => $id . ' name',
- 'label' => $id . ' label',
- 'why' => $id . ' why',
- 'fix' => $id . ' fix',
- 'fix_url' => '',
- 'conflict' => $conflict,
- );
+ public function test_guest_checkout_is_optional(): void {
+ $this->make_every_step_pass();
+ update_option( 'woocommerce_enable_guest_checkout', 'no' );
update_option(
- 'woocommerce_agent_readiness_report',
+ AgentReadiness::REPORT_OPTION,
array(
'generated_at' => gmdate( 'c' ),
- 'store_checks' => array(
- array_merge(
- $row( 'product_jsonld_present', false, true ),
- array(
- 'seen_at' => 'https://example.org/product/mug/',
- // A report stored before plugin names were dropped.
- 'plugins' => array( 'Yoast SEO', 'Rank Math SEO' ),
- )
- ),
- $row( 'product_offer_jsonld', null ),
- $row( 'sitemap_lists_products', true ),
- ),
- )
+ 'store_checks' => array(),
+ ),
+ false
);
- $html = $this->render_page();
-
- foreach ( array( 'Can agents get in?', 'Can they find your store?', 'Do they understand your products?', 'Can they buy?' ) as $question ) {
- $this->assertStringContainsString( $question, $html );
- }
- $this->assertStringContainsString( 'Agent shopping is off', $html, 'UCP is off in this test' );
- $this->assertMatchesRegularExpression( '/data-on="(?![^"]*Agent shopping is off)[^"]*" data-off="Agent shopping is off/', $html, 'The switch script can show the line for UCP on without a reload' );
- $this->assertStringContainsString( 'Likely conflict', $html );
- $this->assertStringContainsString( 'Something on your store may be replacing this.', $html );
- $this->assertStringContainsString( 'Seen on: <a href="https://example.org/product/mug/">https://example.org/product/mug/</a>', $html, 'A conflict names the page' );
- $this->assertStringNotContainsString( 'Yoast SEO', $html, 'No plugin is named, even from an older stored report' );
- $this->assertStringNotContainsString( 'product_offer_jsonld name', $html, 'Its prerequisite failed' );
- $this->assertMatchesRegularExpression( '#<details>.*sitemap_lists_products name.*</details>#s', $html );
+ $items = array_column( $this->view()['fix_first']['items'] ?? array(), 'tier', 'id' );
+ $this->assertArrayNotHasKey( 'guest_checkout', $items, 'No heading says Required for an Optional step' );
+ $this->assertSame( array(), wc_get_container()->get( StoreConditions::class )->failing_required(), 'It doesn\'t keep AI shopping from being turned on' );
}
/**
- * @testdox The declared list shows found and not found as information, and isn't counted in the summary.
+ * @testdox "Discourage search engines" and a missing payment method are Required in Fix first and the Setup checklist, but don't keep AI shopping from being turned on.
*/
- public function test_output_declared_block(): void {
+ public function test_search_and_payments_are_shown_required_without_blocking(): void {
+ $this->make_every_step_pass();
+ update_option( 'blog_public', '0' );
+ $emails = array_intersect_key( WC()->mailer()->get_emails(), array_flip( array( 'WC_Email_Customer_Processing_Order', 'WC_Email_Customer_Completed_Order' ) ) );
+ foreach ( $emails as $email ) {
+ $this->restore[] = array( $email, $email->enabled );
+ $email->enabled = 'no';
+ }
+ foreach ( WC()->payment_gateways()->payment_gateways() as $gateway ) {
+ $this->restore[] = array( $gateway, $gateway->enabled );
+ $gateway->enabled = 'no';
+ }
update_option(
- 'woocommerce_agent_readiness_report',
+ AgentReadiness::REPORT_OPTION,
array(
'generated_at' => gmdate( 'c' ),
'store_checks' => array(),
- 'declared' => array(
- array(
- 'id' => 'ai-txt',
- 'name' => 'ai.txt usage file',
- 'found' => true,
- ),
- array(
- 'id' => 'agents-md',
- 'name' => 'AGENTS.md',
- 'found' => false,
- ),
- ),
- )
+ ),
+ false
);
- $html = $this->render_page();
-
- $this->assertStringContainsString( '1 of 2 found', $html );
- $this->assertStringContainsString( 'Not found', $html );
- $this->assertStringNotContainsString( 'AGENTS.md</td><td>Fix', $html );
- $this->assertMatchesRegularExpression( '#Can they find your store\?</a>\s*Run check to find out#', $html, 'Not counted as a result' );
- }
-
- /**
- * @testdox The declared summary says what couldn't be checked, and a bad stored entry doesn't break the page.
- */
- public function test_output_declared_unknown_and_bad_entries(): void {
- $report = static fn( array $declared ): array => array(
- 'generated_at' => gmdate( 'c' ),
- 'store_checks' => array(),
- 'declared' => $declared,
- );
- $item = static fn( ?bool $found ): array => array(
- 'id' => 'ai-txt',
- 'name' => 'ai.txt usage file',
- 'found' => $found,
- );
+ $items = array_column( $this->view()['fix_first']['items'], null, 'id' );
+ $this->assertSame( 'Required for AI shopping', $items['search_visible']['tier'] );
+ $this->assertSame( 'Required for AI shopping', $items['payment_method']['tier'] );
+ $this->assertSame( array(), wc_get_container()->get( StoreConditions::class )->failing_required(), 'Neither blocks the switch' );
- update_option( 'woocommerce_agent_readiness_report', $report( array( $item( null ), $item( null ), 'not an array' ) ) );
$html = $this->render_page();
- $this->assertStringContainsString( '<summary>Not checked</summary>', $html );
- $this->assertStringNotContainsString( '0 of', $html );
+ $this->assertMatchesRegularExpression( '#Finish 2 required steps#', $html );
+ $this->assertLessThan( strpos( $html, 'wc-agentic-commerce-item--open' ), strrpos( $html, 'wc-agentic-commerce-item--required' ), 'They come before the optional order emails step' );
+ $this->assertMatchesRegularExpression( '#Sales readiness</a> <mark[^>]*>2 issues</mark>#', $html, 'Status counts what Sales readiness shows: both; order emails are only in the Setup checklist' );
- update_option( 'woocommerce_agent_readiness_report', $report( array( $item( true ), $item( false ), $item( null ) ) ) );
- $this->assertStringContainsString( '1 of 3 found, 1 not checked', $this->render_page() );
+ foreach ( $emails as $email ) {
+ $email->enabled = 'yes';
+ }
+ delete_option( AgenticCommerceSettings::PRIVACY_PAGE_OPTION );
+ $this->assertMatchesRegularExpression( '#Sales readiness</a> <mark[^>]*>2 issues</mark>#', $this->render_page(), 'A missing policy page is only in the Setup checklist, so not counted' );
+ $this->assertDoesNotMatchRegularExpression( '/<button[^>]*wc-agentic-commerce-ucp-switch[^>]*disabled=([\'"])disabled\\1/', $html );
}
/**
- * @testdox Every question reads the scan, so without one each asks for it; pending checks don't count as unchecked.
+ * @testdox With AI shopping on, a connection URL or catalog search that fails is Required and in Fix first.
*/
- public function test_groups_need_a_scan(): void {
- $summary = new \ReflectionMethod( AgenticCommerceSettingsPage::class, 'group_summary' );
- $summary->setAccessible( true );
- $passed = array(
- array(
- 'ok' => true,
- 'level' => 'recommended',
- ),
+ public function test_failing_ucp_profile_and_endpoint_are_required(): void {
+ $this->make_every_step_pass();
+ update_option( 'woocommerce_feature_ucp_enabled', 'yes' );
+ $row = static fn( string $id ): array => array(
+ 'id' => $id,
+ 'ok' => false,
+ 'blocks' => 'ucp',
+ 'group' => 'access',
+ 'name' => 'name',
+ 'label' => 'label',
+ 'why' => 'why',
+ 'fix' => 'fix',
+ 'fix_url' => '',
+ 'conflict' => false,
+ 'pending' => false,
);
-
- $pending = array(
+ update_option(
+ AgentReadiness::REPORT_OPTION,
array(
- 'ok' => null,
- 'level' => 'recommended',
- 'pending' => true,
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array( $row( 'ucp_profile' ), $row( 'ucp_endpoints_live' ), $row( 'ucp_profile_version' ) ),
),
+ false
);
- $this->assertSame( 'Run check to find out', $summary->invoke( null, 'buy', $passed, false, 0, false, true ) );
- $this->assertSame( 'Yes', $summary->invoke( null, 'buy', $passed, true, 0, false, true ) );
- $this->assertSame( 'Yes', $summary->invoke( null, 'buy', array_merge( $passed, $pending ), true, 0, false, true ) );
- $this->assertSame( 'Coming soon', $summary->invoke( null, 'buy', $pending, true, 0, false, true ), 'Only pending checks answer nothing yet' );
- $this->assertSame( 'Run check to find out', $summary->invoke( null, 'access', $passed, true, 0, false, true ), 'A scan from before UCP was on does not answer access' );
- $this->assertSame( 'Yes', $summary->invoke( null, 'access', $passed, true, 0, true, true ) );
+ $view = $this->view();
+ $items = array_column( $view['fix_first']['items'], 'tier', 'id' );
+ $this->assertSame( 'Required for AI shopping', $items['ucp_profile'] );
+ $this->assertSame( 'Required for AI shopping', $items['ucp_endpoints_live'] );
+ $this->assertArrayNotHasKey( 'ucp_profile_version', $items, 'A different version is likely another plugin, not a blocker' );
+ $this->assertSame( 'Required', array_column( array_column( $view['sections'], null, 'id' )['access']['rows'], 'badge', 'id' )['ucp_profile']['text'] );
}
/**
- * @testdox Examples skip deleted products, so a deleted product doesn't leave the cell empty.
+ * @testdox A missing returns policy in the product details shows once, as the refund and returns page step, while no page is chosen.
*/
- public function test_examples_skip_deleted_products(): void {
- $kept = \WC_Helper_Product::create_simple_product();
- $links = new \ReflectionMethod( AgenticCommerceSettingsPage::class, 'product_links' );
- $links->setAccessible( true );
+ public function test_returns_policy_shows_once_with_the_refund_page_step(): void {
+ $this->make_every_step_pass();
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array(
+ array(
+ 'id' => 'product_return_policy_schema',
+ 'ok' => false,
+ 'blocks' => 'checkout',
+ 'group' => 'buy',
+ 'name' => 'name',
+ 'label' => 'label',
+ 'why' => 'why',
+ 'fix' => 'fix',
+ 'fix_url' => '',
+ 'conflict' => false,
+ 'pending' => false,
+ ),
+ ),
+ ),
+ false
+ );
+ $title = ReadinessCopy::store_check( 'product_return_policy_schema' )['action'];
- wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
- $result = $links->invoke( $this->page(), array( 999991, 999992, 999993, $kept->get_id() ) );
+ $this->assertStringContainsString( $title, (string) wp_json_encode( $this->view() ), 'Shown while a refund and returns page is chosen' );
- $this->assertCount( 1, $result );
- $this->assertStringContainsString( (string) $kept->get_id(), $result[0] );
+ delete_option( AgenticCommerceSettings::REFUND_RETURNS_PAGE_OPTION );
+ $this->assertStringNotContainsString( $title, (string) wp_json_encode( $this->view() ), 'Left out while the step fails' );
}
/**
- * @testdox The page shows each failing product check with its channel tags and example products, and a failing setup check says what to do.
+ * @testdox Checks coming in a later update aren't shown or counted, and an open check names its fix and links to it.
*/
- public function test_output_product_checks_and_store_check_detail(): void {
- $product = WC_Helper_Product::create_simple_product();
- update_option( 'blog_public', '0' );
- wc_get_container()->get( AgentReadiness::class )->refresh_report();
-
- $html = $this->render_page();
+ public function test_readiness_hides_pending_checks(): void {
+ $this->make_every_step_pass();
+ $row = static fn( string $id, ?bool $ok, bool $pending = false ): array => array(
+ 'id' => $id,
+ 'ok' => $ok,
+ 'blocks' => 'checkout',
+ 'group' => 'buy',
+ 'name' => $id . ' name',
+ 'label' => $id . ' label',
+ 'why' => $id . ' why',
+ 'fix' => $id . ' fix',
+ 'fix_url' => admin_url( 'upload.php' ),
+ 'pending' => $pending,
+ );
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array( $row( 'policy_pages_linked', false ), $row( 'product_shipping_schema', null, true ) ),
+ ),
+ false
+ );
- $this->assertStringContainsString( 'Product checks', $html );
- $this->assertStringContainsString( 'Required by ChatGPT', $html );
- $this->assertStringContainsString( 'Harder to find on Google', $html );
- $this->assertStringContainsString( 'post=' . $product->get_id(), $html );
- $this->assertStringContainsString( 'Let search engines index your store', $html, 'Hidden from search engines is a Recommended setup step' );
- $this->assertStringContainsString( 'Last checked', $html );
+ $view = $this->view();
+ $json = wp_json_encode( $view );
+
+ $this->assertStringNotContainsString( 'product_shipping_schema', $json );
+ $this->assertStringNotContainsString( 'Coming soon', $json );
+ $this->assertMatchesRegularExpression( '#Sales readiness</a> <mark[^>]*>1 issue</mark>#', $this->render_page(), 'Status counts the same checks' );
+ $this->assertSame( '1 issue', array_column( $view['sections'], 'badge', 'id' )['buy']['text'] );
+ $row = $this->row( 'Link to your privacy and returns pages from your home page' );
+ $this->assertSame( ReadinessCopy::store_check( 'policy_pages_linked' )['fix'], $row['fix'], 'The fix line comes from the copy, not the report' );
+ $this->assertSame( 'Go to Media library', $row['link']['text'], 'A fix in the media library says where it goes' );
+ $this->assertSame( 'Check again', $view['run']['label'], 'Once a check has run, the button runs it again' );
}
/**
@@ -523,21 +1488,29 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
delete_option( AgentReadiness::REPORT_OPTION );
as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
- $html = $this->render_page();
- $this->assertDoesNotMatchRegularExpression( '/wc-agentic-commerce-run"[^>]*disabled/', $html );
- $this->assertStringNotContainsString( 'Product checks', $html, 'No product checks before the first scan' );
+ $view = $this->view();
+ $this->assertSame( 'Not checked yet', $view['last_checked'], 'No check has run' );
+ $this->assertSame( 'Run checks', $view['run']['label'], 'and the page offers to run one' );
+ $this->assertFalse( $view['run']['pending'] );
+ $this->assertSame( 'Run a check to see what AI assistants get when they visit your store and read your products.', $view['intro'], 'No results before the first scan' );
+ $this->assertSame( array(), $view['sections'] );
+ $this->assertNull( $view['fix_first'] );
wc_get_container()->get( ScheduledScan::class )->queue();
- $html = $this->render_page();
- $this->assertStringContainsString( 'Checking your store in the background.', $html );
- $this->assertMatchesRegularExpression( '/wc-agentic-commerce-run"[^>]*disabled/', $html );
+ $run = $this->view()['run'];
+ $this->assertSame( 'Checking your store.', $run['message'], 'Read out to screen readers; the page shows a spinner' );
+ $this->assertTrue( $run['pending'] );
+ $this->assertFalse( $run['stalled'], 'A queued check is not stalled, so the page keeps polling' );
as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
$this->age_finished_actions();
as_schedule_single_action( time() - ScheduledScan::STALLED_AFTER - 60, ScheduledScan::RUN_NOW_HOOK, array(), ScheduledScan::GROUP );
- $html = $this->render_page();
- $this->assertStringContainsString( 'The check has not started because scheduled actions', $html );
- $this->assertMatchesRegularExpression( '/wc-agentic-commerce-run"[^>]*disabled/', $html );
+ $run = $this->view()['run'];
+ $this->assertSame( 'The check can’t start because scheduled actions aren’t running on this site.', $run['message'] );
+ $this->assertSame( 'Go to Scheduled Actions', $run['link']['text'] );
+ $this->assertStringContainsString( 'tab=action-scheduler', $run['link']['href'] );
+ $this->assertTrue( $run['pending'] );
+ $this->assertTrue( $run['stalled'], 'and the page stops showing a spinner' );
as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
}
@@ -576,7 +1549,7 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
update_option( AgenticCommerceSettings::REFUND_RETURNS_PAGE_OPTION, $draft );
update_option( AgenticCommerceSettings::FAQ_PAGE_OPTION, $old_faq );
- $settings = $this->page()->get_settings_for_section( '' );
+ $settings = $this->page()->get_settings_for_section( AgenticCommerceSettings::SHOPPING_SECTION );
$refund = current( wp_list_filter( $settings, array( 'id' => AgenticCommerceSettings::REFUND_RETURNS_PAGE_OPTION ) ) );
$terms = current( wp_list_filter( $settings, array( 'id' => AgenticCommerceSettings::TERMS_PAGE_OPTION ) ) );
$this->assertSame( 'Returns draft (Draft)', $refund['options'][ (string) $draft ], 'The stored draft is listed with its status' );
@@ -615,7 +1588,7 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
);
update_option( 'woocommerce_checkout_page_id', $checkout );
$terms_field = array();
- foreach ( $this->page()->get_settings_for_section( '' ) as $field ) {
+ foreach ( $this->page()->get_settings_for_section( AgenticCommerceSettings::SHOPPING_SECTION ) as $field ) {
if ( AgenticCommerceSettings::TERMS_PAGE_OPTION === ( $field['id'] ?? '' ) ) {
$terms_field = $field;
}
@@ -623,7 +1596,7 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
$this->assertArrayNotHasKey( (string) $checkout, $terms_field['options'], 'The checkout page is not offered' );
WC_Admin_Settings::save_fields(
- $this->page()->get_settings_for_section( '' ),
+ $this->page()->get_settings_for_section( AgenticCommerceSettings::SHOPPING_SECTION ),
array( AgenticCommerceSettings::TERMS_PAGE_OPTION => (string) $checkout )
);
@@ -644,7 +1617,7 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
update_option( 'woocommerce_cart_page_id', $cart );
update_option( AgenticCommerceSettings::TERMS_PAGE_OPTION, $cart );
- $settings = $this->page()->get_settings_for_section( '' );
+ $settings = $this->page()->get_settings_for_section( AgenticCommerceSettings::SHOPPING_SECTION );
$terms = current( wp_list_filter( $settings, array( 'id' => AgenticCommerceSettings::TERMS_PAGE_OPTION ) ) );
$this->assertSame( 'Cart (Store page)', $terms['options'][ (string) $cart ] );
$html = $this->render_page();
@@ -669,7 +1642,7 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
update_option( AgenticCommerceSettings::TERMS_PAGE_OPTION, $published );
WC_Admin_Settings::save_fields(
- $this->page()->get_settings_for_section( '' ),
+ $this->page()->get_settings_for_section( AgenticCommerceSettings::SHOPPING_SECTION ),
array( AgenticCommerceSettings::TERMS_PAGE_OPTION => '' )
);
@@ -695,13 +1668,28 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
update_option( AgenticCommerceSettings::PRIVACY_PAGE_OPTION, $privacy );
wp_set_current_user( self::factory()->user->create( array( 'role' => 'shop_manager' ) ) );
- $settings = $this->page()->get_settings_for_section( '' );
+ $settings = $this->page()->get_settings_for_section( AgenticCommerceSettings::SHOPPING_SECTION );
WC_Admin_Settings::save_fields( $settings, array( AgenticCommerceSettings::PRIVACY_PAGE_OPTION => (string) $published ) );
+ $this->assertContains( AgenticCommerceSettings::TERMS_PAGE_OPTION, array_column( $settings, 'id' ), 'The section under test has its fields' );
$this->assertNotContains( AgenticCommerceSettings::PRIVACY_PAGE_OPTION, array_column( $settings, 'id' ) );
$this->assertSame( $privacy, (int) get_option( AgenticCommerceSettings::PRIVACY_PAGE_OPTION ) );
}
+ /**
+ * @testdox A shop manager with no privacy page sees the failing check and no link to a field they cannot use.
+ */
+ public function test_privacy_check_without_manage_privacy_options_has_no_settings_link(): void {
+ StoreConditionsTest::make_store_ready();
+ delete_option( AgenticCommerceSettings::PRIVACY_PAGE_OPTION );
+ wp_set_current_user( self::factory()->user->create( array( 'role' => 'shop_manager' ) ) );
+
+ $html = $this->render_page();
+
+ $this->assertStringContainsString( 'Someone who can manage privacy options needs to select a published privacy policy page under Settings > Privacy.', $html );
+ $this->assertStringNotContainsString( '#wp_page_for_privacy_policy', $html );
+ }
+
/**
* @testdox A discovery file WooCommerce didn't write shows the removal instruction, not a permalinks link.
*/
@@ -714,7 +1702,7 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
try {
$html = $this->render_page();
- $this->assertStringContainsString( 'didn't write', $html );
+ $this->assertStringContainsString( "didn't write", $html, 'Rows print through wp_kses_post, which keeps the apostrophe as is' );
$this->assertStringContainsString( esc_html( $path ), $html );
$this->assertStringNotContainsString( 'options-permalink.php', $html );
$this->assertStringNotContainsString( 'Change permalinks', $html );
@@ -769,26 +1757,242 @@ class AgenticCommerceSettingsTest extends WC_Unit_Test_Case {
$this->assertDoesNotMatchRegularExpression( '/<button[^>]*wc-agentic-commerce-ucp-switch[^>]*disabled=([\'"])disabled\\1/', $ready );
}
+ /**
+ * @testdox A connection URL blocked by a file names that file, and does not offer permalinks.
+ */
+ public function test_connection_url_file_step_names_the_file(): void {
+ $step = $this->setup_step_copy(
+ array(
+ 'id' => 'ucp_discovery',
+ 'label' => 'Fix your connection URL',
+ 'why' => 'AI assistants use your connection URL to find your products, and it doesn\'t load your store\'s details.',
+ 'fix' => 'Remove the /tmp/ucp file that WooCommerce didn\'t write. It is being served instead of your store profile.',
+ 'fix_url' => '',
+ )
+ );
+
+ $this->assertSame( 'Fix your connection URL', $step['title'] );
+ $this->assertStringContainsString( 'didn\'t write', $step['fix'] );
+ $this->assertSame( '', $step['url'] );
+ $this->assertSame( '', $step['link'] );
+ }
+
+ /**
+ * @testdox A connection URL with nothing serving it offers Change permalinks and says why.
+ */
+ public function test_connection_url_permalink_step_offers_permalinks(): void {
+ $step = $this->setup_step_copy(
+ array(
+ 'id' => 'ucp_discovery',
+ 'label' => 'Use a readable permalink structure',
+ 'why' => 'Any structure except Plain lets AI assistants reach your store.',
+ 'fix' => 'Choose any structure except Plain under Settings > Permalinks. Structures that start with index.php don\'t work either. Or make /tmp writable by the web server so WooCommerce can write the file.',
+ 'fix_url' => admin_url( 'options-permalink.php' ),
+ )
+ );
+
+ $this->assertSame( 'Use a readable permalink structure', $step['title'] );
+ $this->assertSame( 'Change permalinks', $step['link'] );
+ $this->assertStringContainsString( 'options-permalink.php', $step['url'] );
+ $this->assertStringContainsString( 'writable', $step['fix'] );
+ $this->assertStringContainsString( 'index.php', $step['fix'] );
+ }
+
+ /**
+ * What Sales readiness says about a failing setup step, as Fix first would show it.
+ *
+ * @param string $id Setup step id.
+ * @return array<string, string>
+ */
+ private function step_copy( string $id ): array {
+ $step = current( wp_list_filter( wc_get_container()->get( StoreConditions::class )->all(), array( 'id' => $id ) ) );
+ $this->assertIsArray( $step, 'No setup step with id ' . $id );
+ return $this->setup_step_copy( $step );
+ }
+
+ /**
+ * What Sales readiness says about one setup step.
+ *
+ * @param array<string, mixed> $step Store condition.
+ * @return array<string, string>
+ */
+ private function setup_step_copy( array $step ): array {
+ $failing = new \ReflectionMethod( ReadinessCheckPage::class, 'failing_copy' );
+ $failing->setAccessible( true );
+ return $failing->invoke( null, $step );
+ }
+
+ /**
+ * Make every setup step pass, recommended ones too, so a test counts only the scanned checks.
+ */
+ private function make_every_step_pass(): void {
+ StoreConditionsTest::make_store_ready( $this );
+ update_option( AgenticCommerceSettings::SHIPPING_POLICY_PAGE_OPTION, get_option( AgenticCommerceSettings::TERMS_PAGE_OPTION ) );
+ update_option( 'blog_public', '1' );
+ update_option( 'woocommerce_enable_guest_checkout', 'yes' );
+ $gateways = WC()->payment_gateways()->payment_gateways();
+ $email = WC()->mailer()->get_emails()['WC_Email_Customer_Processing_Order'];
+ foreach ( array( reset( $gateways ), $email ) as $item ) {
+ $this->restore[] = array( $item, $item->enabled );
+ $item->enabled = 'yes';
+ }
+ }
+
/**
* A fresh settings page.
*/
private function page(): AgenticCommerceSettingsPage {
update_option( 'woocommerce_feature_agent_readiness_enabled', 'yes' );
- update_option( 'woocommerce_feature_ucp_enabled', 'no' );
+ delete_option( 'woocommerce_feature_ucp_enabled' );
$this->sut->handle_init();
$pages = $this->sut->handle_woocommerce_get_settings_pages( array() );
return $pages[0];
}
/**
- * Render the default section.
+ * What Sales readiness and the Overview show, from ReadinessCheckPage::view().
+ *
+ * @return array<string, mixed>
+ */
+ private function view(): array {
+ return wc_get_container()->get( ReadinessCheckPage::class )->view();
+ }
+
+ /**
+ * The titles of every row in every section, open or folded.
+ *
+ * @param array<string, mixed> $view The view.
+ * @return array<int, string>
+ */
+ private function titles( array $view ): array {
+ $titles = array();
+ foreach ( $view['sections'] as $section ) {
+ $titles = array_merge( $titles, array_column( $section['rows'], 'title' ), array_column( $section['folded'], 'title' ) );
+ }
+ return $titles;
+ }
+
+ /**
+ * The row with this title, from any section.
+ *
+ * @param string $title Row title.
+ * @return array<string, mixed>
+ */
+ private function row( string $title ): array {
+ foreach ( $this->view()['sections'] as $section ) {
+ foreach ( array_merge( $section['rows'], $section['folded'] ) as $row ) {
+ if ( $title === $row['title'] ) {
+ return $row;
+ }
+ }
+ }
+ $this->fail( 'No row titled ' . $title );
+ }
+
+ /**
+ * Read apostrophes the same on every WordPress: esc_html() writes the entity, and wp_kses_post() on WordPress 7.2 and later turns it back into a plain apostrophe.
+ *
+ * @param string $html Rendered page.
+ */
+ private static function plain_apostrophes( string $html ): string {
+ return str_replace( ''', "'", $html );
+ }
+
+ /**
+ * Whether the last render_page() hid Save changes.
+ *
+ * @var bool
+ */
+ private $save_hidden = false;
+
+ /**
+ * Render a section of the tab: AI shopping, or '' for the landing page.
+ *
+ * @param string $section Section id.
+ * @param bool $ucp_on Whether UCP is on; page() turns it off.
*/
- private function render_page(): string {
+ private function render_page( string $section = AgenticCommerceSettings::SHOPPING_SECTION, bool $ucp_on = false ): string {
+ global $current_section;
// Localized data accumulates on a registered handle, so start each render clean.
wp_deregister_script( 'wc-agentic-commerce-settings' );
$page = $this->page();
- ob_start();
- $page->output();
- return (string) ob_get_clean();
+ if ( $ucp_on ) {
+ update_option( 'woocommerce_feature_ucp_enabled', 'yes' );
+ }
+ unset( $GLOBALS['hide_save_button'] );
+ $current_section = $section; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- The section WooCommerce sets from the URL; reset below.
+ try {
+ ob_start();
+ $page->output();
+ return self::plain_apostrophes( (string) ob_get_clean() );
+ } finally {
+ $current_section = ''; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Reset after the render.
+ $this->save_hidden = ! empty( $GLOBALS['hide_save_button'] );
+ unset( $GLOBALS['hide_save_button'] );
+ }
+ }
+
+ /**
+ * @testdox With "Discourage search engines" on, the noindex it prints is one issue: the setup step, not also the scanned check.
+ */
+ public function test_noindex_from_discourage_search_engines_shows_once(): void {
+ $this->make_every_step_pass();
+ update_option( 'blog_public', '0' );
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array(
+ array(
+ 'id' => 'no_noindex_directives',
+ 'ok' => false,
+ 'blocks' => 'listing',
+ 'group' => 'access',
+ 'name' => 'noindex name',
+ 'label' => 'noindex label',
+ 'why' => '',
+ 'fix' => '',
+ 'fix_url' => '',
+ ),
+ ),
+ )
+ );
+
+ $titles = array_column( $this->view()['fix_first']['items'], 'title' );
+ $this->assertSame( array( 'Let search engines index your store' ), $titles );
+
+ update_option( 'blog_public', '1' );
+ $this->assertCount( 1, $this->view()['fix_first']['items'], 'A noindex from elsewhere, such as an SEO plugin, still shows' );
+ $this->assertNotContains( 'Let search engines index your store', array_column( $this->view()['fix_first']['items'], 'title' ) );
+ }
+
+ /**
+ * The view with one failing scanned check, which has no affects line of its own.
+ *
+ * @param string $id Check id.
+ * @return array<string, mixed>
+ */
+ private function view_with_check( string $id ): array {
+ update_option(
+ AgentReadiness::REPORT_OPTION,
+ array(
+ 'generated_at' => gmdate( 'c' ),
+ 'store_checks' => array(
+ array(
+ 'id' => $id,
+ 'ok' => false,
+ 'blocks' => 'discovery',
+ 'group' => 'find',
+ 'name' => $id . ' name',
+ 'label' => $id . ' label',
+ 'why' => '',
+ 'fix' => '',
+ 'fix_url' => '',
+ 'conflict' => false,
+ ),
+ ),
+ )
+ );
+ return $this->view();
}
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ProductSalesTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ProductSalesTest.php
index 3f6c07b3421..f967fac11f5 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ProductSalesTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ProductSalesTest.php
@@ -139,6 +139,28 @@ class ProductSalesTest extends WC_Unit_Test_Case {
$this->assertTrue( $this->sut->last_days()['imported'], '20 real orders imported; three WCPay test-mode orders must not block the gate' );
}
+ /**
+ * @testdox Child orders are left out of the import count, so a multivendor sub-order does not ask for an import.
+ */
+ public function test_last_days_imported_ignores_child_orders(): void {
+ $mug = WC_Helper_Product::create_simple_product( true, array( 'regular_price' => 10 ) );
+ $parent = null;
+ for ( $i = 0; $i < ProductSales::MIN_ORDERS; $i++ ) {
+ $parent = $this->order( array( array( $mug, 1 ) ), OrderStatus::COMPLETED );
+ }
+ // Three unsynced child orders: 20/23 would fail the 90% gate if they counted.
+ for ( $i = 0; $i < 3; $i++ ) {
+ $child = wc_create_order();
+ $child->add_product( $mug, 1 );
+ $child->set_parent_id( $parent->get_id() );
+ $child->set_status( OrderStatus::COMPLETED );
+ $child->calculate_totals();
+ $child->save();
+ }
+
+ $this->assertTrue( $this->sut->last_days()['imported'], '20 parent orders imported; three child orders must not block the gate' );
+ }
+
/**
* @testdox With no orders the total is zero; with Analytics off there are no sales to read.
*/
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessCheckPageTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessCheckPageTest.php
new file mode 100644
index 00000000000..d7f753d3f48
--- /dev/null
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessCheckPageTest.php
@@ -0,0 +1,125 @@
+<?php
+declare( strict_types = 1 );
+
+namespace Automattic\WooCommerce\Tests\Internal\AgentReadiness;
+
+use Automattic\WooCommerce\Internal\AgentReadiness\AgentReadiness;
+use Automattic\WooCommerce\Internal\AgentReadiness\ReadinessCheckPage;
+use Automattic\WooCommerce\Internal\AgentReadiness\ScheduledScan;
+use Automattic\WooCommerce\Internal\AgentReadiness\StoreConditions;
+use Automattic\WooCommerce\Internal\Features\FeaturesController;
+use WC_Unit_Test_Case;
+
+/**
+ * Tests for the Sales readiness view builder.
+ */
+class ReadinessCheckPageTest extends WC_Unit_Test_Case {
+
+ /**
+ * The System Under Test.
+ *
+ * @var ReadinessCheckPage
+ */
+ private $sut;
+
+ /**
+ * Set up test fixtures.
+ */
+ public function setUp(): void {
+ parent::setUp();
+ StoreOutputChecksTest::block_requests();
+ update_option( 'woocommerce_feature_agent_readiness_enabled', 'yes' );
+ delete_option( AgentReadiness::REPORT_OPTION );
+ as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
+ $this->sut = wc_get_container()->get( ReadinessCheckPage::class );
+ }
+
+ /**
+ * Tear down test fixtures.
+ */
+ public function tearDown(): void {
+ as_unschedule_all_actions( ScheduledScan::RUN_NOW_HOOK );
+ delete_option( 'woocommerce_feature_agent_readiness_enabled' );
+ parent::tearDown();
+ }
+
+ /**
+ * A scan whose is_pending answers come from a list, one per call.
+ *
+ * @param array<int, bool> $answers Pending answers in call order.
+ * @return ScheduledScan
+ */
+ private function scan_with_pending_answers( array $answers ): ScheduledScan {
+ $scan = new class() extends ScheduledScan {
+ /**
+ * Pending answers left to return.
+ *
+ * @var array<int, bool>
+ */
+ public array $answers = array();
+
+ /**
+ * Next answer from the list, or false when the list is empty.
+ */
+ public function is_pending(): bool {
+ return (bool) array_shift( $this->answers );
+ }
+
+ /**
+ * Never stalled in these race tests.
+ */
+ public function is_stalled(): bool {
+ return false;
+ }
+ };
+ $scan->answers = $answers;
+ return $scan;
+ }
+
+ /**
+ * Re-init the page with a scan stub that returns the given pending answers.
+ *
+ * @param array<int, bool> $answers Pending answers in call order.
+ */
+ private function with_pending_answers( array $answers ): void {
+ $this->sut->init(
+ wc_get_container()->get( FeaturesController::class ),
+ wc_get_container()->get( StoreConditions::class ),
+ wc_get_container()->get( AgentReadiness::class ),
+ $this->scan_with_pending_answers( $answers )
+ );
+ }
+
+ /**
+ * @testdox A scan that finishes while the report is read still reports pending, so the client polls once more.
+ */
+ public function test_view_keeps_pending_when_scan_finishes_during_report_read(): void {
+ $this->with_pending_answers( array( true, false ) );
+
+ $view = $this->sut->view();
+
+ $this->assertTrue( $view['run']['pending'], 'Completion during the report read must not clear pending' );
+ }
+
+ /**
+ * @testdox A scan queued while the report is read still reports pending, so the client keeps polling.
+ */
+ public function test_view_reports_pending_when_scan_is_queued_during_report_read(): void {
+ $this->with_pending_answers( array( false, true ) );
+
+ $view = $this->sut->view();
+
+ $this->assertTrue( $view['run']['pending'], 'A queue during the report read must not hide the new scan' );
+ }
+
+ /**
+ * @testdox With no scan before or after the report read, the view is not pending.
+ */
+ public function test_view_is_not_pending_when_no_scan_runs(): void {
+ $this->with_pending_answers( array( false, false ) );
+
+ $view = $this->sut->view();
+
+ $this->assertFalse( $view['run']['pending'], 'No scan must leave pending false' );
+ }
+}
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessChecksTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessChecksTest.php
index 6a05ec6d2ac..41fd3d3b341 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessChecksTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessChecksTest.php
@@ -81,6 +81,13 @@ class ReadinessChecksTest extends WC_Unit_Test_Case {
$variation->set_attributes( array_fill_keys( array_keys( $attributes ), '' ) );
$variation->save();
$this->assertTrue( $table['variation_attributes_not_set']->fails( wc_get_product( $variable->get_id() ), $this->scan ), 'A variation set to "any"' );
+ $this->assertContains( $variation->get_id(), $table['variation_attributes_not_set']->failing_variations( wc_get_product( $variable->get_id() ), $this->scan ) );
+
+ $variable->set_attributes( array() );
+ $variable->save();
+ $whole = wc_get_product( $variable->get_id() );
+ $this->assertTrue( $table['variation_attributes_not_set']->fails( $whole, $this->scan ), 'No variation attribute on the parent' );
+ $this->assertNull( $table['variation_attributes_not_set']->failing_variations( $whole, $this->scan ), 'The blank child does not shrink a parent-level failure to one variation' );
}
/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessCopyTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessCopyTest.php
new file mode 100644
index 00000000000..d19b5ddfea0
--- /dev/null
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessCopyTest.php
@@ -0,0 +1,182 @@
+<?php
+declare( strict_types = 1 );
+
+namespace Automattic\WooCommerce\Tests\Internal\AgentReadiness;
+
+use Automattic\WooCommerce\Internal\AgentReadiness\ReadinessCheckPage;
+use Automattic\WooCommerce\Internal\AgentReadiness\ReadinessCopy;
+use Automattic\WooCommerce\Internal\AgentReadiness\StoreOutputChecks;
+use WC_Unit_Test_Case;
+
+/**
+ * Tests for ReadinessCopy.
+ */
+class ReadinessCopyTest extends WC_Unit_Test_Case {
+
+ /**
+ * Checks that wait for output WooCommerce doesn't build yet, so Sales readiness doesn't show them.
+ *
+ * @return array<int, string>
+ */
+ private static function pending(): array {
+ return ( new \ReflectionClassConstant( StoreOutputChecks::class, 'PENDING' ) )->getValue();
+ }
+
+
+ /**
+ * @testdox Every store check Sales readiness shows has copy, headed by what to do and saying what the scan found.
+ */
+ public function test_every_store_check_has_copy(): void {
+ $checks = new \ReflectionMethod( StoreOutputChecks::class, 'checks' );
+ $checks->setAccessible( true );
+ $ids = array_diff( array_column( $checks->invoke( wc_get_container()->get( StoreOutputChecks::class ) ), 'id' ), self::pending() );
+
+ $this->assertNotEmpty( $ids );
+ foreach ( $ids as $id ) {
+ $copy = ReadinessCopy::store_check( $id );
+ $this->assertNotNull( $copy, "{$id} has copy" );
+ $this->assertNotSame( $copy['title'], $copy['action'], "{$id} is worded as what to do while it fails" );
+ $this->assertNotSame( '', $copy['why'], "{$id} says why it matters once it passes" );
+ $this->assertNotSame( '', $copy['found'], "{$id} says why it matters while it fails" );
+ }
+ $this->assertNull( ReadinessCopy::store_check( 'not_a_check' ), 'A check without copy keeps the report\'s' );
+ }
+
+ /**
+ * @testdox The checkout check, pending until its output ships, has its copy and is Required.
+ */
+ public function test_checkout_check_has_copy_and_is_required(): void {
+ $copy = ReadinessCopy::store_check( 'ucp_checkout' );
+ $this->assertSame( 'Let AI assistants send shoppers to your checkout', $copy['action'] ?? null );
+ $this->assertNotSame( '', $copy['why'] );
+ $this->assertNotSame( '', $copy['found'] );
+ $this->assertSame( 'Turn off AI shopping (also called UCP or agentic commerce) in the other plugin, or deactivate it.', $copy['fix'] );
+
+ $required = new \ReflectionMethod( ReadinessCheckPage::class, 'is_required' );
+ $required->setAccessible( true );
+ $check = array(
+ 'id' => 'ucp_checkout',
+ 'blocks' => 'ucp',
+ 'group' => 'access',
+ 'level' => 'recommended',
+ 'conflict' => false,
+ );
+ $this->assertTrue( $required->invoke( null, $check ), 'Without checkout, AI assistants find products but can\'t sell them' );
+ $this->assertFalse( $required->invoke( null, array( 'id' => 'ucp_profile_version' ) + $check ), 'Other UCP checks stay recommended' );
+ }
+
+ /**
+ * @testdox Every store check Sales readiness shows has a fix line, so a failed row always names a next step.
+ */
+ public function test_every_store_check_has_a_fix_line(): void {
+ $checks = new \ReflectionMethod( StoreOutputChecks::class, 'checks' );
+ $checks->setAccessible( true );
+ foreach ( array_diff( array_column( $checks->invoke( wc_get_container()->get( StoreOutputChecks::class ) ), 'id' ), self::pending() ) as $id ) {
+ $this->assertNotSame( '', ReadinessCopy::store_check( $id )['fix'] ?? '', $id );
+ }
+ }
+
+ /**
+ * @testdox The image size line names Google, the only AI app with the rule, and no date: rules.json moves it to can't be listed when the rule starts.
+ */
+ public function test_image_size_line_names_google(): void {
+ $this->assertSame( 'Google asks for images of at least 500 x 500 pixels.', ReadinessCopy::product_check( 'image_too_small', 2 )['why'] );
+ }
+
+ /**
+ * @testdox The UCP version message names the version the store serves, when the scan found one.
+ */
+ public function test_ucp_version_message_names_served_version(): void {
+ $this->assertStringContainsString( '(UCP 2025-01-01)', ReadinessCopy::store_check( 'ucp_profile_version', '2025-01-01' )['found'] );
+ $this->assertStringContainsString( '(UCP).', ReadinessCopy::store_check( 'ucp_profile_version' )['found'] );
+ $this->assertSame( ReadinessCopy::store_check( 'ucp_profile' )['found'], ReadinessCopy::store_check( 'ucp_profile', '2025-01-01' )['found'], 'Other checks ignore the source' );
+ }
+
+ /**
+ * @testdox Every product check in the rules file has copy that says what to do and to how many products.
+ */
+ public function test_every_product_check_has_copy(): void {
+ // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- A local file in the plugin.
+ $rules = json_decode( (string) file_get_contents( WC_ABSPATH . 'src/Internal/AgentReadiness/rules.json' ), true );
+ $hidden = new \ReflectionClassConstant( ReadinessCheckPage::class, 'HIDDEN_PRODUCT_CHECKS' );
+ $ids = array_diff( array_keys( $rules['checks'] ), $hidden->getValue() );
+
+ $this->assertNotEmpty( $ids );
+ foreach ( $ids as $id ) {
+ $copy = ReadinessCopy::product_check( $id, 13 );
+ $this->assertNotNull( $copy, "{$id} has copy" );
+ $this->assertStringContainsString( '13 products', $copy['action'], "{$id} names how many products" );
+ $this->assertNotSame( '', $copy['why'], "{$id} says why it matters" );
+ $this->assertStringNotContainsString( '%s', ReadinessCopy::product_check( $id, 2, array( 'Blue hoodie', 'Red cap' ) )['action'], "{$id} fills in the product names" );
+ }
+ $this->assertSame( 'Add a brand to Blue hoodie', ReadinessCopy::product_check( 'missing_brand', 1, array( 'Blue hoodie' ) )['action'], 'One product is named' );
+ $this->assertSame( 'Add a brand to Blue hoodie and Red cap', ReadinessCopy::product_check( 'missing_brand', 2, array( 'Blue hoodie', 'Red cap' ) )['action'], 'Two products are named' );
+ $this->assertSame( 'Add a brand to Blue hoodie, Red cap, and Canvas tote', ReadinessCopy::product_check( 'missing_brand', 3, array( 'Blue hoodie', 'Red cap', 'Canvas tote' ) )['action'], 'Three products are named' );
+ $this->assertSame( 'Give Blue hoodie and Red cap their own barcode numbers', ReadinessCopy::product_check( 'duplicate_gtin', 2, array( 'Blue hoodie', 'Red cap' ) )['action'], 'Named titles agree with the number of products' );
+ $this->assertSame( 'Add a brand to 2 products', ReadinessCopy::product_check( 'missing_brand', 2, array( 'Blue hoodie' ) )['action'], 'Names that don\'t match the count give the count' );
+ $this->assertSame( 'Add a brand to 4 products', ReadinessCopy::product_check( 'missing_brand', 4, array( 'A', 'B', 'C', 'D' ) )['action'], 'More than three products are counted' );
+ $this->assertSame( 'Add a brand to a product', ReadinessCopy::product_check( 'missing_brand', 1 )['action'], 'One product without a name' );
+ $this->assertSame( 'Add a brand to 13 products', ReadinessCopy::product_check( 'missing_brand', 13 )['action'], 'Many products are counted' );
+ $this->assertStringStartsWith( 'ChatGPT only lists products that have a brand.', ReadinessCopy::product_check( 'missing_brand', 1 )['why'] );
+ $this->assertNull( ReadinessCopy::product_check( 'not_a_check', 1 ) );
+ }
+
+ /**
+ * @testdox The product why lines that name ChatGPT, Google or Copilot match the bundled channel rules.
+ */
+ public function test_product_why_lines_match_channel_rules(): void {
+ // What each why line says, and what that means per channel; update both when the rules change.
+ $said = array(
+ 'missing_regular_price' => array(
+ 'AI assistants only list products that have a price.',
+ array(
+ 'chatgpt' => 'not_listable',
+ 'google' => 'not_listable',
+ 'copilot' => 'not_listable',
+ ),
+ ),
+ 'missing_images' => array(
+ 'AI assistants only list products that have a main image.',
+ array(
+ 'chatgpt' => 'not_listable',
+ 'google' => 'not_listable',
+ 'copilot' => 'not_listable',
+ ),
+ ),
+ 'missing_product_text' => array(
+ 'ChatGPT only lists products that have a description. In Google and Copilot, a description makes products easier to find.',
+ array(
+ 'chatgpt' => 'not_listable',
+ 'google' => 'gaps',
+ 'copilot' => 'gaps',
+ ),
+ ),
+ 'missing_brand' => array(
+ 'ChatGPT only lists products that have a brand. In Google and Copilot, a brand makes products easier to find.',
+ array(
+ 'chatgpt' => 'not_listable',
+ 'google' => 'gaps',
+ 'copilot' => 'gaps',
+ ),
+ ),
+ 'invalid_gtin' => array(
+ 'Google doesn’t list products with a barcode number that isn’t valid. In ChatGPT and Copilot, a valid one makes products easier to find.',
+ array(
+ 'chatgpt' => 'gaps',
+ 'google' => 'not_listable',
+ 'copilot' => 'gaps',
+ ),
+ ),
+ );
+ $rules = json_decode( (string) file_get_contents( WC_ABSPATH . 'src/Internal/AgentReadiness/rules.json' ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- a local file.
+
+ foreach ( $said as $id => list( $why, $channels ) ) {
+ $this->assertSame( $why, ReadinessCopy::product_check( $id, 2 )['why'], "The why line of {$id} is the one checked here" );
+ $this->assertSame(
+ $channels,
+ array_map( static fn( array $channel ): string => $channel['effect'], $rules['checks'][ $id ]['channels'] ),
+ "The why line of {$id} matches what each channel does in rules.json"
+ );
+ }
+ }
+}
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessRestControllerTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessRestControllerTest.php
index d7878d51949..bb23433e3f5 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessRestControllerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/ReadinessRestControllerTest.php
@@ -67,6 +67,27 @@ class ReadinessRestControllerTest extends WC_REST_Unit_Test_Case {
$this->assertSame( $report['generated_at'], $response->get_data()['report']['generated_at'] );
}
+ /**
+ * @testdox GET view gives the Sales readiness page and the AI tools Overview what they show, as text and badges.
+ */
+ public function test_get_view(): void {
+ $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/agent-readiness/view' ) );
+ $this->assertSame( 200, $response->get_status() );
+ $data = $response->get_data();
+ $this->assertSame( 'Not checked yet', $data['last_checked'] );
+ $this->assertSame( 'Run checks', $data['run']['label'] );
+ $this->assertNull( $data['fix_first'] );
+ $this->assertSame( array(), $data['sections'] );
+ $this->assertSame( 'AI shopping', $data['overview']['shopping']['title'] );
+ $this->assertStringContainsString( 'path=/sales-readiness', $data['overview']['view_all']['href'] );
+
+ wc_get_container()->get( AgentReadiness::class )->refresh_report();
+ $data = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/agent-readiness/view' ) )->get_data();
+ $this->assertSame( 'Check again', $data['run']['label'] );
+ $this->assertSame( array( 'access', 'find', 'understand', 'products', 'buy' ), array_column( $data['sections'], 'id' ) );
+ $this->assertArrayHasKey( 'intent', $data['sections'][0]['badge'] );
+ }
+
/**
* @testdox GET reads setup checks now, so a setting changed after the scan shows its current state.
*/
@@ -118,6 +139,7 @@ class ReadinessRestControllerTest extends WC_REST_Unit_Test_Case {
$this->assertSame( 403, $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/agent-readiness' ) )->get_status() );
$this->assertSame( 403, $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v3/agent-readiness/scan' ) )->get_status() );
+ $this->assertSame( 403, $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/agent-readiness/view' ) )->get_status() );
$this->assertFalse( as_has_scheduled_action( ScheduledScan::RUN_NOW_HOOK ) );
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/RegressionGuardChecksTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/RegressionGuardChecksTest.php
index 16fafb79d0d..4c1740aa248 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/RegressionGuardChecksTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/RegressionGuardChecksTest.php
@@ -138,17 +138,16 @@ class RegressionGuardChecksTest extends WC_Unit_Test_Case {
}
/**
- * @testdox When the store can't reach itself, the guards that read pages are couldn't check.
+ * @testdox When the store can't reach itself, every guard is couldn't check, including reviews when no page needs loading.
*/
public function test_unreachable_store(): void {
add_filter( 'pre_http_request', static fn() => new \WP_Error( 'http_request_failed', 'Blocked in tests' ) );
$results = array_column( wc_get_container()->get( StoreOutputChecks::class )->all(), 'ok', 'id' );
- foreach ( array_diff( self::GUARDS, array( 'product_review_markup' ) ) as $id ) {
+ foreach ( self::GUARDS as $id ) {
$this->assertNull( $results[ $id ], $id );
}
- $this->assertTrue( $results['product_review_markup'], 'No product has reviews, so there is nothing to mark up and no page is loaded' );
}
/**
@@ -555,6 +554,29 @@ class RegressionGuardChecksTest extends WC_Unit_Test_Case {
$this->assertFalse( $this->results( $store )['product_review_markup'] );
}
+ /**
+ * @testdox A reviewed Search results only product is sampled, so missing rating markup fails.
+ */
+ public function test_review_markup_samples_search_only_products(): void {
+ update_option( 'woocommerce_enable_reviews', 'yes' );
+ update_option( 'woocommerce_enable_review_rating', 'yes' );
+ $search = WC_Helper_Product::create_simple_product();
+ $search->set_catalog_visibility( 'search' );
+ $search->save();
+ update_post_meta( $search->get_id(), '_wc_average_rating', '4.00' );
+
+ $store = $this->healthy_store();
+ $json = wp_json_encode(
+ array(
+ '@type' => 'Product',
+ 'name' => $search->get_name(),
+ )
+ );
+ $store[ self::path( $search->get_permalink() ) ] = array( 200, '<script type="application/ld+json">' . $json . '</script>' );
+
+ $this->assertFalse( $this->results( $store )['product_review_markup'] );
+ }
+
/**
* @testdox Hidden reviewed products are skipped before the sample limit, so an older visible one is still read.
*/
diff --git a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/StoreConditionsTest.php b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/StoreConditionsTest.php
index b89728a686f..93407c849a9 100644
--- a/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/StoreConditionsTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/AgentReadiness/StoreConditionsTest.php
@@ -140,14 +140,14 @@ class StoreConditionsTest extends WC_Unit_Test_Case {
}
/**
- * @testdox The UCP and policy page fixes link to the Agentic commerce settings tab, the policy ones to their field.
+ * @testdox The UCP and policy page fixes link to AI shopping's settings, the policy ones to their field.
*/
- public function test_fix_links_open_agentic_commerce(): void {
- $checks = array_column( $this->sut->all(), 'fix_url', 'id' );
- $tab = admin_url( 'admin.php?page=wc-settings&tab=agentic-commerce' );
+ public function test_fix_links_open_ai_shopping(): void {
+ $checks = array_column( $this->sut->all(), 'fix_url', 'id' );
+ $shopping = admin_url( 'admin.php?page=wc-settings&tab=agentic-commerce§ion=shopping' );
- $this->assertSame( $tab, $checks['ucp_on'] );
- $this->assertSame( $tab . '#' . AgenticCommerceSettings::TERMS_PAGE_OPTION, $checks['terms_page'] );
+ $this->assertSame( $shopping, $checks['ucp_on'] );
+ $this->assertSame( $shopping . '#' . AgenticCommerceSettings::TERMS_PAGE_OPTION, $checks['terms_page'] );
}
/**