Commerce provides a useful hook to alter checkout page information:

hook_commerce_checkout_page_info_alter

Button text can be set/altered there, as documented in the hook_commerce_checkout_page_info code comments:

back_value:the translatable value of the submit button used for going back in the checkout process; defaults to ‘Back’

An example hook_commerce_checkout_page_info_alter implementation

/**
 * Implements hook_commerce_checkout_pages_alter
 */
MODULE_commerce_checkout_pages_alter(&$checkout_pages){
  $checkout_pages['checkout']['back_value'] = t('Back to cart');
}

However, in commerce_checkout_form the back_value isn't honoured on the "Checkout" page.

The attached minor patch fixes the issue and allows the checkout back_value text to be overridden in hook_commerce_checkout_pages_alter

Comments

davidwhthomas’s picture

The updated patch attached ensures if no back_value is specified in an override on the checkout page (no previous page defined), then the default t('Cancel') text is still used instead.

Supersedes previous.

rszrama’s picture

Category: bug » feature
Status: Needs review » Closed (won't fix)

I believe this is working as designed, though I can update the documentation to make it more clear. Basically, on the first checkout page, there is nowhere to go "back" to, which is why we have a hardcoded "Cancel" button there to exit the checkout process. The correct thing to do here, as far as I can tell, is to use a form alter to turn the cancel button into whatever custom value you want to exit the checkout process. The key takeaway is that Commerce treats the "back" and "cancel" buttons as two distinct things.

I've updated the docs for that parameter: http://drupalcode.org/project/commerce.git/commitdiff/5990837

davidwhthomas’s picture

Thanks Ryan.

There are cases where a developer / client might want to override that text. In my case it was a change to "Back to cart". I suppose it could also be "Continue shopping" or similar.

It would be nice if one could use the same hook_checkout_page_info_alter hook to set that text, but I suppose a hook_form_alter is workable as well.

Cheers,
David

rszrama’s picture

Yeah, let's put it on the roadmap. I'd make a "cancel_value" property, but I'm not sure that really gets us where we need to be. I'll leave a comment about this in relation to checkout form improvements on http://www.drupalcommerce.org/roadmap.