Magento: Display disabled products on frontend

Magento: Display disabled products on frontend

August 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Display disabled products on frontend

Displaying Disabled Products on Magento Frontend

As an experienced e-commerce developer, I often receive requests to display disabled products on the frontend of Magento sites while keeping them hidden from general catalog or search views. This is a common requirement for special promotions, private sales, or internal product management.

In this guide, we’ll walk through the steps required to achieve this functionality using Magento’s built-in features and custom code snippets.

Understanding Enabled Products in Magento

Firstly, it’s essential to understand how product enablement works in Magento:

  • By default, a Magento product is either enabled or disabled via its status field in the admin interface.
    • An Enabled product (Status = 1) appears in catalogs, search results, and can be added to cart.
    • A Disabled product (Status = 0) is hidden from these views but remains accessible via direct URL.

The Current Issue: View.Phtml Not Triggering

You mentioned that the catalog/product/view.phtml template isn’t triggering for disabled products, resulting in a 404 page. This happens because Magento’s core logic prevents the product view page from loading if the product is disabled.

To override this behavior and display a custom message for disabled products accessed via direct URL, we need to create a custom module and modify the catalog_product_view event listener.

Creating a Custom Module

  1. Create a new module directory under app/code/YourVendorName/DisableProductView/ with the following structure:
- app
  - code
    - YourVendorName
      - DisableProductView
        - etc
          - module.xml
        - etc
          - di.xml
        - view
          - frontend
            - templates
              - catalog
                - product
                  - view.phtml (custom)
  1. In etc/module.xml, define your module:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="YourVendorName_DisableProductView"/>
</config>

Overriding the Product View Event

  1. In etc/di.xml, override the core catalog_product_view event listener:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc.acl.xsd">
    <type name="Magento\Catalog\Controller\Product\View">
        <plugin name="disable-products-view-plugin"
                type="YourVendorName\DisableProductView\Model\Plugin\ProductView"
                sortOrder="10"/>
    </type>
</config>
  1. Create the plugin class app/code/YourVendorName/DisableProductView/Model/Plugin/ProductView.php:
<?php

namespace YourVendorName\DisableProductView\Model\Plugin;

use Magento\Framework\App\RequestInterface;
use Magento\Catalog\Controller\Product\View as ProductViewController;

class ProductView
{
    protected $request;

    public function __construct(RequestInterface $request)
    {
        $this->request = $request;
    }

    public function afterExecute(ProductViewController $subject, string $result)
    {
        if ($this->request->getParam('id')) {
            $productId = (int) $this->request->getParam('id');
            $product = $subject->getProduct();

            if (!$product->getEnabled()) {
                return 'This product is currently disabled.';
            }
        }

        return $result;
    }
}

Creating the Custom View Template

  1. In view/frontend/templates/catalog/product/view.phtml, create your custom template:
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// Place your custom HTML and PHP code here to display a message when the product is disabled

?>

Enabling Your Custom Module

  1. Enable your module via the command bin/magento module:enable YourVendorName_DisableProductView in the terminal.

  2. Clear the cache with bin/magento cache:clean.

Now, when you access a disabled product’s direct URL (e.g., https://yourstore.com/product/disabled-product-sku.html), Magento will display your custom message instead of returning a 404 error.

This approach respects Magento’s core logic while providing the flexibility to handle disabled products as required. It ensures that sensitive or special products remain accessible via direct links without appearing in public catalogs or search results.

I recommend testing this solution thoroughly across different product types and scenarios to ensure it meets your specific business needs.

For further guidance on custom module development and Magento template overrides, refer to the official Magento Developer Documentation and the Laravel Company’s comprehensive blog posts on Magento best practices at https://laravelcompany.com/blog/.

Checkout Catalog Extensions Themes

Our network