WC_API_Resource::__construct()
Setup class
Method of the class: WC_API_Resource{}
No Hooks.
Return
null
. Nothing (null).
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() WC API Resource:: construct code WC 8.6.1
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' ) ); // maybe add meta to top-level resource responses foreach ( array( 'order', 'coupon', 'customer', 'product', 'report' ) as $resource ) { add_filter( "woocommerce_api_{$resource}_response", array( $this, 'maybe_add_meta' ), 15, 2 ); } $response_names = array( 'order', 'coupon', 'customer', 'product', 'report', 'customer_orders', 'customer_downloads', 'order_note', 'order_refund', 'product_reviews', 'product_category', 'tax', 'tax_class', ); foreach ( $response_names as $name ) { /** * 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 */ add_filter( "woocommerce_api_{$name}_response", array( $this, 'filter_response_fields' ), 20, 3 ); } }