1

I am not able to display SALE labels on configurable products.

I am able to display NEW when I set a product as new for a certain period of time, however when I have a special price on a product I am not able to display the SALE label.

I am using Magento 2.3.2. Is there anything I can do? I saw that there is this issue already reported here Magento 2 configurable products issue but as I understood I should not be able to set a product as NEW as well.

Hopefully, someone can assist with this further.

Thanks

0

Create a <div> with your SALE label on the product list page where you want to display the SALE label. For e.g.

<div class="sale_label" style="display: none;">//your sale label</div>

Now on the same file check if the current product is configurable product than check if its child products have a special price or not.

$configProduct = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);

$_children = $configProduct->getTypeInstance()->getUsedProducts($configProduct);
$salePrice = array();
foreach ($_children as $child){
    $salePrice[] = $child->getSpecialPrice();
}
if($salePrice != ''){ ?>
<script>
require(['jquery', 'jquery/ui'], function($){
   jQuery(document).ready( function() {
     jQuery("sale_label").show();
   });
});
</script>
<?php } ?>

You can use it without Object Manager.

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.