Jump to content

Display Stock for Products


RPS

Recommended Posts

This code will take a product id and display the stock, if stock is 0, then it will display an out of stock message.

 

This is useful if you have a product for sale on your website and would like to show everyone the stock available.

 

Put this code somewhere within your php page:

 

<?php
# path can be:
# /home/user/public_html/whmcs/configuration.php
# ../whmcs/configuration.php
# whmcs/configuration.php
# etc..
require('whmcs/configuration.php');
mysql_connect($db_host, $db_username, $db_password) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
# be sure to modify the 39 and use the product id you wish to display, this is the pid variable found on the shopping cart order link of the product details
$result = mysql_query("SELECT qty FROM tblproducts WHERE id = 39 AND stockcontrol = 'on'"); 
$row = mysql_fetch_row($result);
$qty_39 = "(".$row[0]." in stock)";
?>

 

Use this code whenever you would like to display the product stock.

 

<?php if(!$row[0]) echo $out_of_stock; else echo $qty_39; ?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated