1. Home
  2. Docs
  3. Search Filter Pro
  4. Advanced
  5. Exposing your data in the Product API.

Exposing your data in the Product API.

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,
		]
	];
}
Was this article helpful to you? Yes No

How can we help?