WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Utilities

CartController::get_product_for_cart() protected WC 1.0

Get a product object to be added to the cart.

{} It's a method of the class: CartController{}

No Hooks.

Return

\WC_Product|Error. Returns a product object if purchasable.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_product_for_cart( $request );
$request(array) (required)
Add to cart request params.

Code of CartController::get_product_for_cart() WC 5.8.0

protected function get_product_for_cart( $request ) {
	$product = wc_get_product( $request['id'] );

	if ( ! $product || 'trash' === $product->get_status() ) {
		throw new RouteException(
			'woocommerce_rest_cart_invalid_product',
			__( 'This product cannot be added to the cart.', 'woocommerce' ),
			400
		);
	}

	return $product;
}