[TomatoCart] Hide Add to Cart Button for Out of Stock Items in Glass Gray Template

Several community users contact me to get the solution for the following problem:

Hi,

I have been able to reconfigure the code with help from the site to stop showing the “Add to Cart” or “Buy Now” buttons for products that are out of stock, however I am stumped by the listings on the front page.

When you go to the front page and it shows New Items, I still see my out of stock items and they can still be added to the cart, even though on all other pages you cannot do this.

Can someone help me to change it so that either the new items listing show out of stock items without the “Add to Cart” button, or just not show the out of stock items at all.

In this article, i will teach you how to hide the add to cart / buy now button when the item is out of stock in the glass gray template. Please update your store files as follows:

Add a new configuration for your store

admin_stock

Step 1. Go to your web host cpanel and find the phpmyadmin tool in it.

Step 2. Run the following sql in your phpmyadmin tool to add the new configuration for your store.

INSERT INTO toc_configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('Hide add to cart button for out of stock items', 'STOCK_HIDE_OUT_OF_STOCK', '0', 'When the product is out of stock, the add to cart button will not be shown in the store front.', '9', '7', 'osc_cfg_use_get_boolean_value', 'osc_cfg_set_boolean_value(array(1, -1))', now());

Hide the add to cart buttons for the out of stock items in the new products module.

new_products_module_out_of_stock

Step 1. Go to includes/modules/content/new_products.php and find the following code snippet:

$this->_content .= '<div style="margin-top: 10px; float:left; width: 33%; text-align: center">' .
                             '<span style="display:block; height: 32px; text-align: center">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qnewproducts->value('products_id')), $Qnewproducts->value('products_name')) . '</span>' . 
                             osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qnewproducts->value('products_id')), $osC_Image->show($Qnewproducts->value('image'), $Qnewproducts->value('products_name')), 'id="img_ac_newproductsmodule_' . $Qnewproducts->value('products_id') . '"') .
                             '<span style="display:block; padding: 3px; text-align: center">' . $product->getPriceFormated(true) . '</span>' . 
                             osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qnewproducts->valueInt('products_id') . '&action=cart_add'), osc_draw_image_button('button_add_to_cart.png', $osC_Language->get('button_add_to_cart'), 'class="ajaxAddToCart" id="ac_newproductsmodule_' . $Qnewproducts->value('products_id') . '"')) . '</div>';

Step 2. Replace it with:

$this->_content .= '<div style="margin-top: 10px; float:left; width: 33%; text-align: center">' .
                             '<span style="display:block; height: 32px; text-align: center">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qnewproducts->value('products_id')), $Qnewproducts->value('products_name')) . '</span>' . 
                             osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qnewproducts->value('products_id')), $osC_Image->show($Qnewproducts->value('image'), $Qnewproducts->value('products_name')), 'id="img_ac_newproductsmodule_' . $Qnewproducts->value('products_id') . '"') .
                             '<span style="display:block; padding: 3px; text-align: center">' . $product->getPriceFormated(true) . '</span>';

          $display_buy_now = true;
          if (defined('STOCK_HIDE_OUT_OF_STOCK') && STOCK_HIDE_OUT_OF_STOCK == 1) {
          	if ($product->getQuantity() < 1) {
          		$display_buy_now = false;
          	}
          }

          if ($display_buy_now) {
          	$this->_content .= osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qnewproducts->valueInt('products_id') . '&action=cart_add'), osc_draw_image_button('button_add_to_cart.png', $osC_Language->get('button_add_to_cart'), 'class="ajaxAddToCart" id="ac_newproductsmodule_' . $Qnewproducts->value('products_id') . '"')) . '</div>';
          }else {
            $this->_content .= '<div class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . $osC_Language->get('out_of_stock') . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</div></div>';
          }

Hide the add to cart buttons for the out of stock items in product listing.

listing_out_of_stock

Step 1 . Go to includes/modules/product_listing.php and find the following code snippet:

