0

In Magento 2.3.3 Commerce I want to use the Store credit for backend only.

How to disable Store Credit option from the checkout page?

7
  • Hi Adarsh, did you get any solution for this?
    – Abhishek
    Feb 9 at 11:51
  • No, I am hiding it from CSS atm. Let me know if you find the solution. Feb 9 at 23:46
  • Yes I got solution for it. This block is managed by Knockout JS so I override JS and HTML files in my Theme and added a condition so this block is not appear on checkout page.
    – Abhishek
    Feb 10 at 5:39
  • I was more interested in other solutions than overriding the files. Feb 11 at 1:01
  • Hi Adarsh, Please check my answer for new approach. I hope it will help you.
    – Abhishek
    Feb 19 at 8:25
1

Magento use LayoutProcessor to render components on checkout page.

You can remove any block on checkout page using LayoutProcessor in Magento.

I built a plugin to remove Store credit Option

<type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
    <plugin name="remove_store_credit"
        type="Vendor\Module\Plugins\Checkout\GiftCardLayoutProcessor"
        sortOrder="1" 
        disabled="false"/>
</type>

    <?php

namespace Vendor\GiftCard\Plugins\Checkout;

use Magento\Checkout\Block\Checkout\LayoutProcessor;

class GiftCardLayoutProcessor
{
    public function afterProcess(LayoutProcessor $subject, $result)
    {
        // hide shipping address component
        unset(
            $result['components']['checkout']['children']['steps']['children']
            ['shipping-step']['children']['shippingAddress']
        );
        // hide store credit component
        unset(
            $result['components']['checkout']['children']['steps']['children']
                    ['billing-step']['children']['payment']['children']
                    ['beforeMethods']['children']['storeCredit']
        );
        return $result;
    }
}

Please follow this link: https://devdocs.magento.com/guides/v2.4/howdoi/checkout/checkout_customize.html

I tried example mentioned there but it was not working for me so I created a plugin to customize layoutprocessor.

0

After working on removing store credit in checkout and finding the above examples not working I dug into the problem and found at least on version 2.4.1 the solution is to use "afterMethods" instead of "beforeMethods".

I do not know which version changed this, but referencing the layout XML from the vendor directory we can see line: 22 references "afterMethods":

vendor/magento/module-customer-balance/view/frontend/layout/checkout_index_index.xml

To implement into your module do the following, create the file:

app\code\Vendor\YourModulePackageName\view\frontend\layout\checkout_index_index.xml

Paste this in as the contents of your modules checkout_index_index.xml:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.root">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="checkout" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="billing-step" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="payment" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="afterMethods" xsi:type="array">
                                                            <item name="children" xsi:type="array">
                                                                <item name="storeCredit" xsi:type="array">
                                                                    <item name="config" xsi:type="array">
                                                                        <item name="componentDisabled" xsi:type="boolean">true</item>
                                                                    </item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

Hope this helps someone!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.