2

I downloaded the commerce bitcoin module and I'd like to override the current output of the pane. There is no theme_ function to override. How can this be done?

The code is below:

 1 <?php
  2
  3
  4 /**
  5  * Implements base_checkout_form()
  6  * Display the bitcoin address at the checkout
  7  *
  8  */
  9 function commerce_bitcoin_pane_checkout_form($form, $form_state, $checkout_pane, $order) {
 10
 11   
 12   
 13
 14   $output .= t('<strong>Total amount</strong> %total BTC', array('%total' => $bittotal)) . '<br/>';                                                                                               15   $output .= t('<a href="https://blockchain.info/address/'. $bitaddress .'" target="_blank">Check Blockchain.info Payment Status</a>') . '<br/>';
 16   $checkout_form['commerce_bitcoin_pane_field_display'] = array(
 17     '#markup' => $output
 18   );
 19
 20   return $checkout_form;
 21 }
1

It looks like using

 hook_commerce_checkout_pane_info_alter(&$checkout_panes) 

or

 hook_commerce_checkout_page_info_alter(&$checkout_pages) 

would be the best options. There are also hooks that allow you to create your own checkout panes/pages from scratch if necessary

(hook_commerce_checkout_pane_info() and hook_commerce_checkout_page_info())

I would suggest reading more about them here and checking out the specific examples (about page/pane info hook implementations) that you can find in the Drupal Commerce submodule (mostly Checkout) files

| improve this answer | |
  • that only gets the $checkout_panes data passed in, but what if you also wanted the $order data in the hook alter also? how do u pass that in? – Patoshi パトシ Nov 9 '15 at 5:44
6

Checkout panes are fieldsets within the context of per-page checkout router form. You can use a hook_form_alter() to modify the contents of the entire page that a form is shown on. For instance, if you want to modify objects that appear on the checkout page (which is the first one in Commerce Core), you'd use this hook:

MYMODULE_form_commerce_checkout_form_checkout_alter(&$form, &$form_state) {
  // Make the customer profile billing pane's locality field a bit smaller.
  $form['customer_profile_billing']['commerce_customer_address']['und'][0]['locality_block']['locality']['#size'] = 20;
}

Where commerce_checkout_form_checkout is commerce_checkout_form_ concatenated with the current checkout router step. See commerce_checkout_router(). Each of the panes within the page exists within this form. As Ryan also points out in the comments, the main form traps errors and other items to present them inline with the checkout pane, so a payment error won't show up at the top of the page, but it will show up above the payment pane for instance.

If you're wanting more info on how to theme checkout, I'd recommend you go review the code for Commerce Responsive UI and mimic what it does.

This includes the complete pane which is still a form. If you want to override the form completely, you can just change the callback that is called when the completion pane is being built:

/**
 * Implements hook_commerce_checkout_pane_info_alter().
 */
function MYMODULE_commerce_checkout_pane_info_alter(&$checkout_panes) {           
  $checkout_panes['checkout_completion_message']['callbacks']['checkout_form'] = 'MYMODULE_completion';
}

Then, you put your own output into the new callback. Just copy what commerce_checkout_completion_message_pane_checkout_form() does and put your own content in.

| improve this answer | |
  • just tried your hook alter. I did a dsm($form) and it only shows up on pages with a form. I mainly want to theme the checkout complete panes, which are just text and has no forms as shown above. – Patoshi パトシ Nov 9 '15 at 2:56
  • 1
    Ah. Okay. Well the same information applies, but there is likely a slightly better way to handle it if you're wanting to change the completion pane. See the update. – nvahalik Nov 9 '15 at 3:41
  • nope still doesnt work. i put in a dsm($checkout_panes) in hook_commerce_checkout_pane_info_alte and it doesnt show up on the checkout complete page. however it does show up on every other checkout page. so that isn't the right hook im guessing. – Patoshi パトシ Nov 9 '15 at 5:34
  • Checkout complete is checkout/_id_/complete, on your site right? – nvahalik Nov 9 '15 at 12:00
  • 1
    The reason you aren't seeing the dsm() on the checkout page is because the checkout form traps messages to present them inline with their checkout panes. If you're creating a message outside of the context of a checkout pane, it would make sense for it to be "lost" and not appear on the page as expected. In those cases, I just write my debug output to watchdog(). – Ryan Szrama Nov 9 '15 at 14:55
0

Here's an example to modify the output of the commerce_payment review pane:

/**
 * Implements hook_commerce_checkout_pane_info_alter().
 */
function MYMODULE_commerce_checkout_pane_info_alter(&$checkout_pane) {
  $checkout_pane['commerce_payment']['callbacks']['review'] = 'MYMODULE_commerce_payment_pane_review';
}

/**
 * Replacement callback function for the commerce_payment review pane.
 */
function MYMODULE_commerce_payment_pane_review($form, $form_state, $checkout_pane, $order) {
  module_load_include('inc', 'commerce_payment', 'includes/commerce_payment.checkout_pane');
  $html = commerce_payment_pane_review($form, $form_state, $checkout_pane, $order);
  // Add our custom HTML, could use theme() here to be nice.
  return $html . "<p>More data here...</p>";
}
| improve this answer | |

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.