Page 1 of 3

[MOD] Hide add to cart button for items not in stock?

Posted: Sun Jun 13, 2010 12:39 pm
by Karen
It just looks strange to me to have an add to cart button for something that is clearly listed as not in stock.

Can someone give me the code mods to make to hide it when an item is not in stock? Am using 1.4.8.

Thanks!

Re: Hide add to cart button for items not in stock?

Posted: Thu Jun 17, 2010 6:34 pm
by Karen
I found this info, which is similar:

http://forum.opencart.com/viewtopic.php ... 3633#p3645

But it's from an older version.

Can anyone help me update it for 1.4.8, with the variable being number in stock = 0 rather than price being $0.0?

Re: Hide add to cart button for items not in stock?

Posted: Wed Jun 30, 2010 1:00 pm
by icareless
I'd like to know too.

Re: Hide add to cart button for items not in stock?

Posted: Wed Jun 30, 2010 2:28 pm
by i2Paq
There is a recent topic about this question + a solution here on these forums. I suggest you use the search.

Re: Hide add to cart button for items not in stock?

Posted: Wed Jun 30, 2010 2:40 pm
by Karen
Hi Norman,

As I always do, I did do a search for this before I posted it. Care to give us a link? We would certainly appreciate it.

Re: Hide add to cart button for items not in stock?

Posted: Wed Jun 30, 2010 7:05 pm
by JAY6390
Have to say I couldn't find this myself, but here's how I would do it
find this in your product.tpl file

Code: Select all

              <div class="content">
                <?php echo $text_qty; ?>
                <input type="text" name="quantity" size="3" value="<?php echo $minimum; ?>" />
                <a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a>                
                <?php if ($minimum > 1) { ?><br/><small><?php echo $text_minimum; ?></small><?php } ?>
              </div>
and change it to this (the first and last lines are the only additions)

Code: Select all

              <?php if($stock == $this->language->get('text_instock') || $stock > 0): ?>
              <div class="content">
                <?php echo $text_qty; ?>
                <input type="text" name="quantity" size="3" value="<?php echo $minimum; ?>" />
                <a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a>                
                <?php if ($minimum > 1) { ?><br/><small><?php echo $text_minimum; ?></small><?php } ?>
              </div>
              <?php endif; ?>
That should do it

Re: Hide add to cart button for items not in stock?

Posted: Wed Jun 30, 2010 7:26 pm
by i2Paq
Karen wrote:Hi Norman,

As I always do, I did do a search for this before I posted it. Care to give us a link? We would certainly appreciate it.
My bad.

The topic was hiding under a differend name: [MOD] Out of stock status change automatic?

Re: Hide add to cart button for items not in stock?

Posted: Wed Jun 30, 2010 8:01 pm
by JasonSGN
Thanks Jay. Simple and works perfectly!!!

Re: Hide add to cart button for items not in stock?

Posted: Wed Jun 30, 2010 8:05 pm
by JAY6390
No problem :)

Re: Hide add to cart button for items not in stock?

Posted: Thu Jul 29, 2010 11:11 am
by FFJim
Works great, but what about all the places where the item is listed with the [+] icon, such as Bestsellers, Featured, Search results, Category listings, etc.? Do each of these require separate edits or is there a function somewhere that can be edited?

Re: Hide add to cart button for items not in stock?

Posted: Thu Jul 29, 2010 4:10 pm
by JAY6390
separate edits required

Re: Hide add to cart button for items not in stock?

Posted: Thu Sep 02, 2010 2:48 pm
by YEWEI123SG
Where can i find "product.tpl" ?

Is it equivalent to "product.php" ?

I am using opencart_v1.4.9 version.

Re: Hide add to cart button for items not in stock?

Posted: Thu Sep 02, 2010 9:46 pm
by Qphoria
YEWEI123SG wrote:Where can i find "product.tpl" ?

Is it equivalent to "product.php" ?
YES! They are exactly the same, that is why we included both for fun ;)
This should help
http://forum.opencart.com/viewtopic.php?f=20&t=4113

Re: Hide add to cart button for items not in stock?

Posted: Sun Sep 12, 2010 11:33 pm
by dyl4n3
how do you remove the [+] icon next to out of stock items?

Re: Hide add to cart button for items not in stock?

