Magento 2 is never failed to meet your Ecommerce store requirements they have tons of preloaded options built-in while customizations can be covered with coding. Considering international businesses many time, it happens that you have to restrict some payment or shipping options for different countries. Because not shipping and payment charges are the same for all locations, depending on distance and amount of transactions it may vary. Adding those charges to the product price is not a solution nor can be bared by store owners. At that time all you need to do is restrict payment methods based on the shipping method.
For example, if your customer selects the “Flat Rate” shipping method, you don’t want your customer to select the “Cash on delivery” payment method and hide it from checkout. There is no such in Magento 2 backend configurations, however, you can try 3rd party Magento Extensions such as Shipping & Payment Restrictions for Customer Groups in Magento 2. But if you want to do it on your own, you have to code for it.
So, we are back with another blog using which you can restrict any payment method based on your customer shipping method selections in Magento 2. Just follow the below steps and you are done.
First, you need to create “di.xml” file inside your extension folder.
app\code\Vendor\Extension\etc\di.xml

After that you need to create “MethodList.php” file inside your extension folder and add below code inside that file.
app\code\Vendor\Extension\Plugin\Model\MethodList.php

That’s it. You are free to manipulate this code according to your need to restrict and hide multiple payment methods based on your customer’s shipping method selection. Also, check out Shipping and Payment Method per Customer Group Extension which allows the store owner to manage shipping and payment method for the specific customer groups.

Lastly, if you found this blog helpful, don’t forget to share it with your colleagues and Magento Friends and Let us know if you are facing any issue while implementing this code.
Happy Coding!

Restrict Payment Based on Shipping

Click to rate this post!
[Total: 17 Average: 4.9]