Back to Top

How to check if the cart is virtual

Updated 16 May 2019

In this blog we will see how to check if the cart is virtual or not in magento 2.

After adding the products to the cart, when ever we need to check if the products added in the cart is virtual without looping over quote item or doing some other stuffs.

we will use the Quote object containing the quoted data and use isVirtual method of the quote class.

Here i will show you how.

public function isCartVirtual(\Magento\Quote\Api\Data\CartInterface $quote)
{
    if ($quote->getIsVirtual()) {
        $flag = true;
    }
}
Now, the return type we are going to get is bool. And perfom our operation using the stuff.

Thank you for checking this blog.

Searching for an experienced
Magento Company ?
Find out More

Please let me know if you find any issue.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home