public function get_item($request)
{
$id = (int) $request['id'];
$post = get_post($id);
if (!empty($post->post_type) && 'product_variation' === $post->post_type && 'product' === $this->post_type) {
return new WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('To manipulate product variations you should use the /products/<product_id>/variations/<id> endpoint.', 'woocommerce'), array('status' => 404));
} elseif (empty($id) || empty($post->ID) || $post->post_type !== $this->post_type) {
return new WP_Error("woocommerce_rest_invalid_{$this->post_type}_id", __('Invalid ID.', 'woocommerce'), array('status' => 404));
}
$data = $this->prepare_item_for_response($post, $request);
$response = rest_ensure_response($data);
if ($this->public) {
$response->link_header('alternate', get_permalink($id), array('type' => 'text/html'));
}
return $response;
}