2 replies [Last post]
littly_kitty's picture
Offline
Bug Finder
Joined: 01/20/2008
Juice: 155
Was this information Helpful?

I want to be able to display a message to my users when a product is out of stock. That way, when they place an order for an out-of-stock product, they will be aware of the possibility that order may not be fulfilled.

After searching through the forums, I concluded that the best way of doing this would be to add a snippet of PHP to my to my template.

The following:

<?php
print uc_stock_level($node->model);
?>

will detect the stock levels, but I’m not sure how to write an if statement that will display a message if the stock level is less than 0.

Does anyone know of a solution to my problem (or a good resource that explains how to write PHP IF statements that doesn’t require a knowledge of PHP to understand).

[I know that there is a contributed module, Simple Stock Levels, that does this. However, at the bottom of the page [http://www.ubercart.org/contrib/132], there is a message saying that it is not a good idea to use this module with the updated ubercart].

Thanks ^_^

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Display a message when a product is out of stock

At its most basic, you can try something like this:

<?php
if (uc_stock_level($node->model) <= 0) {
 
drupal_set_message('This product is out of stock.', 'error');
}
?>

You can adjust the error message, display it some other way, or do whatever you want... but that's a basic if statement for ya. If you just want it to be a normal message, take out the ", 'error'".

cis.vindesh's picture
Offline
Joined: 01/19/2011
Juice: 11
out of stock message displaying

Hi

'out of stock' error message display when I added item to cart on my stage website http://stage.texenergo.com/cart.

but...but... same website running on my local machine there is not showing any this type of error.

could you tell me the reason why this happening??

Help me plzzzz.

Thanks you & Regards
Vindesh