How to Check Which Shopping Cart Rule is Applied to Cart in Magento
The default Magento allows the admin to add shopping cart price rules.
He can offer coupon codes to avail the discounts.
However, sometimes you may want to set conditions based on which discounts are offered.
For example, the admin wants to offer a specific payment method only for certain scenarios.
To implement this, the admin needs to check which shopping cart rule is applied to cart in Magento.
The below solution can be used for the same:
Method to Check Which Shopping Cart Rule is Applied to Cart in Magento:
Add the below code.
1 2 3 |
$appliedRuleIds = Mage::getSingleton('checkout/session')->getQuote()->getAppliedRuleIds(); $appliedRuleIds = explode(',', $appliedRuleIds); print_r($appliedRuleIds); |
By adding this code, you will be able to check which shopping cart price rule has applied to quote.
That’s it.
If you have queries regarding this post, feel free to ask in the Comment section below.
I would be happy to answer your questions.
Thank you.
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
How to Add Dynamic Field in Magento 2 Admin Using system.xml
How to Add Custom Block in Admin Sales Order View in Magento 2
Next