Hello Richard,
Here is how I would do this to retain the compatibility with future X-Cart 5 versions:
1. Create a custom module
2. Copy the skins/default/en/product/details/stock/body.tpl file to skins/default/en/modules/[YOUR_DEV_ID]/[YOUR_MODULE_ID]/product/details/stock/body.tpl and change it as follows:
HTML Code:
...
<span class="product-items-available" IF="isItemsAvailableVisible()">({t(#X items available#,_ARRAY_(#count#^getAvailableAmount()))})</span>
...
3. Decorate \XLite\View\Product\Details\Customer\Stock class as follows:
classes/XLite/Module/[YOUR_DEV_ID]/[YOUR_MODULE_ID]/View/Product/Details/Customer/Stock.php
PHP Code:
namespace XLite\Module\[YOUR_DEV_ID]\[YOUR_MODULE_ID]\View\Product\Details\Customer;
abstract class Stock extends \XLite\View\Product\Details\Customer\Stock implements \XLite\Base\IDecorator
{
protected function isItemsAvailableVisible()
{
// Add your logic here and set $flag to TRUE when the stock level is to be displayed
return $flag;
}
protected function getDefaultTemplate()
{
return 'modules/[YOUR_DEV_ID]/[YOUR_MODULE_ID]/product/details/stock/body.tpl';
}
}
Haven't tested the code, but it should work as is.