Discussions

Checkout pane titles

I am trying to understand how I can alter the titles of the checkout panes and the text displayed in the various checkout form buttons. I can use string overrides but that changes both the button and the title text.

I have tried hook_form_alter in a custom module but that does nothing so I assume there is a commerce function to handle this?

What would I need to do starting from something like this...

<?php

/**
* Implementation of hook_form_alter().
*/
function MY_FUNCTION_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#id'] == 'views-form_commerce_cart_form_default') {
    $form['submit']['#value'] = t('Continue');
  }
}

Some example code would be very useful if anyone is able to provide it. I am not a competent coder by any means, so treat me gently please!

Thanks

Posted: Feb 8, 2012

Comments

Nick Kendall on May 19, 2014

The button titles are hard-coded into the Commerce Checkout module. The simplest approach is with the hook_form_alter() function. This can be applied in two ways: 1) a custom module; 2) editing the the theme for your drupal site (since this is a design issue, rather than functionality).

I have applied the following code to the bartik theme (NB if you switch themes you'll need to copy the code over to the newly enabled theme).

function bartik_form_alter(&$form, &$form_state, $form_id){
// dpm($form_id);
// dpm($form);
if (commerce_form_callback($form_id, $form_state) == "commerce_cart_add_to_cart_form"){
$form['submit']['#attributes']['title'] = $form['submit']['#attributes']['value']=t("Add to Inquiry List");
}
if(strpos($form_id, 'views_form_commerce_cart_form_default')===0){
$form['actions']['submit']['#value'] = t("Update List");
$form['actions']['checkout']['#value'] = t("Submit List");

}

}

This code is at the bottom of my bartik theme template. What it does is change the hard-coded values for the buttons to the text that works semantically with my site. You'll notice that I had to call modifications to two different forms within the general form_alter() function. This code changes the text of the 'Add to Cart', 'update cart', and 'checkout' buttons. I have the dpm statements commented out, but if you un-comment them they will show you all the form ids on your page, and them the contents of those forms. You then have to poke around to find the values you want to change.

There is a good video by the Commerce Guys, which will get your head straight about using the Devel module to identify the forms you want to change http://www.youtube.com/watch?v=xYMd6WDqxKY

If you wanted to do this through a module, you could as well, but there's plenty of documentation on how to write and implement one elsewhere.

I'm still working on how to change the pane titles, but this should get you started.

Nick Kendall on May 20, 2014

The button titles are hard-coded into the Commerce Checkout module. The simplest approach is with the hook_form_alter() function. This can be applied in two ways: 1) a custom module; 2) editing the the theme for your drupal site (since this is a design issue, rather than functionality).

I have applied the following code to the bartik theme (NB if you switch themes you'll need to copy the code over to the newly enabled theme).

function bartik_form_alter(&$form, &$form_state, $form_id){
// dpm($form_id);
// dpm($form);
if (commerce_form_callback($form_id, $form_state) == "commerce_cart_add_to_cart_form"){
$form['submit']['#attributes']['title'] = $form['submit']['#attributes']['value']=t("Add to Inquiry List");
}
if(strpos($form_id, 'views_form_commerce_cart_form_default')===0){
$form['actions']['submit']['#value'] = t("Update List");
$form['actions']['checkout']['#value'] = t("Submit List");

}

}

This code is at the bottom of my bartik theme template. What it does is change the hard-coded values for the buttons to the text that works semantically with my site. You'll notice that I had to call modifications to two different forms within the general form_alter() function. This code changes the text of the 'Add to Cart', 'update cart', and 'checkout' buttons. I have the dpm statements commented out, but if you un-comment them they will show you all the form ids on your page, and them the contents of those forms. You then have to poke around to find the values you want to change.

There is a good video by the Commerce Guys, which will get your head straight about using the Devel module to identify the forms you want to change http://www.youtube.com/watch?v=xYMd6WDqxKY

If you wanted to do this through a module, you could as well, but there's plenty of documentation on how to write and implement one elsewhere.

I'm still working on how to change the pane titles, but this should get you started.