1

On the first checkout page (checkout/xx/checkout), there is a view which displays line items for the order. The view appears to be named "Shopping cart summary (Commerce Order)"

When I add the standard Delete button to the view (for deleting line items), it causes a Save button to appear below the line items.

How do I remove that Save button?

Update:

I tried a form-specific hook_form_alter(), but didn't find the Save button in the $form array. It appears to be a form embedded in another form. Reading answer from @Yogesh made me realize that maybe I had the wrong $form_id and can debug with a general hook_form_alter() and look for a nested call for the embedded form.

1 Answer 1

4

One way of doing this is implementing hook_form_alter and hiding save button. Check example below:

function [MODULE_NAME]_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id = 'YOUR_FORM_ID') {
    // Set access to FALSE will prevent rendering form element on form.
    // Check the hierarchy of 'Save' button, before using #access.
    $form['actions']['save']['#access'] = FALSE;
  }
}
3
  • I tried this with a form_alter hook that I thought was specific to the form and couldn't find the button in the $form array. It appears to be a form embedded in another form. Maybe I should try a general form_alter hook in case I had the wrong $form_id.
    – kentr
    Oct 26, 2016 at 18:01
  • Specifically, the form to alter is views_form_commerce_cart_summary_default, and the element to alter is $form['actions']['submit']. It's embedded into the parent form (commerce_checkout_form_checkout) as rendered markup.
    – kentr
    Oct 26, 2016 at 23:07
  • I had $form['actions']['submit']['#access'], so submit instead of save (maybe because I'm using the workflow module) Feb 27, 2017 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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