Automattic\WooCommerce\StoreApi\Routes\V1

ProductBrandsById::get_route_responseprotectedWC 1.0

Get a single item.

Method of the class: ProductBrandsById{}

No Hooks.

Returns

\WP_REST_Response.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_route_response( $request );
$request(WP_REST_Request) (required)
Request object.

ProductBrandsById::get_route_response() code WC 9.8.5

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 );
}