Actually you asked 2 questions. To override the template file and override the block function.
The first one is easy.The original file is on vendor/magento/module-catalog-inventory/view/frontend/templates/stockqty/default.phtml
. To override this file, you can copy this file and paste it on your active theme. So that app/design/frontend/Your_Vendor/Your_Theme/Magento_CatalogInventory/templates/stockqty/default.phtml
. You can start editing it now.
The second one is a bit tricky, but still OK. To override the original threshold function isMsgVisible
, you can just modify it a bit.
Create a new module. Let's say, MyVendor_CatalogInventory. Create a new file app/code/MyVendor/CatalogInventory/etc/module.xml
and add the following content:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MyVendor_CatalogInventory" setup_version="0.0.1"/>
</config>
Create new file app/code/MyVendor/CatalogInventory/etc/di.xml
and add the following content:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="\Magento\CatalogInventory\Block\Stockqty\AbstractStockqty">
<plugin name="MyVendor_CatalogInventory::aroundIsMsgVisible" type="MyVendor\CatalogInventory\Block\Stockqty" sortOrder="10"/>
</type>
</config>
Create new file app/code/MyVendor/CatalogInventory/Block/Stockqty.php
with the following content:
<?php
namespace MyVendor\CatalogInventory\Block\;
class Stockqty{
public function aroundIsMsgVisible()
{
//Start your logic here
}
}
Enable this module
cd <your magento root>
php bin/magento module:enable MyVendor_CatalogInventory
Ref: http://devdocs.magento.com/guides/v2.1/extension-dev-guide/plugins.html