WC_REST_Orders_V2_Controller::prepare_links()protectedWC 1.0

Prepare links for the request.

Method of the class: WC_REST_Orders_V2_Controller{}

No Hooks.

Return

Array. Links for the given post.

Usage

// protected - for code of main (parent) or child class
$result = $this->prepare_links( $object, $request );
$object(WC_Data) (required)
Object data.
$request(WP_REST_Request) (required)
Request object.

WC_REST_Orders_V2_Controller::prepare_links() code WC 8.6.1

protected function prepare_links( $object, $request ) {
	$links = array(
		'self'       => array(
			'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ),
		),
		'collection' => array(
			'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
		),
	);

	if ( 0 !== (int) $object->get_customer_id() ) {
		$links['customer'] = array(
			'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $object->get_customer_id() ) ),
		);
	}

	if ( 0 !== (int) $object->get_parent_id() ) {
		$links['up'] = array(
			'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $object->get_parent_id() ) ),
		);
	}

	return $links;
}