cancel
Showing results for 
Search instead for 
Did you mean: 

Change In Stock message depends on Quantity

Change In Stock message depends on Quantity

Hello, I am trying to change the message In stock depends on stock qty in the inventory.

 

What I did so far is to add this code :

 

<?php $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product); ?>
<?php $qty = "$stock->getQty()"; ?>

and then change from 

<?php if ($_product->isAvailable()): ?>
<p class="availability in-stock"><span>(<?php echo $this->__('In stock') ?>)</span></p>
<?php else: ?>
<p class="availability out-of-stock"><span>(<?php echo $this->__('Out of stock') ?>)</span></p> <?php endif; ?>

to this

<?php if ($_product->isAvailable() && $qty > 0): ?>
	<p class="availability in-stock"><span>(<?php echo $this->__('In stock') ?>)</span></p>
<?php elseif ($_product->isAvailable() && $qty = 0): ?>
	<p class="availability in-stock"><span>(<?php echo "hello" ?>)</span></p>
<?php else: ?>
	<p class="availability out-of-stock"><span>(<?php echo $this->__('Out of stock') ?>)</span></p>
<?php endif; ?>

but is not working.

What I am doing wrong?

Thanks in advance

 

 

 

4 REPLIES 4

Re: Change In Stock message depends on Quantity

Hello @geokat 

 

There's a mistake at:

$qty = 0

The correct way is:

$qty == 0

I hope it helps.

Problem solved? Click Kudos and "Accept as Solution".
200+ Magento 2 Extensions for Enhanced Shopping Experience.

Re: Change In Stock message depends on Quantity

Just been reading about the immense amount of uncertainty right now due to rising cases, US elections and global cues - so wanted to ask if it’s a good time to do some profit booking and probably re-enter if and when the market goes down much further? Or is it just a better idea to think long term and hold positions? krogerfeedback survey

Re: Change In Stock message depends on Quantity

The code is correct now but the result is not changing. When I turn the qty to zero it just say Available and not Hello that I type in the second case.

Re: Change In Stock message depends on Quantity

worked for me. Thanks