If you want to Enable COD Payment Method for Particular Products, Follow below steps
You need to create an extension for this,
Here I have created extension : Magemonkeys_CodRestrict
1. Add new YES/NO product attribute i.e enable_cod_payment and set in Attribute Set which you are using for products
2. Create registration.php file in app/code/Magemonkeys/CodRestrict and add below code
1 2 3 4 5 6 |
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magemonkeys_CodRestrict', __DIR__ ); |
3. Create module.xml file in app/code/Magemonkeys/CodRestrict/etc and add below code
1 2 3 4 5 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Magemonkeys_CodRestrict" setup_version="1.0"> </module> </config> |
3. Create module.xml file in app/code/Magemonkeys/CodRestrict/etc and add below code
1 2 3 4 5 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Magemonkeys_CodRestrict" setup_version="1.0"> </module> </config> |
4. Create events.xml file in app/code/Magemonkeys/CodRestrict/etc and add below code
1 2 3 4 5 6 |
<?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="codpayment" instance="Magemonkeys\CodRestrict\Observer\CodAvailable" /> </event> </config> |
5. Create CodAvailable.php file in app/code/Magemonkeys/CodRestrict/Observer and add below code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?php namespace Magemonkeys\CodRestrict\Observer; use Magento\Framework\Event\ObserverInterface; class CodAvailable implements ObserverInterface { /** * payment_method_is_active event handler. * * @param \Magento\Framework\Event\Observer $observer */ public function execute(\Magento\Framework\Event\Observer $observer) { $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $cartObj = $objectManager->get('\Magento\Checkout\Model\Cart'); $cartItemsCollection = $cartObj->getQuote()->getItemsCollection(); $cartItemsVisible = $cartObj->getQuote()->getAllVisibleItems(); $itemsArray = $cartObj->getQuote()->getAllItems(); $enable_cod_payment = array(); foreach($itemsArray as $item) { $productid = $item->getProductId(); $product = $objectManager->create('Magento\Catalog\Model\Product')->load($productid); $enable_cod_payment[] = $product->getData('enable_cod_payment'); } if($observer->getEvent()->getMethodInstance()->getCode()=="cashondelivery"){ if(in_array(0, $enable_cod_payment)){ $checkResult = $observer->getEvent()->getResult(); $checkResult->setData('is_available', false); } } } } |
You can change payment method condition as per your need.
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-62846eca5696b181001081/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...