0

i have this piece of code, but:

  1. i would like the span classes to appear when qty is 0
  2. do you always need the else, because else i don't want it to do anything

So only when an item is sold out it should show the text SOLD with the span classes.

Thanks.

<span class="sticker-wrapper top-left"><span class="out-of-stock">
         <?php 
                $qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
                if ($qty == 0) :
                    echo $this->__('SOLD');
                else :
                    echo $this->__('&nbsp;');
                endif;
        ?>
</span></span>

1 Answer 1

1

You can add class based on condition like this -

<?php $qty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); ?>
<span class="sticker-wrapper top-left"><span class="<?php if ($qty == 0) { echo  'out-of-stock'; } ?>">
         <?php 

                if ($qty == 0) :
                    echo $this->__('SOLD');
                else :
                    echo $this->__('&nbsp;');
                endif;
        ?>
</span></span>

2.You don't need else always, you can simply use only if like this-

if ($qty == 0){
//you can put your condition or whole span here
}
0

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.