WC_API_Resource::__construct()publicWC 2.1

Setup class

Method of the class: WC_API_Resource{}

No Hooks.

Return

null. Nothing.

Usage

$WC_API_Resource = new WC_API_Resource();
$WC_API_Resource->__construct( $server );
$server(WC_API_Server) (required)
-

Changelog

Since 2.1 Introduced.

WC_API_Resource::__construct() code WC 7.7.0

public function __construct( WC_API_Server $server ) {

	$this->server = $server;

	// automatically register routes for sub-classes
	add_filter( 'woocommerce_api_endpoints', array( $this, 'register_routes' ) );

	// remove fields from responses when requests specify certain fields
	// note these are hooked at a later priority so data added via filters (e.g. customer data to the order response)
	// still has the fields filtered properly
	foreach ( array( 'order', 'coupon', 'customer', 'product', 'report' ) as $resource ) {

		add_filter( "woocommerce_api_{$resource}_response", array( $this, 'maybe_add_meta' ), 15, 2 );
		add_filter( "woocommerce_api_{$resource}_response", array( $this, 'filter_response_fields' ), 20, 3 );
	}
}