Hiding Price if 0

The question:

This seems like it should be easier then the results Im getting. Im not a PHP expert but I’ve got a product(s) that will be a different price and therefore am trying to set it up so when it’s in my catalog it simply says “Call For Price or Call To Order”.

I’ve got my own template file in in my theme and it is working, just not properly. I dont know any other way to do this and I know it’s probably not best practice (I’m open to suggestions).
I’ve set it up so when the price is set to “0” a message should be displayed for calling.

<?php if ($this->getPriceHtml($_product) === "$0.00" ) : ?>
    <h2>Call  To Order</h2>
<?php else: ?> 
    <?php echo $this->getPriceHtml($_product); ?>
<?php endif; ?>

IT seems to me like this should work but It keeps showing the price of $0.00. What am I missing?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

Not sure but it might be due to ===. In this case == should be more than enough.

Instead of comparing a string try and use the finalPrice value which is numeric. It would also prevent any issues if the format of your price HTML ever changes.

<?php if ($_product->getFinalPrice() == 0) : ?>
    <h2>Call  To Order</h2>
<?php else: ?> 
    <?php echo $this->getPriceHtml($_product); ?>
<?php endif; ?>

Method 2

<?php if ($_product->getFinalPrice() == 0) : ?>
    <h2>Make your selection</h2>
<?php else: ?> 
    <?php echo $this->getPriceHtml($_product); ?>
    <?php echo $this->getChildHtml('bundle_prices') ?>
    <?php echo $this->getTierPriceHtml() ?>
<?php endif; ?>

this works great, with one exception if yo uhave custom options (dropdowns) with additional prices, then when selected the price does not now get updated as per selection like it did before

is there anyway to get this working

this is magento 1.9 with rwd theme


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment