Would like to put an if statement in the below code as follows.
If saleable qty <=0 (equals 0 or under), add CSS. Otherwise, add different CSS
<div class="left-stock">
<strong>
<?= ($block->salebleqty() != '') ? $block->escapeHtml(__('Only %1 left in stock!', $block->salebleqty())) : '' ?>
</strong>
</div>
Best Answer
You can use the following code conditionally to display different CSS based on your condition:
For example:
In this code, the
color
CSS property is added to thestrong
tag. You can adjust it to fit your needs.For those using Magento 2.4.0 or higher version, it is recommended to use the
$secureRenderer
variable, which is available in thephtml
template, to render thestyle
tag. You can refer to theimage_with_borders.phtml
in Magento core for an example https://github.com/magento/magento2/blob/2.4.0/app/code/Magento/Catalog/view/frontend/templates/product/image_with_borders.phtml