Commerce Hook Function To Checkout Button I am a Drupal Commerce novice. I have a basic cart system working fine, but I now need to get into some custom code. I don't think I can use Rules because the code is a bit too complicated.

I have a Shopping Cart page with a Checkout button. I want to hook into that Checkout button.

I need to add a php function (which I already have) which will execute when that button is clicked but -before- the checkout page is rendered.

And I need this to do so without disabling the default actions that the Checkout button performs.

SO: How do I hook into this button without disabling the default behaviour?

Due to my noobness--I'd appreciate as complete an example as possible. I'm not lazy, just can't take for granted that I'll catch everything I need to if the answer is 'shorthand'.

TIA,

---JC
The checkout form is a form like any other, so you can just alter it (using hook_form_alter()) and add a submit handler:

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'views_form_commerce_cart_form_default') {
    $form['#submit'][] = 'MYMODULE_some_function';
  }
}

function MYMODULE_some_function($form, &amp;$form_state) {
  drupal_set_message('This was run after the cart form was submitted, before the checkout page was rendered.');
}


Addressing the comments...

As you have a custom shopping cart form, with a link instead of submit button, no extra processing will be done so you can just hook into the page build of the linked page (/checkout/%) and perform your operation there; it will have the same effect. 

There are a couple of places you could do this (neither really 'better' than the other), hook_page_alter() and hook_init(). There are other places too (theme preprocess functions) but for processing logic something a bit earlier is probably more appropriate. Basic example (will probably need tweaking for your needs):

function MYMODULE_init() {
  if (arg(0) == 'checkout' &amp;&amp; $some_other_pertinent_condition) {
    // Do some processing.
  }
}


As for learning Commerce - that's a tricky one. Commerce is heavily integrated with Drupal and uses a lot of its functions/hooks/integrations just like any other module would. So really you need to know Drupal's workflow, and then overlay Commerce's workflow on top of that. The best advise I can give is to grab a Drupal book (Pro Drupal Development is excellent), and after you're happy with the workflow there, hit the Drupal Commerce support pages and read, read, read.

Drupal has a notoriously steep learning curve, and there isn't really a shortcut to understanding how it works as a whole. You just have to get stuck in. But it's well worth it, Drupal's awesome.