2

I'm using Drupal 7 + Ubercart 3 and am trying to run a piece of code just before the user adds a product in cart. hook_uc_add_to_cart seems to be the right function to use for it. So I'm trying to utilize it using the following syntax in template.php file of my template

function tbw_uc_add_to_cart($nid, $qty, $data){die('here: ' . $qty);}

where tbw is my template name. I've flushed all caches but the above code does not work as it doesn't die() when I add a product to cart. I suspect the problem is that this hook can't be implemented in a template because the documentation only talks about using it inside a module, i.e., Some modules need to be able to hook into the process of adding items to a cart.... Can anybody please shed some light on why it is not working and guide me in the right direction. Thanks.

2

I suspect the problem is that this hook can't be implemented in a template

Correct :)

Only hook_theme(), preprocess hooks, and alter hooks can be implemented in template.php. For any others, including this one, you'll need to write a custom module.

  • Just what I didn't want to be told :D Drupal keeps boasting off the steepness of its learning curve on me :( thank you for your help (another weekend to drupal) :) – Ejaz May 25 '13 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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