In magento 2 how to override stock availability in product detail page in custom module

enter image description here

app/code/Vendor/Module/view/frontend/layout/catalog_product_view.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>
    <referenceContainer name="product.info.type">
        <block class="Magento\Catalog\Block\Product\View\Type\Simple" name="product.info.simple" as="product_type_data" template="Vendor_Module::product/view/type/default.phtml"/>
    </referenceContainer>
</body>
</page>

app/code/Vendor/Module/view/frontend/templates/product/view/type/default.phtml

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

// @codingStandardsIgnoreFile

?>
<?php /* @var $block \Magento\Catalog\Block\Product\View\AbstractView */?>
<?php $_product = $block->getProduct() ?>

<?php if ($block->displayProductStockStatus()): ?>
    <?php if ($_product->isAvailable()): ?>
        <div class="stock available" title="<?= /* @escapeNotVerified */ __('Availability') ?>">
            <span><?= /* @escapeNotVerified */ __('In stock with static text') ?></span>
        </div>
    <?php else: ?>
        <div class="stock unavailable" title="<?= /* @escapeNotVerified */ __('Availability') ?>">
            <span><?= /* @escapeNotVerified */ __('Out of stock') ?></span>
        </div>
    <?php endif; ?>
<?php endif; ?>
有帮助吗?

解决方案

Your path seems wrong. You forget to add the "frontend" folder name.

Vendor/Module/view/frontend/templates/product/view/type/default.phtml

Please change it and try again.

Follow this

github.com/emizentech/

许可以下: CC-BY-SA归因
scroll top