2

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; ?>
1

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

| improve this answer | |
  • FML cannot believe I didn't spot that. Thanks – Boss Nass Apr 20 '19 at 4:24
  • Welcome @Paul :) – Pawan Apr 20 '19 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.