Hello everyone,
I want to enable COD for a particular cart using custom module. Can anyone suggest me, what should i do to achieve this? As i fetched all the available payment methods but unable to set a particular payment method like COD.
Your reply will be hearty appreciated.
Thanks
Solved! Go to Solution.
Hello @Vivek Singh,
You can enable table rate shipping method and you can easily restrict zip code within in it. Please refer this link https://docs.magento.com/m1/ce/user_guide/shipping/table-rates.html
--
If my answer is useful, please Accept as Solution & give Kudos
Hi @Vivek Singh
Here i would say you required to write down your custom module as an Plugin.
Create a custom plugin and check for the conditions and based on that you can enable/disable your payment method.
Below i am sharing the url links for the same
https://magento.stackexchange.com/questions/180422/magento-2-payment-methods-hide-by-code
Hope it helps!
Hello @Vivek Singh,
First you will need to create events.xml file under app/code/Company/Module/etc/. Then write “payment_method_is_active” event in it. This is the event which hits on checkout page for payment method availability.
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="payment_method_is_active"> <observer name="custom_payment" instance="Company\Module\Observer\PaymentMethodAvailable" /> </event> </config>
Now create PaymentMethodAvailable.php under Company/Module/Observer/ and write following code in the file. I am disabling the cashondelivery payment method, you can change payment method code according to your need.
<?php namespace Company\Module\Observer; use Magento\Framework\Event\ObserverInterface; class PaymentMethodAvailable implements ObserverInterface { /** * payment_method_is_active event handler. * * @param \Magento\Framework\Event\Observer $observer */ public function execute(\Magento\Framework\Event\Observer $observer) { // you can replace "checkmo" with your required payment method code if($observer->getEvent()->getMethodInstance()->getCode()=="cashondelivery"){ $checkResult = $observer->getEvent()->getResult(); $checkResult->setData('is_available', false); //this is disabling the payment method at checkout page } } }
Now the payment method cashondelivery is disabled from checkout page.
--
If my answer is useful, please Accept as Solution & give Kudos
Hello @gelanivishal
I am able to set payment method by this solution, actually i want cash on delivery for particular product according to zipcode when zipcode available in your area cash on delivery should be enable.
Hello @Vivek Singh,
You can enable table rate shipping method and you can easily restrict zip code within in it. Please refer this link https://docs.magento.com/m1/ce/user_guide/shipping/table-rates.html
--
If my answer is useful, please Accept as Solution & give Kudos