- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @stojanovicef91
Please follow the steps below to show the applied cart rules on each product in the cart/minicart in Magento 2:
- Please create a custom module or use an existing one to override the vendor/magento/module-checkout/view/frontend/templates/cart/item/default.phtml template file.
- Please copy the default.phtml file to your module's template directory, which should be located at app/code/[Vendor]/[Module]/view/frontend/templates/cart/item/default.phtml.
- Please find the following code in the default.phtml file:
<span class="price"> <?= /* @escapeNotVerified */ $block->getItemPrice($_item) ?> </span>
- Please replace it with the following code to display the applied cart rules for the item:
<?php $quote = $block->getQuote(); $cartRules = $quote->getAppliedCartRules($_item); ?> <span class="price"> <?= /* @escapeNotVerified */ $block->getItemPrice($_item) ?> </span> <?php if (!empty($cartRules)): ?> <div class="applied-rules"> <ul> <?php foreach ($cartRules as $rule): ?> <li><?= $rule->getName() ?></li> <?php endforeach; ?> </ul> </div> <?php endif; ?>
- Please save the file and clear the Magento cache.
This code retrieves the quote object, which contains the applied cart rules, and displays them in a list below the item price. If there are no cart rules applied to the item, the list will not be displayed.
If you find our reply helpful, please give us kudos.
A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.
WebDesk Solution Support Team
Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789
Thank You,
WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789
Location: 150 King St. W. Toronto, ON M5H 1J9
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello @stojanovicef91
Please follow the steps below to show the applied cart rules on each product in the cart/minicart in Magento 2:
- Please create a custom module or use an existing one to override the vendor/magento/module-checkout/view/frontend/templates/cart/item/default.phtml template file.
- Please copy the default.phtml file to your module's template directory, which should be located at app/code/[Vendor]/[Module]/view/frontend/templates/cart/item/default.phtml.
- Please find the following code in the default.phtml file:
<span class="price"> <?= /* @escapeNotVerified */ $block->getItemPrice($_item) ?> </span>
- Please replace it with the following code to display the applied cart rules for the item:
<?php $quote = $block->getQuote(); $cartRules = $quote->getAppliedCartRules($_item); ?> <span class="price"> <?= /* @escapeNotVerified */ $block->getItemPrice($_item) ?> </span> <?php if (!empty($cartRules)): ?> <div class="applied-rules"> <ul> <?php foreach ($cartRules as $rule): ?> <li><?= $rule->getName() ?></li> <?php endforeach; ?> </ul> </div> <?php endif; ?>
- Please save the file and clear the Magento cache.
This code retrieves the quote object, which contains the applied cart rules, and displays them in a list below the item price. If there are no cart rules applied to the item, the list will not be displayed.
If you find our reply helpful, please give us kudos.
A Leading Magento Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation.
WebDesk Solution Support Team
Get a Free Quote | | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789
Thank You,
WebDesk Solution Support Team
Get a Free Quote | Email | Adobe Commerce Partner | Hire Us | Call Us 877.536.3789
Location: 150 King St. W. Toronto, ON M5H 1J9