In template.php
or some such...
function site_uc_product_add_to_cart( $variables ) {
$sku = $variables['form']['node']['#value']->model;
$stocklevel = uc_stock_level($sku);
if (is_numeric($stocklevel)) {
// Stock tracking is active
if ($stocklevel <= 0) {
return '<div class="add-to-cart out-of-stock"><button disabled>' . t('Sold') . '</button></div>';
}
else {
return theme_uc_product_add_to_cart($variables);
}
}
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($variables);
}
}
I tried this with Drupal 7 and UC 3 to no avail. Thoughts on why it didn’t work?
Thanks for the snippet!
Derek M / 8:21am / 9 January 2012
Did you get the function name right? You’ll have to change “site_” in the function name to the name of your theme.
Ryan / 11:54am / 10 January 2012