{"id":448,"date":"2019-05-28T06:24:26","date_gmt":"2019-05-28T06:24:26","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/05\/28\/solution-discount-based-on-payment-method-not-showing-in-magento-2-cart-total\/"},"modified":"2025-05-22T16:48:54","modified_gmt":"2025-05-22T11:18:54","slug":"solution-discount-based-on-payment-method-not-showing-in-magento-2-cart-total","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/solution-discount-based-on-payment-method-not-showing-in-magento-2-cart-total\/","title":{"rendered":"Solution: Discount Based on Payment Method Not Showing in Magento 2 Cart Total"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Offering discounts may seem to be a concern for the profit of the business. But, implementing it effectively leads to brand recognization, attract new customers and win customer loyalty.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u201cEmployed thoughtfully, discounts can give sales a healthy boost; handled incorrectly, they can devalue and detract from the bottom line.\u201d<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Talking about the discounts, it is important that customers acknowledge that they are offered the discount! However, for Magento 2 stores, there is sometimes an issue of&nbsp;<em><strong>discount based on payment method not showing in Magento 2 cart total<\/strong><\/em>&nbsp;. To address this issue, one can&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/make-a-payment-method-visible-only-to-admin-in-magento-2\/\">make a payment method visible only to admin<\/a>&nbsp;and offer the discount through that payment method, ensuring that only the admin can apply the discount to the customer\u2019s order. This way, the discount will be displayed in the cart total for the customer to see, and they can benefit from the discount while still maintaining a smooth checkout experience. So if you are offering multiple payment option and you want to redirect your customers to one particular payment method encourage them by giving&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/give-discount-on-payment-methods-in-magento-2\/\">Magento 2 discount on payment methods<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the order summary does not reflect the discount calculation in the cart, how are you ever going to leverage the benefits of discounts?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The discount is applied but does not show in the cart. It may lead to the confusion for the customer as to whether he benefitted from using a particular payment method or not? Such confusions result in an abandoned cart. Surely, we don\u2019t want that and hence implement the solution given below!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Also, you can download package of the below solution directly from&nbsp;<a href=\"https:\/\/github.com\/MeetanshiInc\/Solution-Discount-Based-on-Payment-Method-Not-Showing-in-Magento-2-Cart-Total\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solution: Discount Based on Payment Method Not Showing in Magento 2 Cart Total<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<strong>registration.php<\/strong>&nbsp;file at&nbsp;<em><strong><em><strong>app\\code\\Meetanshi\\Fixpaymentrule<\/strong><\/em>&nbsp;<\/strong><\/em>directory<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n    \\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n    'Meetanshi_Fixpaymentrule',\n    __DIR__\n);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create&nbsp;<strong>module.xml<\/strong>&nbsp; at&nbsp;<em><strong><em><strong>app\\code\\Meetanshi\\Fixpaymentrule\\etc<\/strong><\/em>&nbsp;<\/strong><\/em>directory<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"..\/..\/..\/..\/..\/vendor\/magento\/framework\/Module\/etc\/module.xsd\">\n    &lt;module name=\"Meetanshi_Fixpaymentrule\" setup_version=\"1.0.0\">\n        &lt;sequence>\n            &lt;module name=\"Magento_Rule\"\/>\n        &lt;\/sequence>\n    &lt;\/module>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Create&nbsp;<strong>routes.xml<\/strong>&nbsp; at&nbsp;<em><strong><em><strong>app\\code\\Meetanshi\\Fixpaymentrule\\etc\\frontend<\/strong><\/em>&nbsp;<\/strong><\/em>directory<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:App\/etc\/routes.xsd\">\n    &lt;router id=\"standard\">\n        &lt;route id=\"Meetanshi_Fixpaymentrule\" frontName=\"fixpaymentrule\">\n            &lt;module name=\"Meetanshi_Fixpaymentrule\"\/>\n        &lt;\/route>\n    &lt;\/router>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4. Create&nbsp;<strong>ApplyPaymentMethod.php<\/strong>&nbsp;at&nbsp; <em><strong><em><strong>app\\code\\Meetanshi\\Fixpaymentrule\\Controller\\Checkout<\/strong><\/em>&nbsp;<\/strong><\/em>directory<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Meetanshi\\Fixpaymentrule\\Controller\\Checkout;\n\nuse Magento\\Framework\\App\\Action\\Context;\nuse Magento\\Framework\\Controller\\Result\\ForwardFactory;\nuse Magento\\Framework\\View\\LayoutFactory;\nuse Magento\\Checkout\\Model\\Cart;\nuse Magento\\Framework\\App\\Action\\Action;\n\nclass ApplyPaymentMethod extends Action\n{\n    protected $resultForwardFactory;\n    protected $layoutFactory;\n    protected $cart;\n\n    public function __construct(\n        Context $context,\n        ForwardFactory $resultForwardFactory,\n        LayoutFactory $layoutFactory,\n        Cart $cart\n    )\n    {\n        $this->resultForwardFactory = $resultForwardFactory;\n        $this->layoutFactory = $layoutFactory;\n        $this->cart = $cart;\n\n        parent::__construct($context);\n    }\n\n    public function execute()\n    {\n        $pMethod = $this->getRequest()->getParam('payment_method');\n        $quote = $this->cart->getQuote();\n        $quote->getPayment()->setMethod($pMethod['method']);\n        $quote->setTotalsCollectedFlag(false);\n        $quote->collectTotals();\n        $quote->save();\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">5. Create&nbsp;<strong>requirejs-config.js<\/strong>&nbsp; at&nbsp; <em><strong><em><strong>app\\code\\Meetanshi\\Fixpaymentrule\\view\\frontend<\/strong><\/em>&nbsp;<\/strong><\/em>directory<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">var config = {\n    map: {\n        '*': {\n            'Magento_Checkout\/js\/action\/select-payment-method':\n                'Meetanshi_Fixpaymentrule\/js\/action\/select-payment-method'\n        }\n    }\n};<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">6. Create&nbsp;<strong>select-payment-method.js<\/strong>&nbsp;at&nbsp; <em><strong><em><strong>app\\code\\Meetanshi\\Fixpaymentrule\\view\\frontend\\web\\js\\action<\/strong><\/em>&nbsp;<\/strong><\/em>directory<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">define(\n    [\n        'Magento_Checkout\/js\/model\/quote',\n        'Magento_Checkout\/js\/model\/full-screen-loader',\n        'jquery',\n        'Magento_Checkout\/js\/action\/get-totals',\n        'mage\/url',\n    ],\n    function (quote, fullScreenLoader, jQuery, getTotalsAction,url) {\n        'use strict';\n        return function (paymentMethod) {\n            quote.paymentMethod(paymentMethod);\n\n            fullScreenLoader.startLoader();\n\n            var linkUrl = url.build('fixpaymentrule\/checkout\/applyPaymentMethod');\n            jQuery.ajax(linkUrl, {\n                data: {payment_method: paymentMethod},\n                complete: function () {\n                    getTotalsAction([]);\n                    fullScreenLoader.stopLoader();\n                }\n            });\n\n        }\n    }\n);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With the above solution, if you offer a payment method based discount, it will always show the calculations clearly in the cart total, leaving no room for any confusions! If you can also solve&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/solved-magento-2-navigation-menu-not-showing\/\">Magento 2 navigation menu not showing<\/a>&nbsp;error, as top navigation menu makes it easy for visitors to navigate through the Magento 2 store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Offering discounts may seem to be a concern for the profit of the business. But, implementing it effectively leads to brand recognization, attract new customers&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-448","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=448"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/448\/revisions"}],"predecessor-version":[{"id":15406,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/448\/revisions\/15406"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}