Removing Add to Cart for Out of Stock Products in Opencart

  • Tuesday, 19 August 2014 14:03
Written by 
Rate this item
(4 votes)
Many Opencart users must be aware of this awful problem of Opencart, you can add a product which is out of stock. But you will not be allowed to checkout, which is completely frustrating to the users/shoppers. Recently i was working on an Opencart site and thought of fixing this problem. I was able to fix it without much sweat.
I am sharing it for all those Opencart users who wants to change the Add to Cart button to Out of Stock, for products which are not available.

Rule of the Thumb: Backup the said file before doing anything, in case anything bad happens.

Fire up your FTP program or your cPanel, and then open the following php file

/public_html/catalog/view/theme/emanipur/template/product/product.tpl

Please note that the theme name will differ from site to site. For this tutorial, i am using emanipur as the theme name.

After opening that file, find the Add to cart button which is somewhat like this 

<input type="button" value="<?php echo $button_cart; ?>" id="button-cart" class="button cart-product" />

Please note that the button Id and class may be different for your theme. The only thing you need to look out is the $button_cart value.

Now, remove the above lines and change with the following slightly modified code

<?php if ($stock == "In Stock")
     {
          ?>
               <input type="button" value="<?php echo $button_cart; ?>" id="button-cart" class="button cart-product" />
         <?php }
               else
                  {
           ?>
              <a class="button" style="font-size:16px;">Out of Stock</a>
         <?php
                  }
          ?>

That's it. Now instead of that Add to Cart button, it will be replaced by Out of Stock button/text.
Please remember that i am using my own button class for the Out of Stock button, you can create or use your own class to suit your theme appearance.

Feel free to contact us, if you have any problems.
Read 15731 times


7 comments

  • Comment Link //www.gravatar.com/avatar/1eaecc80ee68ffb0d5ab5593e31e0153?s=48&default=http%3A%2F%2Fwww.emanipur.org%2Fcomponents%2Fcom_k2%2Fimages%2Fplaceholder%2Fuser.png Thursday, 02 October 2014 04:20 posted by Sagar

    Product Page Edited Successfully thanks to this. But the Add to Cart buttons are still there on Category Page and the Homepage. For Category page getting the stock parameter is hectic. Can you help ?

  • Comment Link //www.gravatar.com/avatar/a77835ca9372a30e0c94f15d42203172?s=48&default=http%3A%2F%2Fwww.emanipur.org%2Fcomponents%2Fcom_k2%2Fimages%2Fplaceholder%2Fuser.png Friday, 10 October 2014 13:32 posted by eManipur! Team

    Hello Sagar,
    Please contact us via our contact form and we will help you out.

    Thanks

  • Comment Link //www.gravatar.com/avatar/9484e28d697ee08b5bb455f681f9de4c?s=48&default=http%3A%2F%2Fwww.emanipur.org%2Fcomponents%2Fcom_k2%2Fimages%2Fplaceholder%2Fuser.png Monday, 13 October 2014 02:51 posted by Homero Menezes

    Hello!

    Product Page Edited Successfully thanks to this. But the Add to Cart buttons are still there on Category Page and the Homepage. For Category page getting the stock parameter is hectic. Can you help ?

  • Comment Link //www.gravatar.com/avatar/8374d977c7723c285ebbdf99808bb2af?s=48&default=http%3A%2F%2Fwww.emanipur.org%2Fcomponents%2Fcom_k2%2Fimages%2Fplaceholder%2Fuser.png Thursday, 08 January 2015 12:05 posted by Sandhya Singh

    Hi I used the method you told and m successful in removing add to cart from the products page and i have replaced the same with out of stock. Huge Thanks to you. m new in opencart and now i want do the same in latest.tpl and best seller.tpl etc but even after so much try m not able to do the same. Any Help would be appriciated. Thanx in advance

  • Comment Link //www.gravatar.com/avatar/74840054d949414d1cfb197adac84444?s=48&default=http%3A%2F%2Fwww.emanipur.org%2Fcomponents%2Fcom_k2%2Fimages%2Fplaceholder%2Fuser.png Wednesday, 11 February 2015 06:06 posted by sree

    sir i want remove product description in featured list in home page...i am using opencart 2.0.0.0 pleas help me how to solve this problm..

  • Comment Link //www.gravatar.com/avatar/b4f8ee0c46170ce7bb5dfae3234cdbb8?s=48&default=http%3A%2F%2Fwww.emanipur.org%2Fcomponents%2Fcom_k2%2Fimages%2Fplaceholder%2Fuser.png Friday, 10 April 2015 10:14 posted by pushpendrasingh

    I just wanna thank you for sharing your information and your site or blog this is simple but nice article I've ever seen i like it i learn something today.
    ------------------

    Opencart Website Developer

    -------------------------

  • Comment Link //www.gravatar.com/avatar/1803d28fc3bf9a804e3b62e88c54cf37?s=48&default=http%3A%2F%2Fwww.emanipur.org%2Fcomponents%2Fcom_k2%2Fimages%2Fplaceholder%2Fuser.png Wednesday, 01 July 2015 15:28 posted by Claus

    Hi
    I tested with opencart 2.3.1 and no working.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.


Anti-spam: complete the task

Our Services

  • Web Design & UX Design
  • eCommerce sites
  • Social Media Marketing
  • Joomla Upgrade and troubleshooting
  • Blogging
  • Website Maintenance

Latest Offer from eManipur!

Joomla   Upgrade Your Old Joomla Website For Free*.
   For More Information click on the Link Below.

Upgrade Joomla

Drop in here

Keishamthong Elangbam Leikai,
Imphal -795001,
Manipur, India

Emanipur Location

Call

+91 8131 05 0034

Subscribe to our Tips

Receive our tips and hacks right into your Inbox. We promise you, it will be be a unique experience for you.


Receive HTML?

Social Icon
Facebook    Linked In    Gplus     Twitter