Display sale badge on PLP
-
27-02-2021 - |
Question
I am trying to display a 'Sale' badge on product category pages if the products have a special price. Though the isn't rendering anything.
<?php if (_$product->getPriceInfo()->getPrice('special_price')->getValue()): ?>
<div class="product-abs-top w-100">
<div class="tags-wrapper">
<div class="tag sale">Sale</div>
</div>
</div>
<?php elseif ($_product->getResource()->getAttribute('badge')->getFrontend()->getValue($_product)): ?>
<div class="product-abs-top w-100">
<div class="tags-wrapper">
<div class="tag <?= /* @escapeNotVerified */ str_replace(' ', '_',strtolower($_product->getResource()->getAttribute('badge')->getFrontend()->getValue($_product))) ?>"><?= /* @escapeNotVerified */ $_product->getResource()->getAttribute('badge')->getFrontend()->getValue($_product) ?></div>
</div>
</div>
<?php endif; ?>
Solution
I think You have typo in your code:
<?php if (_$product->getPriceInfo()->getPrice('special_price')->getValue()): ?>
Should be:
<?php if ($_product->getPriceInfo()->getPrice('special_price')->getValue()):
See _$product
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange