The following function works only for simple products (when they have an special price, a sale label is attached to the product image):

public function getLabels($product) {
    $labels = [];

    if ($product->getSpecialPrice()) {
        $labels['sale'] = 'Sale';

    return $labels;

Now I am wondering how to combine a check that works for simple products and for configurable products (thus also in the case that all child products of a configurable product have an special price).

1 Answer 1


try this code block on listing page ( works for me ) , in my case all child products have same price and special price is applied, you can use logic something like this:

if ($_product->getTypeId() == "configurable") {
    $_children = $_product->getTypeInstance()->getUsedProducts($_product);

    foreach ($_children as $child){
         $salePrice = $child->getFinalPrice();
         $regularPrice = $child->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();
    } else {
        $salePrice = $_product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue();
        $regularPrice = $_product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();
  • You are checking on only the first child product. What if there are multiple child products? OR second child product has a higher/lower sale price? Oct 15, 2020 at 1:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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