Automattic\WooCommerce\StoreApi\Routes\V1

ProductBrandsById::get_route_response │ protected │ WC 1.0

Get a single item.

Метод класса: ProductBrandsById{}

Хуков нет.

Возвращает

\WP_REST_Response.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_route_response( $request );
$request(WP_REST_Request) (обязательный)
Request object.

Код ProductBrandsById::get_route_response() WC 11.2.1

protected function get_route_response( \WP_REST_Request $request ) {
	if ( isset( $request['identifier'] ) && is_numeric( $request['identifier'] ) ) {
		$object = get_term( (int) $request['identifier'], 'product_brand' );
	} else {
		$object = get_term_by( 'slug', $request['identifier'], 'product_brand' );
	}

	if ( ! $object ) {
		if ( isset( $request['identifier'] ) && is_numeric( $request['identifier'] ) ) {
			throw new RouteException( 'woocommerce_rest_brand_invalid_id', esc_html__( 'Invalid brand ID.', 'woocommerce' ), 404 );
		} else {
			throw new RouteException( 'woocommerce_rest_brand_invalid_slug', esc_html__( 'Invalid brand slug.', 'woocommerce' ), 404 );
		}
	}

	$data = $this->prepare_item_for_response( $object, $request );
	return rest_ensure_response( $data );
}