WC_REST_Report_Sales_Controller::get_item_schema │ public │ WC 1.0

Get the Report's schema, conforming to JSON Schema.

Extends the v2 schema with the per-period refunds field and replaces the previously incorrect totals typing (array of array) with the actual object-of-objects shape so the schema reflects reality.

Method of the class: WC_REST_Report_Sales_Controller{}

No Hooks.

Returns

array.

Usage

$WC_REST_Report_Sales_Controller = new WC_REST_Report_Sales_Controller();
$WC_REST_Report_Sales_Controller->get_item_schema();

WC_REST_Report_Sales_Controller::get_item_schema() code WC 11.1.2

public function get_item_schema() {
	$schema = parent::get_item_schema();

	$schema['properties']['totals'] = array(
		'description'          => __( 'Totals.', 'woocommerce' ),
		'type'                 => 'object',
		'context'              => array( 'view' ),
		'readonly'             => true,
		'additionalProperties' => array(
			'type'       => 'object',
			'properties' => array(
				'sales'     => array(
					'description' => __( 'Gross sales in the period.', 'woocommerce' ),
					'type'        => 'string',
					'context'     => array( 'view' ),
					'readonly'    => true,
				),
				'orders'    => array(
					'description' => __( 'Number of orders in the period.', 'woocommerce' ),
					'type'        => 'integer',
					'context'     => array( 'view' ),
					'readonly'    => true,
				),
				'items'     => array(
					'description' => __( 'Number of items sold in the period.', 'woocommerce' ),
					'type'        => 'integer',
					'context'     => array( 'view' ),
					'readonly'    => true,
				),
				'tax'       => array(
					'description' => __( 'Tax charged in the period.', 'woocommerce' ),
					'type'        => 'string',
					'context'     => array( 'view' ),
					'readonly'    => true,
				),
				'shipping'  => array(
					'description' => __( 'Shipping charged in the period.', 'woocommerce' ),
					'type'        => 'string',
					'context'     => array( 'view' ),
					'readonly'    => true,
				),
				'discount'  => array(
					'description' => __( 'Discounts applied in the period.', 'woocommerce' ),
					'type'        => 'string',
					'context'     => array( 'view' ),
					'readonly'    => true,
				),
				'refunds'   => array(
					'description' => __( 'Refunds issued in the period.', 'woocommerce' ),
					'type'        => 'string',
					'context'     => array( 'view' ),
					'readonly'    => true,
				),
				'customers' => array(
					'description' => __( 'New customers in the period.', 'woocommerce' ),
					'type'        => 'integer',
					'context'     => array( 'view' ),
					'readonly'    => true,
				),
			),
		),
	);

	return $this->add_additional_fields_schema( $schema );
}