if ($Qlisting->value('products_type') == PRODUCT_TYPE_SIMPLE) {
							//enable quantity input field
							if (defined('PRODUCT_LIST_QUANTITY_INPUT') && PRODUCT_LIST_QUANTITY_INPUT == 1) {
								$lc_text .= '<input type="text" id="qty_' . $Qlisting->value('products_id') . '" value="1" size="1" class="qtyField" />';
							}

              $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add'), osc_draw_image_button('button_buy_now.gif', $osC_Language->get('button_buy_now'), 'class="ajaxAddToCart" id="ac_productlisting_'. $Qlisting->value('products_id') . '"')) . ' <br />';
            }else {
              $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add'), osc_draw_image_button('button_buy_now.gif', $osC_Language->get('button_buy_now'))) . ' <br />';
            }

Step 2. Replace it with:

 $display_buy_now = true;
            if (defined('STOCK_HIDE_OUT_OF_STOCK') && STOCK_HIDE_OUT_OF_STOCK == 1) {
              if ($osC_Product->getQuantity() < 1) {
                $display_buy_now = false;
              }
            }

            if ($Qlisting->value('products_type') == PRODUCT_TYPE_SIMPLE) {
							if ($display_buy_now) {
						  	//enable quantity input field
								if (defined('PRODUCT_LIST_QUANTITY_INPUT') && PRODUCT_LIST_QUANTITY_INPUT == 1) {
									$lc_text .= '<input type="text" id="qty_' . $Qlisting->value('products_id') . '" value="1" size="1" class="qtyField" />';
								}

								$lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add'), osc_draw_image_button('button_buy_now.gif', $osC_Language->get('button_buy_now'), 'class="ajaxAddToCart" id="ac_productlisting_'. $Qlisting->value('products_id') . '"')) . ' <br />';
							}else {
							  $lc_text .= '<div class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . $osC_Language->get('out_of_stock') . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</div>';
							}
            }else {
							if ($display_buy_now) {
							  $lc_text .= osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $Qlisting->value('products_id') . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add'), osc_draw_image_button('button_buy_now.gif', $osC_Language->get('button_buy_now'))) . ' <br />';
							}else {
							  $lc_text .= '<div class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . $osC_Language->get('out_of_stock') . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</div>';
							}
            }

Hide the add to cart buttons for the out of stock items in new products listing.

out_stock_new

Step 1. Go to templates/glass_gray/content/products/new.php and find the following code snippet:

<td align="right" valign="middle">
          <?php 
            echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qproducts->value('products_id') . '&action=cart_add'), osc_draw_image_button('button_in_cart.gif', $osC_Language->get('button_add_to_cart'), 'class="ajaxAddToCart" id="ac_productsnew_' . $Qproducts->value('products_id') . '"'));
          ?>
        </td>

Step 2. Replace it with:

<td align="right" valign="middle">
          <?php 
	          $display_buy_now = true;
	          if (defined('STOCK_HIDE_OUT_OF_STOCK') && STOCK_HIDE_OUT_OF_STOCK == 1) {
	          	if ($osC_Product->getQuantity() < 1) {
	          		$display_buy_now = false;
	          	}
	          }

	          if ($display_buy_now) {
	            echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qproducts->value('products_id') . '&action=cart_add'), osc_draw_image_button('button_in_cart.gif', $osC_Language->get('button_add_to_cart'), 'class="ajaxAddToCart" id="ac_productsnew_' . $Qproducts->value('products_id') . '"'));
	          }else {
	            echo '<div class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . $osC_Language->get('out_of_stock') . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</div>';
	          }

          ?>
        </td>

Hide the add to cart buttons for the out of stock items in special products listing.

out_of_stock_special

