How to Remove Product Price and Subtotal Amount from Shopping Cart Page in Magento 2
As a new developer working with Magento 2, you’re likely looking for ways to customize your shopping cart page experience for your users. In this post, we’ll walk through the steps to remove both the product price and subtotal amount fields from the cart summary section while keeping only the quantity of items.
Understanding the Cart Summary Section
The default Magento 2 cart summary section displays the following information:
- Item quantity
- Item price
- Subtotal line item amount
- Row total line item amount (same as subtotal)
- Product name and SKU
- Price field with tax calculation
Removing Unwanted Fields from Cart Summary
To achieve our goal, we’ll need to override the Magento_Checkout/web/js/view/summary file located in the theme directory.
First, navigate to your theme’s root folder:
app/design/frontend/<vendor>/<theme>
Next, create the following directory structure if it doesn’t exist yet:
/app/design/frontend/<vendor>/<theme>/Magento_Checkout
/app/design/frontend/<vendor>/<theme>/Magento_Checkout/view/frontend/templates
/app/design/frontend/<vendor>/<theme>/Magento_Checkout/view/frontend/web/js/view
Now, copy the summary.html file from your Magento 2 installation:
app/code/Magento/Checkout/view/frontend/templates/summary.html
And paste it into your newly created theme directory:
/app/design/frontend/<vendor>/<theme>/Magento_Checkout/view/frontend/templates
Overriding the cartitem Summary
Open the summary.html file and locate the following <div>:
<div class="cart-item-price">
<span class="cart-price">$<?= $block->escapeHtml(__($item->getRowTotal())); ?></span>
</div>
Delete or comment out this entire <div> section. This will remove both the item price and subtotal amount fields.
Your summary.html file should now look like this:
<div class="cart-item-info">
<strong>
<?= $block->escapeHtml(__($item->getProduct()->getName())) ?> #<?= $block->escapeHtml($item->getSku()) ?>
</strong> - <?=$block->escapeHtml($item->getDescription())?>
</div>
Deploying the Changes
After making your changes, clear Magento 2 cache and then run the following commands to deploy:
rm -rf var/cache/*
rm -rf generated/code
bin/magento setup:upgrade
bin/magento setup:static-content:deploy
Your shopping cart page should now display only the item quantity without any price or subtotal information.
Conclusion
Removing unwanted fields from your Magento 2 shopping cart summary is a straightforward process that involves overriding the base template file. By following this guide, you can easily customize the cart layout to better suit the needs of your e-commerce store.
For more advanced customization techniques and best practices, I recommend checking out our comprehensive Magento 2 development guides at Laravel Company.
Happy coding!