What is the easiest way to change the Add to cart form button text to something custom? I want to change the text only on certain product types. How should I approach this?
2 Answers
Take help of hook_form_alter. Get the ID of the form for the product display where you are trying to change the text & do something like this --
function MYMODULE_form_alter(&$form, &$form_state, $form_id){//replace your module name with MYMODULE
if(strpos($form_id, 'commerce-cart-add-to-cart-form-65') !== false){//my form ID is "commerce-cart-add-to-cart-form-65", replace it with your form ID.
$form['submit']['#value'] = t('Check Out');//Put the text which you want to make appear instead of "Add to cart".
}
}
I also have several product display with custom text for "Add to cart". It took some time for me figure out the easy way. Have Fun :)
-
I'm using a Bootstrap module and I found this changed the class of the button from "btn-success" to "btn-default". I can't explain why but it is 100% repeatable :/– CraigCommented Nov 24, 2013 at 21:23
The module works great.stringoverrrides
-
This will change it site wide. OP wants to do it for just a certain product type. Commented Aug 10, 2013 at 14:20