Small addition tip to make it work
form_alter of $form['quantity']['#title'] is altered in another commerce module already. Depending on the weight of the modules your form_alter may get overwritten so the solution is to run it after the form has been built.
This is where the After Build function comes in handy. It allows you to modify the form after the form is built and all the form_alter's have been run. Here is a simple code snippet on how to change the text.
function modulename_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state, $form_id) {
$line_item = $form_state['line_item'];
$product = commerce_product_load($line_item->commerce_product[LANGUAGE_NONE][0]['product_id']);
if ($product->type == '') {
// Change the submit button text to more appropriate "Pay now"
$form['submit']['#value'] = t('Pay Now');
$form['#after_build'][] = 'modulename_after_build';
}
}
function modulename_after_build($form, &$form_state) {
// Change the quantity title text to more appropriate "Enter your quanties"
$form['quantity']['#title'] = t('Enter your quanties');
return $form;
}
Comments
Thanks Ryan but
I've tried change Add To Cart text and Quantity Label using randy fay snippet on previous posting:
function commerce_installments_form_commerce_cart_add_to_cart_form_alter(&$form, &$form_state) {
$line_item = $form_state['line_item'];
$product = commerce_product_load($line_item->commerce_product[LANGUAGE_NONE][0]['product_id']);
if ($product->type == 'containere') {
// Change the submit button text to more appropriate "Pay now"
$form['submit']['#value'] = t('Tilføj til vogn');
$form['quantity']['#title'] = t('Vælg ant. containere');
}
}
Add to Cart text successfully changed but 'Enter Quantity' text not change?
What did I miss?