Hide Price for Out of Stock Products – PHP and HTML Guide

htmlPHPpriceprice-rules

How to hide price for out of stock products in all Magento pages.(product pages and category pages)

Best Answer

Generally price is render by below code:

<?php echo $this->getPriceHtml($_product); ?>

And magento is check in stock by using below code:

$_product->isSaleable().

At list.phtml file add this as condition like :

<?php if($_product->isSaleable()): ?>
<?php echo $this->getPriceHtml($_product,true); ?>
<?php endif; ?>

At view.phtml and condition like:

<?php if($_product->isSaleable()): ?>
<?php echo $this->getPriceHtml($_product); ?>
<?php endif; ?>

and

<?php if($_product->isSaleable()): ?>
 <?php echo $this->getTierPriceHtml() ?>
 <?php endif; ?>

Also you can do this by css:

add css code at list.phtml and view.phtml file:

<?php if(!$_product->isSaleable()): ?>
<style type="text/css">

.price-box {display:none;}
</style>
<?php endif; ?>
Related Topic