I have a website that only sells one product. It has a $0.00 Price.

I have this custom form when sent, it will give the product id (e.g.) to the uc_cart_add_item

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

Well, technically it goes to the cart with a price of $0.00.

So the question here is, how can I alter the product price before sending it to the cart?

I saw this function from other website that this one alters the product price


Unfortunately, it doesn't seem to work or something.

I've searched for some questions

Ubercart alter product price when product added to cart

Even this one, but it's on Drupal Commerce not on Ubercart

programmically change price of product

Any help would be appreciated.

1 Answer 1


You want to alter the cart item, not the product node. hook_uc_cart_alter is what you're looking for.

function MYMODULE_uc_cart_alter(&$items) {
  foreach($items as $key => $item) { //Set all items to $3.50
    $item->price = 3.50;
  • I saw this code somewhere (that looks like this) and I tried it and it does not work for some reason, and yet I tried this it work. Oh my. Thanks for this! xD Jun 1, 2015 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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