Request Quote

How to check if the cart is virtual

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.

Please let me know if you find any issue.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close