In ubercart,While buyer sees a product and clicks on add-to-cart button for buying that product, i want to know which action is responsible for that product being added in to the cart?

I want to edit the sell price, so that only this question. Already tried this hook, but it was not printing anything,

    mymodulename_uc_add_to_cart($nid, $qty, $data) {
    print "<pre>";print_r($data);print "</pre>";exit;

    if ($qty > 1) {
        $result[] = array(
                'success' => FALSE,
                'message' => t('Sorry, you can only add one of those at a time.'),
    return $result;

Which of these hooks


is responsible for adding quantity and price to cart in the cart page.Or is there any other hook which is doing it ?

Any ideas? Thanks in advance


If you want to alter the cart item, then you can use hook_uc_cart_alter of ubercart.

This hook is not in documentation of ubercart 7 but its still working for Ubercart 7.

This is called every time the cart is rebuild (e.g. when products are added), so it's a good place to alter the cart item.

I have checked uc_coupon module and hook hook_uc_cart_alter is implemented into that module. So, you can try this hook.

Edit: Code snippets to modify the price of item

 * Implements uc_cart_alter.
function mymodule_uc_cart_alter(&$items ) {

  foreach ($items as $index => $item) {

   //you can add condition for your bid product

    $items[$index]->price = 100;

For reference:


| improve this answer | |
  • I am not using uc_coupon. Before product is added to cart page(if i click on add-to-cart button), i want to alter the sell price of tat product ? is tat possible using hook_uc_cart_alter? If so how? – Ram Nov 18 '13 at 5:16
  • @Ram, Yes, its possible to alter sell price of the product. I only mentioned uc_coupon module, so you know that this hook is working in other contrib module. – Jayendra Kainthola Nov 18 '13 at 5:18
  • Let me try hook_uc_cart_alter – Ram Nov 18 '13 at 5:19
  • on clicking on add-to-cart button in hook_uc_cart_alter, it doesn't have currently added product in the order object. $order = new UcOrder(); $order->products = $items; $order->data = array(); print "<pre>"; print_r($order);exit; print "</pre>"; – Ram Nov 18 '13 at 10:03
  • @Ram, hook_uc_cart_alter will allow you to alter the item of cart content. $order will automatically fetch the updated cart item by hook_uc_cart_alter. – Jayendra Kainthola Nov 18 '13 at 10:08

with little googling I found this,might be what you are looking for

core add to functionality is handled by

uc_cart_add_item($nid, $qty = 1, $data = NULL, $cid = NULL, $msg = TRUE, $check_redirect = TRUE, $rebuild = TRUE)



But if you are looking for a hook which allows you to penetrate your codes,

hook_uc_add_to_cart($nid, $qty, $data)



Also check the following links for more info about different API's




Checkout already being discussed thread for custom alteration of prices here.

| improve this answer | |
  • Tried all those and i can't find which one is the 'ONE'.Also tried hook_uc_add_to_cart and it didnt help. – Ram Nov 12 '13 at 10:22
  • can you make sure if there is any cache issue – arpitr Nov 12 '13 at 10:35
  • Already tried clearing cache stil no success. – Ram Nov 12 '13 at 10:36
  • @ram just to make sure if you have missed replacing hook with your module name, I am suggesting as your sample code does not reflect so – arpitr Nov 12 '13 at 10:40
  • That's an example.In the code i have my module name only. – Ram Nov 12 '13 at 10:45

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.