Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need help with a boolean function in PHP. It's simple (but I'm not PHP savvy enough to do it myself). I just need to create a block with a message (not a system message because I am using better messages and I don't want people to close the pop-out without even reading it) that will only show in the ubercart cart page, if two of the products are in the cart. Else it won't show.

Of course, if there is a better workaround tio this, I am open to suggestions.

Thanks in advance to whomever might wanna help.

share|improve this question
is this Drupal7 ? – niksmac Nov 23 '12 at 4:23
up vote 0 down vote accepted

Create a block with input format as php code. uc_cart_get_contents() function will help you to get current cart products. So use it to check for your products.


$items = uc_cart_get_contents();
// print_r($items); you can see all
foreach ($items as $item){
  //check your condition if condition true print your message,

Assign the block to a specific region and give display in cart page only

share|improve this answer
PHP Eval will slow down the code about ~60% and why dont you check if (empty($items)) ? – niksmac Nov 23 '12 at 4:24
users need is to check "if two of the products are in the cart". It is not clear that if he want to check just any 2 products or a particular type of products. If he means particular type of products (empty($items)) not enough – Anoop Joseph Nov 23 '12 at 5:51
but the title says "Ubercart: PHP message if a Product is in cart" sorry for that. – niksmac Nov 23 '12 at 6:50
Sorry for the delay in replying! This is drupal 6.0! Thanks for the responses. I will go through them in a bit. Thank you Anoop! Will try that – cara Nov 30 '12 at 17:27
Yes I am sorry I was very unclear with my question. Maybe language barrier. It is like this. This is a bakery. And almost everything is sold by unit, except for two types of Products that are sold by dozen. So when they add 1 to the cart, they're actually adding 12 (a dozen), and so I want for a message to remind users that it's not that they're paying 15 dollars for just one of those products, but for a whole dozen, and that the 1 in the quantity means a dozen. – cara Nov 30 '12 at 17:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.