Magento 2 check product type is Virtual


Magento 2 check product type is Virtual– We sometimes need to check the product type is “Virtual product” or not. We can check get product type Virtual using product type id property. Here in this tutorial, we are going to explain how you can check whether a product is Virtual or not in Magento 2.


Magento 2 check product type is Virtual Example

Magento 2 check product type is Virtual

You can check if product type is Virtual or not simply as below-

Example:

$productId = 199;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($productId);
$productType = $product->getTypeID();

if($productType == "virtual")
{   
  echo "Product is Virtual Product";
} 

$productType will give you “virtual” which means product type is virtual.


Advertisements

Add Comment

đź“– Read More