Hiding the Add to Cart Link for out of stock items using "if (uc_stock_level($node->model) <= 0) "

Posts: 47
Joined: 01/20/2008
Bug Finder

The following statement can be used to test if the stock level is less than 0:

<?php
if (uc_stock_level($node->model) <= 0) {
}
?>

Is there any way to extend this statement, so the add to cart button is hidden if the stock level is less than 0?

Using the code posted in this thread[*] (and this thread[*]) as a guide, I tried to create the following code:

<?php
if (uc_stock_level($node->model) <= 0) {
   
$output = '<div class="outofstock">';
   
$output .= <p> This product is out of stock </p>
   
$output .= '</div>';
  } else {
   
$output = $node->content['add_to_cart']['#value'] ;
  }
  return
$output;
}
?>

However, I am new to PHP, so I think my code is written wrong.
Does anyone have any ideas/pointers?

([*] These threads deal with hiding prices, but I'm guessing the underlying principle must be the same)

Posts: 1290
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

IIRC you need to make sure you can access the $node data, do a print_r($node) or something similar. If it's in a page.tpl.php type file, I sometimes need to get the nid of the current node by arg(1) - I think.

Maybe I don't quite understand what is happening? Where are you adding this code? To a template .php file?

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 47
Joined: 01/20/2008
Bug Finder

Thanks for your reply.

I am adding it to node.tpl.php. Is that the right place?

Posts: 47
Joined: 01/20/2008
Bug Finder

I've tried adding the code to node.tpl.php and template.php but it just produces a fatal error.

I think the code might not be written correctly.

Could some one give me some pointers for the code (and also where to put it)? ^_^