Use this way to extend data to rest api
use Automattic\WooCommerce\StoreApi\Schemas\V1\ProductSchema;
add_action('rest_api_init', function() {
woocommerce_store_api_register_endpoint_data(
array(
'endpoint' => ProductSchema::IDENTIFIER,
'namespace' => 'plugin_namespace',
'data_callback' => 'my_data_callback',
'schema_callback' => 'my_schema_callback',
'schema_type' => ARRAY_A,
)
);
});
function my_data_callback() {
return [
'custom-key' => 'custom-value';
]
}
function my_schema_callback() {
return [
'custom-key' => [
'description' => __( 'My custom data', 'plugin-namespace' ),
'type' => 'string',
'readonly' => true,
]
];
}