WC_REST_CRUD_Controller::get_item()
Get a single item.
Метод класса: WC_REST_CRUD_Controller{}
Хуков нет.
Возвращает
WP_Error|WP_REST_Response
.
Использование
$WC_REST_CRUD_Controller = new WC_REST_CRUD_Controller(); $WC_REST_CRUD_Controller->get_item( $request );
- $request(WP_REST_Request) (обязательный)
- Full details about the request.
Код WC_REST_CRUD_Controller::get_item() WC REST CRUD Controller::get item WC 9.3.3
public function get_item( $request ) { $object = $this->get_object( (int) $request['id'] ); if ( ! $object || 0 === $object->get_id() ) { return new WP_Error( "woocommerce_rest_{$this->post_type}_invalid_id", __( 'Invalid ID.', 'woocommerce' ), array( 'status' => 404 ) ); } $data = $this->prepare_object_for_response( $object, $request ); $response = rest_ensure_response( $data ); if ( $this->public ) { $response->link_header( 'alternate', $this->get_permalink( $object ), array( 'type' => 'text/html' ) ); } return $response; }