I am using Magento 2.4.2 version. I like to know if there is any possibility to override the stock status on the product detail page without overriding the template. Please help and Thanks in advance. enter image description here

  • Hello. What are you trying to achieve?
    – Joao71
    Commented Sep 15, 2021 at 9:17
  • Do you only want to change stock status from Instock to Outofstock? OR if you want to change the verbiage then you have to make change in template file OR another work around is you can use translation but that will not be conditional. Let me know if you need any other help. Commented Sep 15, 2021 at 14:36

1 Answer 1


You can achieve this by doing the following:

On your etc\di.xml

<type name="Magento\Catalog\Model\Product">
        <plugin name="hidecartbutton" type="vendor\module\Plugin\HideAddButtonOutOfStock" sortOrder="1"/>

Create a Plugins folder an add the file HideAddButtonOutOfStock.php


namespace vendor\module\Plugin;
use Magento\Catalog\Model\Product;
use Magento\Checkout\Model\Session;

class HideAddButtonOutOfStock

    protected $_session;
    protected $productRepository;
    public function __construct(
        Session                                     $session,
        \Magento\Catalog\Model\ProductRepository    $productRepository     
        $this->_session           = $session;
        $this->productRepository  = $productRepository;
   public function afterIsAvailable( Product $product)
            $hasStock = //place your condition here

            if ($hasStock)
                return true;
                return false;


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.