I need to call a function upon successful completion of an order, and that function needs to know the OrderID that called it.

I have setup a rule

Event: "Completing the checkout process"

Conditions: None

Actions: [custom function]

I am aware of two possible ways pass the order_id.

  1. Using a data selector (though I'm not exactly sure what this should be), and passing it through a 'value' argument -or-
  2. Calling the function commerce_cart_order_id($uid) from within my function.

commerce_cart_order_id($uid) did not seem to return anything.

global $user;
$uid = $user->uid;  
$order_id = commerce_cart_order_id($uid);
drupal_set_message(t('OrderID:  ' . $order_id), 'status');

Has anyone got any suggestions on what I might be doing wrong? Many thanks.

1 Answer 1


As you have mentioned, you want to act on completion of the order, so there is a hook of drupal_commerce, which get called on completion..


I have used this hook for some action at the order completion in my custom module. If you call this hook in your custom module then $order variable will have all the information related to order. Check this in your custom module --

function MYMODULE_commerce_checkout_complete($order){
  • @Jymz You welcome..
    – RajeevK
    Commented May 3, 2013 at 5:57

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.