How to Reorder “Display Prices” Including and Excluding Taxes on Mini Cart in Magento 2
Earlier, I posted the solution to display prices including and excluding taxes on the catalog page in Magento 2.
The purpose of it was dependent on the pricing strategy of the store. If you want to lure the customers with prices, you can use the default setting to display the prices excluding the tax and if you want to be upfront with customers regarding the prices, show it including the taxes.
The default Magento 2 also offers an option to show both the prices. However, you can change the sequence of the price display on the frontend according to your theme, design, and customer behaviour study.
You can reorder display prices including and excluding taxes on mini cart in Magento 2 with the below stepwise solution.
Mini cart and cart page must be designed carefully so as to reduce the abandoned cart rate and these steps might just be helpful to you!
Steps to Reorder Display Prices Including And Excluding Taxes on Mini Cart in Magento 2:
- Login to admin panel
- Navigate to Store > configuration > Sales > Tax > Price Display Settings and select “including excluding tax” on Display Product Prices In Catalog.
- Override sidebar.phtml file into app/design/frontend/[Namespace]/[theme]/Magento_Weee/templates/checkout/cart/item/price
- And replace the default code with:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788<?php/*** Copyright © Magento, Inc. All rights reserved.* See COPYING.txt for license details.*/// phpcs:disable Magento2.Templates.ThisInTemplate/** @var $block \Magento\Weee\Block\Item\Price\Renderer */$item = $block->getItem();// ensure we use the zone for the shopping cart / minicart$originalZone = $block->getZone();$block->setZone(\Magento\Framework\Pricing\Render::ZONE_CART);?><?php if ($block->displayPriceExclTax() || $block->displayBothPrices()) : ?><span class="price-excluding-tax" data-label="<?= $block->escapeHtmlAttr(__('Excl. Tax')) ?>"><?php if ($block->displayPriceWithWeeeDetails()) : ?><span class="minicart-tax-total"><?php else : ?><span class="minicart-price"><?php endif; ?><?= /* @noEscape */$block->formatPrice($block->getUnitDisplayPriceExclTax()) ?></span><?php if ($block->displayPriceWithWeeeDetails()) : ?><?php if ($this->helper(\Magento\Weee\Helper\Data::class)->getApplied($item)) : ?><span class="minicart-tax-info"><?php foreach ($this->helper(\Magento\Weee\Helper\Data::class)->getApplied($item) as $tax) : ?><span class="weee" data-label="<?= $block->escapeHtmlAttr($tax['title']) ?>"><?= /* @noEscape */$block->formatPrice($tax['amount'], true, true) ?></span><?php endforeach; ?></span><?php if ($block->displayFinalPrice()) : ?><span class="minicart-tax-total"><span class="weee" data-label="<?= $block->escapeHtmlAttr(__('Total')) ?>"><?= /* @noEscape */$block->formatPrice($block->getFinalUnitDisplayPriceExclTax()) ?></span></span><?php endif; ?><?php endif; ?><?php endif; ?></span><?php endif; ?><?php if ($block->displayPriceInclTax() || $block->displayBothPrices()) : ?><span class="price-including-tax" data-label="<?= $block->escapeHtmlAttr(__('Incl. Tax')) ?>"><?php if ($block->displayPriceWithWeeeDetails()) : ?><span class="minicart-tax-total"><?php else : ?><span class="minicart-price"><?php endif; ?><?= /* @noEscape */$block->formatPrice($block->getUnitDisplayPriceInclTax()) ?></span><?php if ($block->displayPriceWithWeeeDetails()) : ?><?php if ($this->helper(\Magento\Weee\Helper\Data::class)->getApplied($item)) : ?><span class="minicart-tax-info"><?php foreach ($this->helper(\Magento\Weee\Helper\Data::class)->getApplied($item) as $tax) : ?><span class="weee" data-label="<?= $block->escapeHtmlAttr($tax['title']) ?>"><?= /* @noEscape */$block->formatPrice($tax['amount_incl_tax'], true, true) ?></span><?php endforeach; ?></span><?php if ($block->displayFinalPrice()) : ?><span class="minicart-tax-total"><span class="weee" data-label="<?= $block->escapeHtmlAttr(__('Total Incl. Tax')) ?>"><?= /* @noEscape */$block->formatPrice($block->getFinalUnitDisplayPriceInclTax()) ?></span></span><?php endif; ?><?php endif; ?><?php endif; ?></span><?php endif; ?><?php $block->setZone($originalZone); ?>
That’s it.
After implementing the above code, you can change the sequence of display prices in mini cart as shown below:
Case 1:
Case 2:
Any doubts about the method can be mentioned in the Comments section below. I’d be glad to help you out.
Also, do share the post with the Magento community via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How to Reorder “Display Prices” Including and Excluding Taxes on Category Page in Magento 2
How To Create Bundle Products in Magento 2
Next