4

How can I change the text of the "checkout" button in Drupal commerce cart?

I need it to be "continue" instead.

thanks

enter image description here

   function rooms_form_alter(&$form, &$form_state, $form_id) {  
      dsm($form_id);  // print form ID to messages
      switch ($form_id){
            case 'views_form_commerce_cart_form_default':
                $action['#value'] = 'continue';
            break;
      }
    }
3

Try using the string overrides module - http://drupal.org/project/stringoverrides

If you can get it to work, it is a great maintainable way to change text generated by modules

  • I will definitely try it. Looks good. – chefnelone Feb 28 '12 at 20:25
3

By using the hook_form_alter() function, you can change the text of the buttons. It would be something like

$action['#value'] = 'continue';

Please provide us with more code so I can work out a decent example.

  • I didn't use hook_form_alter() before. I will try it – chefnelone Feb 28 '12 at 10:43
  • I tried with the code I added at the bottom of my question. But not working. What am I missing? – chefnelone Feb 28 '12 at 16:43
  • Your form ID. What's your form ID? Also, the $action['#value'] was just an example. You have to figure out your own structure via var_dump – Michiel Feb 28 '12 at 16:50
  • the form id is 'views_form_commerce_cart_form_default'. – chefnelone Feb 28 '12 at 16:57
1

You could be interested in the Commerce Checkout Buttons module.

The Commerce Checkout Buttons module enables the use of shorter button values ​​on Drupal Commerce checkout pages.

What exactly does the module?

  • All default ​​button values to be shortened to the shortest meaningful text.
    Texts that are used:

    • Cancel at the first checkout step.
    • Back for further checkout steps.
    • Continue at all checkout steps.
  • The button prefix or will be removed.

1

Based on my answer to Customize commerce cart form page, here's the section specific to the checkout button:

function yourthemename_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id)  {
  case 'views_form_commerce_cart_form_default': 

    $form['actions']['checkout']['#value'] = 'New checkout button label';

  break;
  }
}

See that above linked answer for the rest of the form!

0

I am very new to drupal and I had the almost the same problem. I have to change the value of the checkout button and to make it translatable up to which language is selected. I tried different approaches but without any success.

I create a custom module with this function.

function md_custom_checkout_mod_form_commerce_checkout_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'commerce-checkout-form-checkout') {
    $form['submit']['#attributes']['title'] = t('Complete order');
  }
}

function md_custom_checkout_mod_form_commerce_checkout_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'commerce-checkout-form-checkout') {
    $form['submit']['#attributes']['title'] = t('Complete order');
  }
}

Please can you give me some tips how to make this working.

  • Looks like you're also very new to using this site (bien venue!)... Please use the "Ask a question" button, instead of "posting an answer" to an existing question ... FYI: it's free ... – Pierre.Vriens Feb 22 '17 at 13:54
-1

//exact code goes here

/*
I have also removed the update cart button here as I dont need you, you must have that code if you want it.
*/


function modulename_form_alter(&$form, &$form_state, $form_id) {

  if (strpos($form_id, 'views_form_commerce_cart_form_') === 0) {

    // Only alter buttons if the cart form View shows line items.

    $view = reset($form_state['build_info']['args']);

    if (!empty($view->result)) {


      // Unset update cart button as we dont need it.
      unset($form['actions']['submit']);

      //Change the name of checkout to - Delivery
       $form['actions']['checkout']['#value'] = t('Delivery');     
       $form['actions']['checkout']['#submit'] = array('memento_checkout_form_submit');

      // Change any Delete buttons to say Remove.
      if (!empty($form['edit_delete'])) {
        foreach (element_children($form['edit_delete']) as $key) {
          // Load and wrap the line item to have the title in the submit phase.
          if (!empty($form['edit_delete'][$key]['#line_item_id'])) {
            $line_item_id = $form['edit_delete'][$key]['#line_item_id'];
            $form_state['line_items'][$line_item_id] = commerce_line_item_load($line_item_id);

            $form['edit_delete'][$key]['#value'] = t('Remove');
            $form['edit_delete'][$key]['#submit'] = array_merge($form['#submit'], array('commerce_cart_line_item_delete_form_submit'));
          }
        }
      }

    }
    else {
      // Otherwise go ahead and remove any buttons from the View.
      unset($form['actions']);
    }
  }  
}

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.