I want to change the remove-button, that removes line items from the cart to an image button representing a trash can like this:
The code I am using in a custom module looks like this:
<? php
function mymodule_custom_form_views_form_commerce_cart_form_default_alter(&$form, &$form_state, $form_id) {
foreach ($form['edit_delete'] as &$item) {
$item['#type']='image_button';
$item['#src']='sites/all/themes/mytheme/images/trash.svg';
$item['#alt']='Remove';
}
}
That code shows the icon instead of the text as expected, but unfortunately it introduces a major issue: now pressing the button doesn't remove the correponding line item, but wrongly successively removes the last added line-items. So when I added item1, item2, item3 to the cart in this order, then no matter which corresponding remove-button you press, item3 is removed. Next time, you press one of the remove-buttons of the remaining 2 line-items, then item-2 is removed. What's wrong with the above code?