how to disable removed from cart message
How to disable 'removed from cart' Message ?
if disabling add to cart message I just disable from rule, but I can't find it for removed from cart message. thanks
How to disable 'removed from cart' Message ?
if disabling add to cart message I just disable from rule, but I can't find it for removed from cart message. thanks
In case anyone else finds this and needs to accomplish the same thing, I took Ryan's advice and did a form alter and removed that submit handler and it works as expected. If you wanted to change the message you could just unset the submit handler and add your own back in.
<?php
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
// Remove the submit handler.
if($form_id == 'views_form_commerce_cart_form_default') {
foreach($form['edit_delete'] as $id => $delete) {
if(isset($delete['#submit'])) {
foreach($delete['#submit'] as $hid => $handler) {
if($handler == 'commerce_cart_line_item_delete_form_submit') {
unset($form['edit_delete'][$id]['#submit'][$hid]);
}
}
}
}
}
}
?>
Great question - as of Commerce 1.5, this message is not simply "disable-able" via the user interface. While we do use Rules to display the Add to Cart message, no such integration was enabled for the remove message. It is simply set during the remove button submission process and disabled on the following pageload. The main difference here is that while there is a hook and Rules event that is invoked when a product is added to the Cart, the cart removal process is tied specifically to the form and has no corresponding hook / event.
You may be able to do something with the session or perhaps with translation to disable this. Perhaps if that string were translated to an empty string, it wouldn't show? I know that from code, an empty string will simply be ignored by the drupal_set_message() function.
The other solution would be to remove the submit handler from line item delete buttons added in by commerce_cart_form_alter(). You'd have to loop over the delete buttons like that code does and remove any reference in their #submit arrays to commerce_cart_line_item_delete_form_submit, the function that handles displaying the removal message.
Comments
I also wanted to remove the message "Your shopping cart has been updated", and adding the following worked for me:
<?php
foreach($form['actions']['submit']['#submit'] as $hid => $handler) {
if($handler == 'commerce_cart_line_item_views_form_submit') {
unset($form['actions']['submit']['#submit'][$hid]);
}
}
?>