I'm new at Magento. I want to list real estate like home or office space in the site. Im doing this as a virtual product. Quantity and in stock options are no relevant to these products. Hence would like to disable those options in the site. I could not find solution anywhere to fix the same.

Do we have any solution to fix this issue? Kindly help.

4 Answers 4


Just set Manage Stock to Off.

  • Where is this??
    – Black
    Jun 4, 2020 at 10:03

You can add a if condition to check that the product is virtual or not. Like below code

 if($product->getTypeId() != "virtual"){
    //show product stock options
//show stock options

Hope this will make a way for you to get your job done! Happy learning

  • Thanks for the reply Asish. In which file shall I add this particular piece of code?
    – sravani G
    Apr 25, 2016 at 14:11
  • @sravaniG that depends on where you want to this?? On list page or in product details page
    – Asish Hira
    Apr 25, 2016 at 14:14
  • On product details page
    – sravani G
    Apr 25, 2016 at 14:17
  • on app/design/frontend/your_theme/template/catalog/product/view.phtml find <?php if ($_product->isSaleable() && $this->hasOptions()):?>` find this and add extra condition on this if
    – Asish Hira
    Apr 25, 2016 at 14:20

In order to disable the quantity and in-stock options for the virtual product, navigate catalog_product_view.xml file, and extends the block/container and then in your template check if the product is of type virtual then don't show the product stock , else show the product quantity for other products.


<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceContainer name="product.info.main">
            <block class="Your\Module\Block\HideStock" name="hide_stock" template="Your_Module::hideStock.phtml"></block>

Similarly create a block for the layout. i.e. Your\Module\Block\HideStock and add the corresponding functions

In your phtml i.e. Your_Module::hideStock.phtml

 if($product->getTypeId() != "virtual"){
    show product stock options
hide stock options

//your code here
<div class="field qty">
          <!--  <label class="label" for="qty"><span><?/*= /* @escapeNotVerified */ //__('Qty') */?></span></label>-->
            <div class="control">
                <input type="hidden"
                       value="<?= /* @escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>"
                       title="<?= /* @escapeNotVerified */ __('Qty') ?>"
                       class="input-text qty"
                       data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"

Just comment above code in template\product\view\addtocart.phtml and make input type "hidden".

Note : Copy above template(addcart.phtml) into your theme then do changes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.