Page 1 of 1
how to hide "Add to Cart" button if price is 0.00?
Posted: Sun Jan 20, 2008 1:07 pm
by madaha
better hide the price "0.00" too.
Looking for help.
Re: how to hide "Add to Cart" button if price is 0.00?
Posted: Sun Jan 20, 2008 4:28 pm
by david.gilbert
I added into the product description input by clicking the source button the following code to remove the add to cart buttons on opencart-extras.com
Code: Select all
<style type="text/css">
.buttons { display: none; }
</style>
to disable the price and the buttons just add
Code: Select all
<style type="text/css">
.buttons { display: none; }
.right { display: none; }
</style>
Hope this helps
-Dave
Re: how to hide "Add to Cart" button if price is 0.00?
Posted: Sun Jan 20, 2008 10:12 pm
by madaha
What I mean is to hide the "add to cart" button if the price is zero. If the price is not zero, I want the button to be there.
Re: how to hide "Add to Cart" button if price is 0.00?
Posted: Sun Jan 20, 2008 10:20 pm
by david.gilbert
This fix is done per listing. When you add or edit the product, the WYSIWYG editor for the description has a button that says source. If you click that button ad add the code I've posted above at the very top of all that writing and then click the source button again and edit your listings description as normal, it will hide the buttons.
-Dave
Re: how to hide "Add to Cart" button if price is 0.00?
Posted: Wed Jan 23, 2008 11:19 am
by madaha
I want to handle this by PHP script automatically instead of CSS by hand.
thanks anyway.
Re: how to hide "Add to Cart" button if price is 0.00?
Posted: Wed Jan 23, 2008 12:08 pm
by bruce
At the bottom of catalog\template\default\content\product.tpl make the following change. I have shown some surrounding code to make it easier to see where.
Code: Select all
<div class="buttons">
<table>
<tr>
<td align="left"><input type="button" value="<?php echo $button_reviews; ?>" onclick="location='<?php echo $review; ?>'" /></td>
<?php if ($price > 0 ) { ?>
<td align="right"><input type="submit" value="<?php echo $button_add_to_cart; ?>" /></td>
<?php }?>
</tr>
</table>
</div>
Re: how to hide "Add to Cart" button if price is 0.00?
Posted: Wed Jan 23, 2008 4:47 pm
by madaha
Thanks for help.
It hide all "Add to Cart" buttons no matter what price is.
Re: how to hide "Add to Cart" button if price is 0.00?
Posted: Wed Jan 23, 2008 5:24 pm
by bruce

sorry about that, not enough testing on my part.
add the following line of code that sets 'price_amount' to catalog\controller\product.php ( extra code shown for location reference )
Code: Select all
$view->set('price', $currency->format($tax->calculate($product_info['price'], $product_info['tax_class_id'], $config->get('config_tax'))));
$view->set('price_amount', $tax->calculate($product_info['price'], $product_info['tax_class_id'], $config->get('config_tax')));
modify what I gave you before in catalog\template\default\content\product.tpl to be as follows
Code: Select all
<div class="buttons">
<table>
<tr>
<td align="left"><input type="button" value="<?php echo $button_reviews; ?>" onclick="location='<?php echo $review; ?>'" /></td>
<?php if ($price_amount > 0.0 ) { ?>
<td align="right"><input type="submit" value="<?php echo $button_add_to_cart; ?>" /></td>
<?php }?>
</tr>
</table>
</div>
You will note that it tests $price_amount this time which is a number, not $price which is text formatted with currency characters.
Re: how to hide "Add to Cart" button if price is 0.00?
Posted: Wed Jan 23, 2008 10:14 pm
by madaha
thank you so much for your kind help!