Posted: Sun Nov 07, 2010 9:15 am
by EricP
I also need to know how to remove the Add to Cart button [+] for items in the category, specials, etc. due to the contract with the vendor, stating that the item can be on the site but cannot be put into a shopping cart. I have the button hidden on the item page, but I still need to remove it within the listing templates based on stock status. When I try to check the $stock variable it doesn't exist at that level.

Re: Hide add to cart button for items not in stock?

Posted: Fri Nov 12, 2010 2:17 am
by i2Paq
JAY6390 wrote:Have to say I couldn't find this myself, but here's how I would do it
find this in your product.tpl file

Code: Select all

              <div class="content">
                <?php echo $text_qty; ?>
                <input type="text" name="quantity" size="3" value="<?php echo $minimum; ?>" />
                <a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a>                
                <?php if ($minimum > 1) { ?><br/><small><?php echo $text_minimum; ?></small><?php } ?>
              </div>
and change it to this (the first and last lines are the only additions)

Code: Select all

              <?php if($stock == $this->language->get('text_instock') || $stock > 0): ?>
              <div class="content">
                <?php echo $text_qty; ?>
                <input type="text" name="quantity" size="3" value="<?php echo $minimum; ?>" />
                <a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a>                
                <?php if ($minimum > 1) { ?><br/><small><?php echo $text_minimum; ?></small><?php } ?>
              </div>
              <?php endif; ?>
That should do it
I've tried your code in 1.4.9.2 but it does not work.

Re: Hide add to cart button for items not in stock?

Posted: Thu Nov 18, 2010 2:35 am
by i2Paq
OK, so I asked JAY6390 to help me on this, thanks JAY!

new code (and working)

Code: Select all

              <?php echo '<!-- STOCK: '.$this->language->get('text_instock').' -->'; ?>
              <?php if($stock === $this->language->get('text_instock') || (strlen($stock) == strlen((int)$stock) && $stock > 0)): ?>
              <div class="content">
                <?php echo $text_qty; ?>
                <input type="text" name="quantity" size="3" value="<?php echo $minimum; ?>" />
                <a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a>
                <?php if ($minimum > 1) { ?><br/><small><?php echo $text_minimum; ?></small><?php } ?>
              </div>
              <?php endif; ?>
If you want to show this only when a fixt amount of stock is used, use: <?php if($stock == -999): ?>

Re: Hide add to cart button for items not in stock?

Posted: Fri Nov 26, 2010 2:44 pm
by i2Paq
To hide the + see below:
SXGuy wrote:in catalog/controller/product/category.php

find

Code: Select all

'price'   => $price,
add underneath

Code: Select all

'quantity' => $result['quantity'],
in catalog/view/theme/default/template/product/category.tpl

find

Code: Select all

<a class="button_add_small" href="<?php echo $products[$j]['add']; ?>" title="<?php echo $button_add_to_cart; ?>" >&nbsp;</a>
replace with

Code: Select all

<?php if ($products[$j]['quantity'] > 0 ) { ?>
          <a class="button_add_small" href="<?php echo $products[$j]['add']; ?>" title="<?php echo $button_add_to_cart; ?>" >&nbsp;</a>
		  <?php } ?>

Re: Hide add to cart button for items not in stock?

Posted: Wed Jan 05, 2011 3:07 am
by i2Paq
Ok, so the next code works OK when the stock gets below 0.
I need (please) this code to work with a fixt amount, lets say -10.

Code: Select all

              <?php echo '<!-- STOCK: '.$this->language->get('text_instock').' -->'; ?>
              <?php if($stock === $this->language->get('text_instock') || (strlen($stock) == strlen((int)$stock) && $stock > 0)): ?>
              <div class="content">
                <?php echo $text_qty; ?>
                <input type="text" name="quantity" size="3" value="<?php echo $minimum; ?>" />
                <a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a>
                <?php if ($minimum > 1) { ?><br/><small><?php echo $text_minimum; ?></small><?php } ?>
              </div>
              <?php endif; ?>
I was told that I could use then

Code: Select all

<?php if($stock == -10): ?>
but whatever I try, it does not work.

I hope that JAY6390 will stop by and help me out ::)

Re: Hide add to cart button for items not in stock?

Posted: Wed Jan 05, 2011 7:43 pm
by JAY6390
If you want it to show whenever the stock level isn't -999 you can just simply use
<?php if($stock != -999): ?>