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.
Ravi says:
Awesome ….Its Help for me …..Thank You!
Axel says:
Yeah ! Super cool. Thanks for your work