Disable payment options-only cash on delivery for particular product-magento

Disable payment options-only cash on delivery for particular product-magento

July 2, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Disable payment options-only cash on delivery for particular product-magento

Disabling Payment Options for Specific Products in Magento

As a senior developer specializing in e-commerce platforms like Magento, I often encounter requests to limit payment options for specific products or categories. In this post, I’ll guide you through the process of disabling all payment methods except Cash on Delivery (COD) for particular items in your Magento store.

Understanding the Payment Process

In Magento, the payment method is determined at the cart level, not the individual product level. This means that by default, every product will be available with all enabled payment options when added to the cart. To achieve our goal—disabling everything except COD for certain products—we need to override the cart behavior or create a custom extension.

Option 1: Overriding Core Files (Not Recommended)

While it’s technically possible to override core files directly, this approach is strongly discouraged by Magento developers and experts at Laravel Company. Overwriting core files can lead to severe issues during updates, making your site vulnerable to security risks.

Option 2: Creating a Custom Extension

The recommended approach is to create a custom extension that modifies the payment method selection based on the items in the cart. This involves creating a new module with a custom observer and a configuration file.

  1. Create a New Module

    • Navigate to app/code/local folder.
    • Create a new directory structure: companyname/CustomPaymentOptions/etc/.
    • Inside etc/, create the following files: config.xml and system.xml.
  2. Configure Payment Methods Based on Cart Contents

In the system.xml file, define a new configuration field to specify which products should have limited payment options.

<label>Products with Limited Payment Options</label>
<frontend_type>multiselect</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
source_model>adminhtml/system_config_source_product</source_model>
  1. Create an Observer

Next, create a new observer that checks the cart contents and disables unnecessary payment methods.

public function removePaymentMethods($observer)
{
    $cart = $observer->getEvent()->getCart();

    // Get the list of products with limited options from admin panel
    $limitedProducts = Mage::helper('custompaymentoptions')->getLimitedProductIds();

    foreach ($cart->getAllVisibleItems() as $item) {
        if (in_array($item->getId(), $limitedProducts)) {
            foreach ($this->_methods as $methodCode => $methodConfig) {
                if (!empty($methodConfig['code'])) {
                    $paymentModel = Mage::getSingleton('payment/config')->getMethodInstance($methodCode);
                    if ($paymentModel && $paymentModel->canUseForCurrency()) {
                        Mage::unregister($methodCode);
                    }
                }
            }
        }
    }
}

Remember to register this observer in your module’s config.xml file.

Conclusion

Disabling payment options for specific products in Magento requires a custom extension approach due to the platform’s architecture. While it might seem complex at first, following the recommended method ensures that your site remains secure and update-friendly.

I highly recommend checking out the advanced Magento tutorials available on Laravel Company for more in-depth insights into customizing payment methods and other e-commerce features.

Checkout Catalog Security Extensions

Our network