WC_REST_Orders_V1_Controller::prepare_links
Prepare links for the request.
Method of the class: WC_REST_Orders_V1_Controller{}
No Hooks.
Returns
Array. Links for the given order.
Usage
// protected - for code of main (parent) or child class $result = $this->prepare_links( $order, $request );
- $order(WC_Order) (required)
- Order object.
- $request(WP_REST_Request) (required)
- Request object.
WC_REST_Orders_V1_Controller::prepare_links() WC REST Orders V1 Controller::prepare links code WC 10.3.6
protected function prepare_links( $order, $request ) {
$links = array(
'self' => array(
'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $order->get_id() ) ),
),
'collection' => array(
'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
),
);
if ( 0 !== (int) $order->get_user_id() ) {
$links['customer'] = array(
'href' => rest_url( sprintf( '/%s/customers/%d', $this->namespace, $order->get_user_id() ) ),
);
}
if ( 0 !== (int) $order->get_parent_id() ) {
$links['up'] = array(
'href' => rest_url( sprintf( '/%s/orders/%d', $this->namespace, $order->get_parent_id() ) ),
);
}
return $links;
}