Out of the box, Ubercart handles Out Of Stock situations very poorly. Here's how to modify the "Add to cart" button to "Out of stock" when you are out of stock of a particular item.
There are two versions of code for this solution. One for Drupal 6 and one for Drupal 7. In both cases you will need to create a module and enable it
Drupal 6 Ubercart version
function uc_out_of_stock_form_alter(&$form, $form_state, $form_id) {
if (substr($form_id, 0, 28) == 'uc_product_add_to_cart_form_') {
// get the node id from the $form array
$nid = $form['nid']['#value'];
// load the node
$node = node_load($nid);
// if the stock level is less than one, show "out of stock" on the button
// and disable the button functionality.
if (uc_stock_level($node->model)<1){
$form['submit']['#value'] = 'Out of stock';
$form['submit']['#executes_submit_callback'] = FALSE; // untested
$form['submit']['#disabled'] = TRUE;
}
}
}
Drupal 7 Ubercart Version
function uc_out_of_stock_form_alter(&$form, &$form_state, $form_id) {
if (substr($form_id, 0, 28) == 'uc_product_add_to_cart_form_') {
// get the node id from the $form array
$nid = $form['nid']['#value'];
// load the node
$node = node_load($nid);
// if the stock level is less than one, show "out of stock" on the button
// and disable the button functionality.
if (uc_stock_level($node->model) < 1) {
$form['actions']['submit']['#value'] = 'Out of stock';
$form['actions']['submit']['#executes_submit_callback'] = FALSE; // untested
$form['actions']['submit']['#disabled'] = TRUE;
}
}
}
For those people who are a little daunted by writing their own modules, I have created a Drupal 6 (D6) and Drupal 7 (D7) version of these files for you. Just download the appropriate zip file for your version of Drupal, extract it to your sites/default/modules directory, then enable it and play with your stock levels to see if it works.
UPDATE:
I want to acknowledge Eduardo Martinez http://michaelphipps.com/how-modify-drupal-ubercart-add-cart-button-out-... for the suggestion to protect submission via DOM

