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
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 2046841-commerce-checkout-button-back-value-fix-v2.patch | 1.02 KB | davidwhthomas |
| commerce-checkout-button-back-value-fix.patch | 719 bytes | davidwhthomas |
Comments
Comment #1
davidwhthomas commentedThe updated patch attached ensures if no
back_valueis specified in an override on the checkout page (no previous page defined), then the defaultt('Cancel')text is still used instead.Supersedes previous.
Comment #2
rszrama commentedI 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
Comment #3
davidwhthomas commentedThanks 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_alterhook to set that text, but I suppose ahook_form_alteris workable as well.Cheers,
David
Comment #4
rszrama commentedYeah, 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.