UPDATE: I found the solution. This code will check the stock of each product when completing an order, then unpublish any products that have a stock or zero or negative. I left the echo's in to help debug, but as it is nothing gets sent to the screen. Any bugs please let me know!
<?php
$nids = array();
foreach (
$order->products as $product) {
//echo '<br />Checking the stock level of model:' . $product->model;
//echo '<br />The stock level is ' . uc_stock_level($product->model) . ' which we check against zero';
if ((uc_stock_level($product->model) - 1) <= 0) {
//echo '<br />The stock level is zero or negative, unpublish nid:' . $product->nid;
// if the stock WILL be 0 or negative after this order, then add to the list to unpublish
$nids[] = $product->nid;
}
}
/*
echo '<pre><b>The nids that will be unpublished are:</b><hr>';
print_r($nids);
echo '</pre>';
*/
node_operations_unpublish($nids);
?>