WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Utilities

CartController::get_variation_id_from_variation_data() protected WC 1.0

Try to match request data to a variation ID and return the ID.

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

No Hooks.

Return

Int. Matching variation ID.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_variation_id_from_variation_data( $request, $product );
$request(array) (required)
Add to cart request params.
$product(\WC_Product) (required)
Product being added to the cart.

Code of CartController::get_variation_id_from_variation_data() WC 5.8.0

protected function get_variation_id_from_variation_data( $request, $product ) {
	$data_store       = \WC_Data_Store::load( 'product' );
	$match_attributes = $request['variation'];
	$variation_id     = $data_store->find_matching_product_variation( $product, $match_attributes );

	if ( empty( $variation_id ) ) {
		throw new RouteException(
			'woocommerce_rest_variation_id_from_variation_data',
			__( 'No matching variation found.', 'woocommerce' ),
			400
		);
	}

	return $variation_id;
}