WC_REST_Posts_Controller::get_item()
Get a single item.
Method of the class: WC_REST_Posts_Controller{}
No Hooks.
Return
WP_Error|WP_REST_Response
.
Usage
$WC_REST_Posts_Controller = new WC_REST_Posts_Controller(); $WC_REST_Posts_Controller->get_item( $request );
- $request(WP_REST_Request) (required)
- Full details about the request.
WC_REST_Posts_Controller::get_item() WC REST Posts Controller::get item code WC 9.6.0
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; }