plugins/woocommerce/src/Internal/RestApi/Routes/README.md
This directory contains route controllers and schemas for WooCommerce REST API endpoints, organized by major version.
Each major version of the REST API has its own directory:
V4/ - REST API v4 controllers and schemasV5/ - REST API v5 controllers and schemas (future)V6/ - REST API v6 controllers and schemas (future)Previous versions of the REST API (v1, v2, v3) can be found in the legacy includes directory:
plugins/woocommerce/includes/rest-api/
These legacy controllers are maintained for backwards compatibility and should not be modified for new features.
Route controllers and schemas for the WooCommerce REST API V4 endpoints are placed in the V4/ directory.
Each route should have its own directory containing both controller and schema files:
V4/
├── AbstractController.php
├── AbstractSchema.php
├── Orders/
│ ├── Controller.php
│ └── OrderSchema.php
├── OrderNotes/
│ ├── Controller.php
│ └── OrderNoteSchema.php
└── Products/
├── Controller.php
└── ProductSchema.php
The main controller class should be named Controller.php with the correct namespace for the route.
For example:
V4/Orders/Controller.php with namespace Automattic\WooCommerce\Internal\RestApi\Routes\V4\OrdersV4/OrderNotes/Controller.php with namespace Automattic\WooCommerce\Internal\RestApi\Routes\V4\OrderNotesThe schema class should be named {SingularResourceType}Schema.php with the correct namespace for the route.
For example:
V4/Orders/OrderSchema.php with namespace Automattic\WooCommerce\Internal\RestApi\Routes\V4\OrdersV4/OrderNotes/OrderNoteSchema.php with namespace Automattic\WooCommerce\Internal\RestApi\Routes\V4\OrderNotesControllers should extend V4/AbstractController.php, which extends WP_REST_Controller.
Schemas should extend V4/AbstractSchema.php and implement the following:
'order', 'order_note')VIEW_EDIT_EMBED_CONTEXT, VIEW_EDIT_CONTEXT)See the WordPress documentation for more information on supported schema properties.
https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/