Magento – Magento 2 Custom remove item from cart button

cart-itemsmagento2PHPquoteitemshopping-cart

I am trying to create a custom button to remove items from the shopping cart.

Example of remove button in cart

I've tried the following code <a href="<?php echo $this->getUrl('checkout/cart/delete', array('id' => $this->getProduct()->getId()))?>"> in vendor\magento\module-checkout\view\frontend\templates\cart\item\default.phtml but it doesn't seem to be working.

I must be putting something in the wrong place or not using correct code but I found this on another post.

Just need a point in the right direction

Best Answer

You can simply use in app/design/frontend/Vendor/Themename/Magento_Checkout/templates/cart/item/default.phtml below code.

<a href="#"
           title="<?= $block->escapeHtml(__('Remove item')) ?>"
           class="action action-delete"
           data-post='<?= /* @escapeNotVerified */ $this->helper('Magento\Checkout\Helper\Cart')->getDeletePostJson($_item) ?>'>
            <span>
                <?= /* @escapeNotVerified */ __('Remove item') ?>
            </span>
        </a>
Related Topic