I've just turned on the option "Display Products Availability in Stock on Storefront" which is working as it should - display either "in stock" or "out of stock" on the front end, but I want to change the default behavior so that the message only shows when a product is out of stock...

So "In stock" = no message and "Out of Stock" = Shows out of stock message

Can this be done?


2 Answers 2


You have to edit this file in your template, if the file is not exist please copy it from the original theme to your theme.


 * 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( $_product->getData("not_saleable")) return; ?>
<?php if ($block->displayProductStockStatus()): ?>
    <?php if (!$_product->isAvailable()): ?>
        <div class="stock unavailable" title="<?= /* @escapeNotVerified */ __('Availability') ?>">
            <span><?= /* @escapeNotVerified */ __('Out of stock') ?></span>
    <?php endif; ?>
<?php endif; ?>

You just need to follow the below code.

Need to do changes in default.phtml file (Magento_Catalog/templates/product/view/type/default.phtml)

<?php if ($_product->isAvailable()): ?>
 <div class="stock available">
            <?php / @escapeNotVerified / echo __('In stock') ?>
<?php else: ?>
<div class="stock unavailable">
             <?php / @escapeNotVerified / echo __('Out of stock') ?

I hope it will help you.

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.