---
title: "How to Restrict Payment Method Based on Shipping selection in Magento 2"
url: "https://magecomp.com/blog/restrict-payment-method-based-on-shipping-selection-in-magento-2/"
date: "2019-09-30T17:21:08+00:00"
modified: "2025-02-25T12:39:11+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 482
reading_time: "3 min read"
summary: "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 businesse..."
description: "Considering international businesses many time, it happens that you have to restrict some payment methods for different countries. Because charges are not th..."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Round Off All Prices in Magento 2"
    url: "https://magecomp.com/blog/round-off-all-prices-in-magento-2/"
  - title: "What is Vertex Tax and How to Set Up Vertex Tax Configuration in Magento 2?"
    url: "https://magecomp.com/blog/configure-vertex-tax-in-magento-2/"
  - title: "Magento 2: Remove Decimal From Quantity In Product Grid In Magento Admin"
    url: "https://magecomp.com/blog/magento-2-remove-decimal-quantity-product-grid-magento-admin/"
---

# How to Restrict Payment Method Based on Shipping selection in Magento 2

_Published: September 30, 2019_  
_Author: Dhiren Vasoya_  

![How to restrict payment method based on the shipping method in Magento 2](https://magecomp.com/blog/wp-content/uploads/2019/09/How-to-restrict-payment-method-based-on-the-shipping-method-in-Magento-2-1024x332.webp)

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.

[![Magento version upgrade](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Version-Upgrade-CTA-1.webp)](https://magecomp.com/services/magento-upgrade-services/)

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**

```
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="MagentoPaymentModelMethodList">
        <plugin name="restrict_payment_on_shippingmethod" type="VendorExtensionPluginModelMethodList" sortOrder="10"/>
    </type>
</config>
```

[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-1.webp)](https://magecomp.com/magento-performance-optimization.html)

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**

```
namespace VendorExtensionPluginModel;

class MethodList
{
	public function afterGetAvailableMethods(
        MagentoPaymentModelMethodList $subject,
    	$availableMethods,
    	MagentoQuoteApiDataCartInterface $quote = null
	) {
    	$shippingMethod = $this->getShippingMethodFromQuote($quote);
    	foreach ($availableMethods as $key => $method) {
        	// Here we will hide CashonDeliver method while customer select FlateRate Shipping Method
            if(($method->getCode() == 'cashondelivery') && ($shippingMethod == 'flatrate_flatrate')) {
                unset($availableMethods[$key]);
        	}
    	}

    	return $availableMethods;
	}

	/**
 	* @param MagentoQuoteApiDataCartInterface $quote
 	* @return string
 	*/
	private function getShippingMethodFromQuote($quote)
	{
    	if($quote) {
        	return $quote->getShippingAddress()->getShippingMethod();
    	}

    	return '';
	}
}
```

[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-5.webp)](https://magecomp.com/services/hyva-theme-development/)

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](https://magecomp.com/magento-2-shipping-and-payment-by-customer-groups-extension.html) 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](https://magecomp.com/blog/wp-content/uploads/2019/09/Restrict-Payment-Based-on-Shipping.png)](https://magecomp.com/magento-2-restrict-payment-based-on-shipping.html?utm_source=blog&utm_medium=CTA&utm_campaign=restrictpaymentbasedonshipping)


---

_View the original post at: [https://magecomp.com/blog/restrict-payment-method-based-on-shipping-selection-in-magento-2/](https://magecomp.com/blog/restrict-payment-method-based-on-shipping-selection-in-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-21 19:40:08 UTC_  
