3

I am creating a custom module to set a custom template for

vendor/magento/module-catalog/view/frontend/templates/product/view/options/type/default.phtml

but I am not able to override it. I have tried using XML like below

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="product.info.options">
        <block class="Magento\Catalog\Block\Product\View\Options\Type\DefaultType" as="default" template="Hemag_StockStatus::product/view/options/type/default.phtml"/>
    </referenceBlock>
</body>

Please let me know how to do this.

2
  • try this answer
    – Piyush
    Commented May 14, 2019 at 6:55
  • I have already tried that but not work Commented May 14, 2019 at 8:33

1 Answer 1

1

Try following way:

app/code/SR/MagentoCommunity/view/frontend/layout/catalog_product_view.xml

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <referenceBlock name="product.info.options.default" template="SR_MagentoCommunity::product/view/options/type/default.phtml"/>
        </referenceContainer>
    </body>
</page>

app/code/SR/MagentoCommunity/view/frontend/templates/product/view/options/type/default.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php $_option = $block->getOption() ?>
<div class="field">
    <label class="label"><span><?= $block->escapeHtml($_option->getTitle()) ?></span></label>
</div>
7
  • @Sohal Rana Still not working :( Commented May 14, 2019 at 10:22
  • Not sure why not working for you, this is working code with M2.3
    – Sohel Rana
    Commented May 14, 2019 at 10:54
  • can you please send me your working extension? I am using 2.2.6 version Commented May 14, 2019 at 11:27
  • I have added this two file and working fine. Did you check with fresh Magento installation or check any other module already overwrite this or not?
    – Sohel Rana
    Commented May 14, 2019 at 11:34
  • Yes, I have installed it in fresh magento 2.3 and its not working there. Commented May 14, 2019 at 12:49

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.