Step 1 . Go to templates/glass_gray/content/products/specials.php and find the following code snippet:

 echo '<div style="margin-top: 10px; float:left; width: 33%; text-align: center">' .
                   '<span style="display:block; height: 32px; text-align: center">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qspecials->value('products_id')), $Qspecials->value('products_name')) . '</span>' . 
                   osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qspecials->value('products_id')), $osC_Image->show($Qspecials->value('image'), $Qspecials->value('products_name')), 'id="img_ac_specials_'. $Qspecials->value('products_id') . '"') . 
                   '<span style="display:block; padding: 3px; text-align: center"><s>' . $osC_Currencies->displayPrice($Qspecials->value('products_price'), $Qspecials->valueInt('products_tax_class_id')) . '</s> <span class="productSpecialPrice">' . $osC_Currencies->displayPrice($Qspecials->value('specials_new_products_price'), $Qspecials->valueInt('products_tax_class_id')) . '</span>';

                   if ($Qspecials->value('products_type') == PRODUCT_TYPE_SIMPLE) {
                   	echo '<div class="qtyBlock"><input type="text" id="qty_' . $Qspecials->valueInt('products_id') . '" value="1" size="1" class="qtyField" /></div>';
                   }

                   echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qspecials->value('products_id') . '&action=cart_add'), osc_draw_image_button('button_add_to_cart.png', $osC_Language->get('button_add_to_cart'), 'class="ajaxAddToCart" id="ac_specials_' . $Qspecials->value('products_id') . '"'));

Step 2. Replace it with:

echo '<div style="margin-top: 10px; float:left; width: 33%; text-align: center">' .
                   '<span style="display:block; height: 32px; text-align: center">' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qspecials->value('products_id')), $Qspecials->value('products_name')) . '</span>' . 
                   osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qspecials->value('products_id')), $osC_Image->show($Qspecials->value('image'), $Qspecials->value('products_name')), 'id="img_ac_specials_'. $Qspecials->value('products_id') . '"') . 
                   '<span style="display:block; padding: 3px; text-align: center"><s>' . $osC_Currencies->displayPrice($Qspecials->value('products_price'), $Qspecials->valueInt('products_tax_class_id')) . '</s> <span class="productSpecialPrice">' . $osC_Currencies->displayPrice($Qspecials->value('specials_new_products_price'), $Qspecials->valueInt('products_tax_class_id')) . '</span>';

                   if ($Qspecials->value('products_type') == PRODUCT_TYPE_SIMPLE) {
                   	echo '<div class="qtyBlock"><input type="text" id="qty_' . $Qspecials->valueInt('products_id') . '" value="1" size="1" class="qtyField" /></div>';
                   }

                   $display_buy_now = true;
                   $osC_Product = new osC_Product($Qspecials->valueInt('products_id'));
                   if (defined('STOCK_HIDE_OUT_OF_STOCK') && STOCK_HIDE_OUT_OF_STOCK == 1) {
                   	if ($osC_Product->getQuantity() < 1) {
                   		$display_buy_now = false;
                   	}
                   }

                   if ($display_buy_now) {
		                  echo osc_link_object(osc_href_link(FILENAME_PRODUCTS, $Qspecials->value('products_id') . '&action=cart_add'), osc_draw_image_button('button_add_to_cart.png', $osC_Language->get('button_add_to_cart'), 'class="ajaxAddToCart" id="ac_specials_' . $Qspecials->value('products_id') . '"'));   
                   }else {
                     	echo '<div class="markProductOutOfStock">' . STOCK_MARK_PRODUCT_OUT_OF_STOCK . $osC_Language->get('out_of_stock') . STOCK_MARK_PRODUCT_OUT_OF_STOCK . '</div>';
                   }

That’s it.

If you can’t apply the code changes by yourself, please contact support@tomatocart.com to get technical support. We provide free technical support service for Arvixe users. So, we strongly recommend you to use Arvixe host to run your TomatoCart store.

Looking for quality TomatoCart Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , , , , , , | Posted under TomatoCart | RSS 2.0

Author Spotlight

Jack Yin

Jack Yin

TomatoCart Developer & Co Founder - Arvixe Web Hosting / TomatoCart Community Liaison

2 Comments on [TomatoCart] Hide Add to Cart Button for Out of Stock Items in Glass Gray Template

  1. Ale says:

    Hi Jack. This is great. Just a quick question…The first step in the sql..should I just copy and paste exactly what you entered and then click continue?

Leave a Reply

Your email address will not be published. Required fields are marked *


5 × = 15

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>