Magento 2 Check If Quote Has A Virtual Product Added

Hi Guys,
In this blog, we will check if there is any virtual product added in the cart or not in Magento 2. we will use the Quote object of the class Magento\Quote\Api\Data\CartInterface.

Lets have a look at below code snippet:

public function isCartVirtual(\Magento\Quote\Api\Data\CartInterface $quote)
    if ($quote->getIsVirtual()) {
        return true;
    return false;

The above method will return true or false based on above condition checks.

Leave a Reply