Magento 2 – Override Template File Using Custom Module

magento2overrides

I need to override below template file using custom module

Magento_ConfigurableProduct::product/view/type/options/configurable.phtml

Best Answer

=> create file under :

app/code/Vendor/Modulename/view/frontend/layout/catalog_product_view_type_configurable.xml

<?xml version="1.0"?>

<page 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.configurable">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Modulename::product/view/type/options/configurable.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

=> Set your templae file at below location :

app/code/Vendor/Modulename/view/frontend/templates/product/view/type/options/configurable.phtml

Clear cache.