5

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;
      }
    }

8 Answers 8

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

1
  • I will definitely try it. Looks good.
    – chefnelone
    Commented Feb 28, 2012 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.

4
  • I didn't use hook_form_alter() before. I will try it
    – chefnelone
    Commented Feb 28, 2012 at 10:43
  • I tried with the code I added at the bottom of my question. But not working. What am I missing?
    – chefnelone
    Commented Feb 28, 2012 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
    Commented Feb 28, 2012 at 16:50
  • the form id is 'views_form_commerce_cart_form_default'.
    – chefnelone
    Commented Feb 28, 2012 at 16:57
2

In Drupal Commerce 8 on, the hook_form_alter() might not be able to catch the "Checkout" button, because the button is implemented in commerce_checkout_form_alter() in /commerce/modules/checkout/commerce_checkout.module. So, depends on the name of your custom module, your custom hook_form_alter() might get called before commerce_checkout.

To make sure your custom module can see the "Checkout" button, go to your configuration: config/sync/core.extension.yml, lower your custom module weight, e.g. custom_module: 1. The number 1 is the weight of the module; bigger number means that module will get loaded/called later.

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.

1
  • 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 ... Commented Feb 22, 2017 at 13:54
0

In Drupal 8 / Commerce 2, you can add a string override to your settings.php file, as such:

/**
 * String overrides:
 *
 * To override specific strings on your site with or without enabling the Locale
 * module, add an entry to this list. This functionality allows you to change
 * a small number of your site's default English language interface strings.
 *
 * Remove the leading hash signs to enable.
 *
 * The "en" part of the variable name, is dynamic and can be any langcode of
 * any added language. (eg locale_custom_strings_de for german).
 */
# $settings['locale_custom_strings_en'][''] = [
#   'forum'      => 'Discussion board',
#   '@count min' => '@count minutes',
# ];

 $settings['locale_custom_strings_en'][''] = [
   'Checkout'      => 'CHECKOUT or GET QUOTE',
 ];

Specifically, this part:

 $settings['locale_custom_strings_en'][''] = [
   'Checkout'      => 'CHECKOUT or GET QUOTE',
 ];
-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 and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.