Magento – How to remove Quantity input box and Delete button for Free cart items

created August 8, 2011, last updated August 8, 2011.

.
closeThis post was last updated 12 years 7 months 15 days ago, some of the information contained here may no longer be actual and any referenced software versions may have been updated!

For Magento 1.4.x  +

BuyXGetYFree items are added and removed automatically by the extension cartcontroller code. To prevent customers from manually deleting free products from the cart we can change the template to remove the delete button and input qty box for items in the cart with a Zero value.

This code is based on the default Magento theme template.

Remove Delete Button

Open the following template file for editing:

app/design/frontend/base/YOURTHEME/template/checkout/cart/item/default.phtml

Search for “Remove item” in the default theme appears on line 243.

Replace

<td class="a-center"><a href="<?php echo $this->getDeleteUrl() ?>" title="<?php echo $this->__('Remove item')?>" class="btn-remove btn-remove2"><?php echo $this->__('Remove item')?></a></td>

With

<?php if ($_item->getCalculationPrice()=='0'): ?>
<td class="a-center"></td>
<?php else: ?>
<td class="a-center"><a href="<?php echo $this->getDeleteUrl()?>" title="<?php echo $this->__('Remove item')?>" class="btn-remove btn-remove2"><?php echo $this->__('Remove item')?></a></td>
 <?php endif; ?>

Remove Qty input Box

Search for “input-text qty”, in the default theme appears on line 156.

Replace

<input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" />

With

<?php if ($_item->getCalculationPrice()=='0'): ?>
<?php echo $this->getQty() ?>
<?php else: ?>
<input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" />
<?php endif; ?>

Refresh cache, and reload cart to test, free items should no longer have a delete button or input quantity box.

Remove delete button and quantity input box for free cart items
Remove delete button and quantity input box for free cart items

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.