How to Display a “Low Stock” Alert on Zen Cart Product Pages
Tuesday, November 25th, 2008To 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.
