getRates(); // Get ordered entity. $item = $order_item->getPurchasedEntity(); if (!($item instanceof ProductVariationInterface)) { // Item is not a product variation. Abort. return; } // Get ordered product. $product = $item->getProduct(); if (!($product instanceof ProductInterface)) { // No product. return; } // Get product type. $product_type = $product->bundle(); // Take a rate depending on product type. switch ($product_type) { case 'book': $rate_id = 'reduced'; break; default: // The rate for this product type can be resolved using the default tax // rate resolver. return; } // Find a rate with this ID. foreach ($rates as $rate) { if ($rate->getId() == $rate_id) { return $rate; } } // If no rate has been found, resolving the right rate will be done by the // next rate resolver in line. return NULL; } }