I modified below code to allow for stock levels on product attributes. Not elegant, but it works 
// ######### BEGIN CUSTOM CODING RELATED TO STOCK DISPLAY ###############
function YOURTHEMENAME_uc_product_add_to_cart( $node ) {
// look up all sku's for this product
$skus=uc_attribute_uc_product_models($node);
if(!empty($skus)){ // if there are multiple sku's, then list stock availability of options.
$avail = array();
foreach($skus as $val) {
$sl = uc_stock_level($val);
if (is_numeric($sl)) {
$name=lookup_option_name($val); // get the pretty name of option sku
$avail[] = " " .$name." (".$sl.")";
}
}
if(!empty($avail)) { $avail_string = "<br><div class=\"stock_level\">Number Available: ". implode(",",$avail) ."</div>"; }
return( $avail_string ). theme_uc_product_add_to_cart($node);
}
else { // else, we do the normal thing.
$stocklevel = uc_stock_level($node->model);
if (is_numeric($stocklevel)) {
// Stock tracking is active
if ($stocklevel == 0) {
return( '<div class="out_of_stock">' . t('Sorry, this item is out of stock') . '</div>' );
} else {
return( '<div class="stock_level">' . t('Number available: ') . $stocklevel . '</div>' ) . theme_uc_product_add_to_cart($node);
}
} else {
// Stock tracking is not being used for this product, just show the add to cart button as normal
return theme_uc_product_add_to_cart($node);
}
}
}
function uc_attribute_uc_product_models($node) {
$models = array();
// Get all the SKUs for all the attriibutes.
$adjustments = db_query("SELECT model FROM {uc_product_adjustments} WHERE nid = %d", $node->nid);
while ($adjustment = db_fetch_object($adjustments)) {
if (!in_array($adjustment->model, $models)) {
$models[$adjustment->model] = $adjustment->model;
}
}
return $models;
}
function lookup_option_name($sku){
//uc_attribute_options: name,oid
//uc_product_adjustments: combination (number in "quotes" equals oid above),model
$query = "SELECT combination FROM {uc_product_adjustments} WHERE model = '$sku'";
$result = db_query($query);
while ($row = db_fetch_array($result)) {
$combo = $row[combination];
list($stuff, $oid, $junk) = split('"', $combo);
$query2="SELECT name FROM {uc_attribute_options} WHERE oid = '$oid'";
$result2=db_query($query2);
while($row2=db_fetch_array($result2)){$name=$row2[name];}
return $name;
}
}
Here's a simple way to display stock level for nodes, and also to remove the "add to cart" button if the stock is zero.
Add the following to the template.php file in your sites/all/themes/YOUR_THEME_NAME directory, changing the function name according to your theme's name:
function YOUR_THEME_NAME_uc_product_add_to_cart( $node ) {
$stocklevel = uc_stock_level($node->model);
if (is_numeric($stocklevel)) {
// Stock tracking is active
if ($stocklevel == 0) {
return( '<div class="out_of_stock">' . t('Sorry, this item is out of stock') . '</div>' );
} else {
return( '<div class="stock_level">' . t('Number available: ') . $stocklevel . '</div>' ) . theme_uc_product_add_to_cart($node);
}
} else {
// Stock tracking is not being used for this product, just show the add to cart button as normal
return theme_uc_product_add_to_cart($node);
}
}Note that there are some obvious limitations to this:
1. It doesn't stop someone adding a quantity to their cart that is greater than the stock available
2. It doesn't update in real time so you may see the "add to cart" button but there may be no stock available by the time you click it
3. Stock is normally updated when an item is purchased, but this code tests at "add to cart" time
4. It is unlikely to work with product attributes. I don't use attributes, so didn't test it, but from what I understand about them, I think this approach is too simplistic.
