How to hide price for out of stock products in all Magento pages.(product pages and category pages)
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; ?>
-
the css code you presented is working fine on product page but it will hide price box for all products (both of in stock and out of stock products). – Moh3n Mar 18 '15 at 19:30
just replace:
<?= /* @escapeNotVerified */ $block->getProductPrice($_product) ?>
about at line 73 of list.phtml to:
<?php if($_product->isSaleable()): ?>
<?= /* @escapeNotVerified */ $block->getProductPrice($_product) ?>
<?php endif; ?>