Articles Menu
Headlines

Article Search

Search
Latest News
Change the lenght of the product description in opencart listing
I have noticed a lot of people enquiring about this so Ill post  an easy and short solution to it. Just for clarificat... read more
Font Size and Font color missing in opencart 1.5.5 html editor
If you updated your opencart store to latest version 1.5.5 or 1.5.5.1 you might have noticed that in the admin Html Editor (for produc... read more
Adefault2 opencart free template
There is a template design competition going on in the opencart forum. I also created a theme for this competition and subm... read more
Opencart 1.5.5 products filters - How it works
As you can all see , in the new opencart 1.5.5 a new module was added called 'Filter' and can be seen in admin by navigating t... read more
Headlines

Hide add to cart button if customer is not logged in (for openca

If you chose to only display your prices on store , only if the customer is logged in, then you might also want to hide the add to cart button, because even if the prices are not beeing displayed in the opencart product modules and in the opencart product listings, if a visitor adds a product to cart, he will be able to see the price on the shopping cart page.

So , to solve that, you just don't allow the visitor to add a product to cart unless he is logged in, and to do that, you hide the add to cart button like it follows:

1.Edit the files: featured.tpl, latest.tpl, special.tpl, bestseller.tpl located in catalog/view/theme/yourtheme/template/module and in each file , make the following modification:

move the code:

<div class="cart"><input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" /></div>

right after the code:

<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></ <span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
<?php } ?>
</div>

2. Now edit the files: category.tpl, search.tpl, special.tpl and manufacturer_info.tpl located in catalog/view/theme/yourtheme/template/product and make the following modifications:

2.1: find the code:

<div class="cart">
<input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" />
</div>

and replace it all with:

<?php if ($product['price']) { ?>
<div class="cart">
<input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" />
</div>
<?php } ?>

2.2: now find the code:

html += '<div class="cart">' + $(element).find('.cart').html() + '</div>';

and replace it with:

if (price != null) {
html += '<div class="cart">' + $(element).find('.cart').html() + '</div>';
}

2.3: and last , find the code:

html += ' <div class="cart">' + $(element).find('.cart').html() + '</div>';

and replace it with:

if (price != null) {
html += '<div class="cart">' + $(element).find('.cart').html() + '</div>';
}

3. Edit the file catalog/view/theme/yourtheme/template/product/product.tpl and find the code:

<div class="cart">
<div><?php echo $text_qty; ?>
<input type="text" name="quantity" size="2" value="<?php echo $minimum; ?>" />
<input type="hidden" name="product_id" size="2" value="<?php echo $product_id; ?>" />
&nbsp;<input type="button" value="<?php echo $button_cart; ?>" id="button-cart" class="button" />
</div>
<div><span>&nbsp;&nbsp;&nbsp;<?php echo $text_or; ?>&nbsp;&nbsp;&nbsp;</span></div>
<div><a onclick="addToWishList('<?php echo $product_id; ?>');"><?php echo $button_wishlist; ?></a><br />
<a onclick="addToCompare('<?php echo $product_id; ?>');"><?php echo $button_compare; ?></a></div>
<?php if ($minimum > 1) { ?>
<div class="minimum"><?php echo $text_minimum; ?></div>
<?php } ?>
</div>

and replace it with:

<?php if ($price) { ?>
<div class="cart">
<div><?php echo $text_qty; ?>
<input type="text" name="quantity" size="2" value="<?php echo $minimum; ?>" />
<input type="hidden" name="product_id" size="2" value="<?php echo $product_id; ?>" />
&nbsp;<input type="button" value="<?php echo $button_cart; ?>" id="button-cart" class="button" />
</div>
<div><span>&nbsp;&nbsp;&nbsp;<?php echo $text_or; ?>&nbsp;&nbsp;&nbsp;</span></div>
<div><a onclick="addToWishList('<?php echo $product_id; ?>');"><?php echo $button_wishlist; ?></a><br />
<a onclick="addToCompare('<?php echo $product_id; ?>');"><?php echo $button_compare; ?></a></div>
<?php if ($minimum > 1) { ?>
<div class="minimum"><?php echo $text_minimum; ?></div>
<?php } ?>
</div> <?php } ?>

4 Comments To "Hide add to cart button if customer is not logged in (for openca"
circey - 11/03/2013

Hi, I'm wondering how to do the same for the "Add to cart" button in the Related Products area.
Flo - 10/09/2012

2.2 and 2.3 are not the same. Notice there is a small difference in the code (in one of them is an extra space). That code is twice in that file (once for grid view and once for list) but there is a difference of a space inside them, that is why they are both added. I will edit the mistake on the last modification now.
Richard - 10/09/2012

This does not work. You put twice the same modification (2.2 and 2.3) and the last replace has an unclosed <div>
edna - 10/09/2012

Hi! Want to do this but noticed that edit code for section 2.3 is a duplicate of 2.2? Is there something else I need to edit? Thanks! Edna

Write a comment

Your Name:


Your Comment: Note: HTML is not translated!

Enter the code in the box below:



Opencart templates © 2013