Show attribute if product is Out-Of-Stock Magento

Show attribute if product is Out-Of-Stock Magento

October 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Show attribute if product is Out-Of-Stock Magento

Customizing Product Attributes Based on Stock Level in Magento

As a senior developer with extensive experience in e-commerce platforms like Magento, I understand your need to conditionally display product attributes based on stock status. In this post, we’ll explore how to make an attribute visible only when a product is in stock.

Understanding the Stock Status Behaviour

Magento treats “Out of Stock” products differently than those with available inventory. By default, it hides certain attributes and options from view if a product has zero quantity.

This behavior is built into Magento’s core functionality for better user experience - why offer size choices if there are no more items left? However, in some cases, you might want to show all product details regardless of stock status.

Enabling Stock Display for Out-Of-Stock Products

To override this default behavior and always display an attribute like ‘size’, we need to make changes at the configuration level. Here’s a step-by-step guide:

  1. Navigate to your Magento admin panel.

  2. Go to Stores > Configuration > Catalog.

  3. In the left sidebar, select “Inventory”.

  4. Under the “Stock Options” section, find the “Display Out of Stock Products” field.

  5. Change its value from “No” to “Yes”.

  6. Click on the “Save Config” button at the top right corner.

Overriding the Core Template

While changing the configuration will enable out-of-stock products in the catalog, it won’t necessarily show hidden attributes like ‘size’. To achieve this, we need to override a core template file:

  1. First, locate your theme’s template/catalog/product/view/type/default.phtml file.

  2. If you’re using a third-party theme or an extension that modifies this file, copy it over to your custom theme folder (usually located at app/design/frontend/{Your_Theme_Path}).

  3. Open the copied file in a text editor and find the following line of code:

<?php if ($_product->isSaleable() && $this->hasOptions()): ?>
    <div class="box-collateral box-configurable">
        <?php echo $this->getChildHtml('super_config') ?>
        <?php echo $this->getChildHtml('swatch_renderer') ?>
        <?php echo $this->getChildHtml('bundle_options_form') ?>
    </div>
<?php endif; ?>
  1. Add a new condition to check if the product has available inventory, and display your custom attribute:
<div class="box-collateral box-custom-attributes">
    <?php if ($_product->isSaleable() && $this->hasOptions()): ?>
        <div class="field configurable-size">
            <label for="attribute_size"><?php echo __('Size') ?></label>
            <select name="size" id="attribute_size">
                <?php foreach ($this->getProduct()->getAttributeText('size') as $_optionValue): ?>
                    <option value="<?php echo $_optionValue ?>"><?php echo $_optionValue ?></option>
                <?php endforeach; ?>
            </select>
        </div>
    <?php endif; ?>
</div>

Conclusion

In this post, we’ve discussed the default stock status behavior in Magento and how to override it. By enabling out-of-stock product display through configuration and modifying the core template file, you can ensure that all product attributes are visible regardless of available inventory.

Remember, these changes should be tested thoroughly in a development environment before deployment. For more advanced customizations or any other Magento-related queries, feel free to explore our Magento Development Services at Laravel Company.

We provide expert Magento consulting and development services tailored to meet your business needs. Contact us today to discuss how we can optimize your e-commerce platform for better performance and user experience.

Catalog Themes Admin Configuration

Our network