0

I want to remove the selected Payment Method on page reload (or) load in checkout page(FrontEnd).

6
  • How about disable from admin area? Nov 1, 2018 at 5:47
  • Please describe your question. Nov 1, 2018 at 5:47
  • Please explain what you're trying to do?
    – Haim
    Nov 1, 2018 at 5:53
  • use javascript to hide selected payment method on page load
    – B.K
    Nov 1, 2018 at 5:57
  • But , its throws Cannot read property 'push' of undefined
    – Mahi M
    Nov 1, 2018 at 6:16

2 Answers 2

1

try this code.

add events.xml in Vendor\Module\etc\

<event name="payment_method_is_active">
    <observer name="hide-payment-method" instance="Vendor\Module\Observer\Paymentactive" />
</event>

and in Paymentactive.php observer add this code.

public function execute(\Magento\Framework\Event\Observer $observer) {

    $method = $observer->getEvent()->getMethodInstance();
    $result = $observer->getEvent()->getResult();
    $paymentCode = $method->getCode();
    if ($paymentCode == 'your_method_code') {
        return $result->setData('is_available', false); //hide method

    }
    return $result->setData('is_available', true);

}

Hope this will help you.

0
 // Remove selected payment method on page onload
            initialize: function () {
                var deferred = $.Deferred();

                //Remove selected payment method from quote
                quote.setPaymentMethod(null);
                //Remove selected payment method from localstorage
                checkoutData.setSelectedPaymentMethod(null);
                //Refresh payment section
                getPaymentInformation(deferred);

                var self = this;
                this._super();
            },
1
  • Do you know how to remove loader when selecting payment method? Jan 17, 2020 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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