How to Display a “Low Stock” Alert on Zen Cart Product Pages
To create a sense of urgency and let customers know a product has only one item left in stock, a simple SQL query is needed in the tpl_product_info_display.php file.
1. First, you must be tracking stock of your products through Zen Cart.
2. Download, includes/template/Your_Templates/tpl_product_info_display.php and open the file.
Copy this code:
<!-- bof limited supply -->
<?php
$limitedSupply_query = "SELECT products_quantity, products_id
FROM " . TABLE_PRODUCTS . "
WHERE products_id = '" . (int)$_GET['products_id'] . "' ";
$limitedSupply = $db->Execute($limitedSupply_query);
if ($limitedSupply->fields['products_quantity'] == 1) {
echo '<div id="limited">Only one left</div>';
}
?>
<!-- eof limited supply -->
3. Paste the code in the file where you would like the alert message to appear, I usually put it just above the Add to Cart button. Upload the edited file to includes/templates/Your_Template/
4. Download your stylesheet and create and define #limited. Upload the edited stylesheet to includes/templates/Your_Template/css/
5. Find a product on your web site that has only one product. Make any needed changes to the stylesheet.

December 29th, 2008 at 5:34 pm
hi there, this sounds really useful! unfortunately I am not familiar with css, could you explain in more detail points 4 and 5?
also, if i define the quantity at say “3″, will it also display the alert when stocks go below 3? thanks in advance!
December 30th, 2008 at 9:47 am
Thanks Gary,
If you are not familiar with CSS, visit the W3 School’s CSS Tutorial here.
Also, please make sure when changing any files in zen cart you:
1. Make a back up of the original file
2. Upload any edited files into your custom template directory.
As for the quantity in the SQL query, if you want the low stock alert to show when there are 3 items or less, you would change
if ($limitedSupply->fields['products_quantity'] == 1)
to
if ($limitedSupply->fields['products_quantity'] <= 3)
Good Luck with your project and thanks again for visiting!
December 31st, 2008 at 5:10 pm
Hey Renee,
I really appreciate you sharing this great tip!
I figured out the problem,
I realized when i copy and paste from your site, the ” and ‘ get all messed up and are not recognized.
So then I only spent another hour of pulling my hair out until I realized you misspelled “limited” in the echo line (left out an “i”)
haha well im just glad everything works now! Thanks again!
December 31st, 2008 at 7:09 pm
Sorry for your trouble and thanks for pointing out the difficulties. I’ve made changes to the post so the next person will have an easier time:) Happy New Year!