in

Want to Disable Cash on Delivery for Specific WooCommerce Products? Try This Simple Snippet!

Need to disable Cash on Delivery for a few WooCommerce products? This simple snippet lets you exclude selected product IDs while keeping COD available for everything else. Add it safely with a code snippets plugin or child theme, then test checkout with restricted and unrestricted products to make sure payment options behave as expected.

Want more control over which orders can be paid for on delivery? With a simple WooCommerce snippet, you can disable Cash on Delivery for specific products while keeping it available for the rest of your store.

This guide shows you how to set up WooCommerce to disable COD for specific WooCommerce products, making it easier to manage products that need upfront payment. Add the snippet, choose the products it applies to, and create a checkout experience that works better for your business and your customers.

Why Disable Cash on Delivery for Selected WooCommerce Products?

Not every item in a store carries the same costs or delivery risks. A product-level rule lets you match payment choices to the needs of each item without changing how customers pay for everything else.

First, consider the situations where a tailored restriction can protect your operations while keeping checkout flexible for shoppers.

When product-specific COD restrictions make sense

Cash on Delivery can be convenient, but it may create extra exposure when an order is expensive, customized, or difficult to resell. If a customer refuses the package at the door, you could be left covering shipping and handling costs—or holding inventory that was prepared specifically for that buyer.

For example, a store might still accept COD for everyday accessories while requiring online payment for a made-to-order item. The same approach can suit bulky products with costly delivery, limited-edition stock, or goods that need special preparation. Instead of applying a broad storewide restriction, you can use a WooCommerce snippet to disable COD for specific WooCommerce products and preserve the option where it remains practical.

Before setting a restriction, weigh the product’s price, fulfillment cost, and likelihood of being returned to stock. Common candidates include:

  • Custom or personalized products that cannot easily be sold to another customer.
  • High-value items where an uncollected order could create a significant loss.
  • Bulky or fragile goods with costly delivery or return logistics.

These rules work best when they reflect a clear business reason, not simply a desire to reduce payment choices ad hoc.

Once you know which products need a different rule, it helps to consider how that choice will feel to customers moving through checkout.

How payment options affect the checkout experience

Payment availability is part of the buying decision. A shopper who expects to pay on delivery may abandon checkout if COD suddenly disappears, so clarity matters: explain relevant payment requirements on the product page or near the payment step, rather than leaving customers to discover them at the end.

At the same time, removing an unsuitable option can make checkout more straightforward. Customers see payment methods that are actually available for their order, reducing confusion and helping set accurate expectations before fulfillment begins. Keep the experience consistent by checking how your rules behave when a cart contains both restricted and unrestricted products.

To balance operational needs with a smooth purchase, consider these practices:

  • Give a brief explanation when a product requires upfront payment.
  • Test mixed-product carts to confirm the payment options behave as intended.
  • Offer familiar alternatives, such as card or other online payment methods.

WooCommerce disable COD for specific WooCommerce products: snippet setup

With your product rules decided, the next step is to connect them to WooCommerce’s checkout process. The snippet below checks the items in the cart and removes Cash on Delivery when it finds a match.

First, look at the filter that makes this targeted change possible. It runs when WooCommerce prepares the available payment gateways for checkout.

The code snippet and how its condition works

Add the snippet below, replacing the example IDs with the products you want to exclude. The cod gateway is removed only when a matching product is in the cart; other payment methods remain available.

addfilter( 'woocommerceavailablepaymentgateways', 'mydisablecodforproducts' );
function mydisablecodforproducts( $gateways ) {
    if ( isadmin() && ! wpdoingajax() ) {
        return $gateways;
    }
    if ( ! WC()->cart || ! isset( $gateways['cod'] ) ) {
        return $gateways;
    }
    $excludedids = array( 123, 456 );
    foreach ( WC()->cart->getcart() as $item ) {
        $productids = array( (int) $item['productid'] );
        if ( ! empty( $item['variationid'] ) ) {
            $productids[] = (int) $item['variationid'];
        }
        if ( arrayintersect( $excludedids, $productids ) ) {
            unset( $gateways['cod'] );
            break;
        }
    }
    return $gateways;
}

The condition checks both the cart line’s product ID and, when present, its variation ID. If either appears in the excluded list, COD is hidden for the entire order.

Before adding IDs to the list, make sure you’re using the right ones. WooCommerce displays product IDs in the dashboard, and you can also find them in product edit links.

Find the product IDs to exclude from Cash on Delivery

In your WordPress dashboard, go to Products → All Products and hover over a product title. Its ID usually appears in the status-bar URL; you can also open the product for editing and check the address bar for post= followed by a number.

For example, if the product ID is 789, add it to the array as an integer: array( 123, 456, 789 ). Keep the commas between values, and avoid adding product names or quotation marks.

Once the list is ready, choose a safe place for the code. Avoid editing WooCommerce core files, since updates can overwrite those changes.

Add the snippet safely using a child theme or code snippets plugin

You can place the code in your child theme’s functions.php file, or use a code snippets plugin to manage it separately from the theme. If using a plugin, add the snippet as PHP and follow its instructions about whether to include the opening <?php tag.

Save or activate the snippet, then test checkout with a restricted product and with an unrestricted one. Also try a mixed cart: the snippet is designed to hide COD if any matching item is present.

Finally, decide whether your rule applies to a whole product or only certain options. The code already supports either approach, depending on which IDs you include.

Adjust the product list or apply the rule to product variations

To change the rule later, edit $excludedids: add IDs to restrict more products or remove them to restore COD. For variable products, adding the parent product ID blocks COD for all its variations; adding a variation ID targets just that option.

After changing the list, clear any relevant checkout or page cache and retest. This helps confirm shoppers see the updated payment options rather than a stored version of checkout.

Test and Maintain Your Product-Specific COD Settings

A rule that looks correct in the code still needs to prove itself at checkout. A few focused tests now can catch confusing payment behavior before customers encounter it.

Start with ordinary products, then check the edge cases most likely to affect your store. These checks also give you a useful baseline for future changes.

Verify the checkout with restricted and unrestricted products

Place test orders using a restricted product and an unrestricted product, checking the payment methods shown in each case. For a restricted item, confirm that COD disappears while your other gateways remain available.

Next, try a mixed cart containing both types of product. With this snippet, one restricted item removes COD for the entire order. Also test a variation if your rule targets a specific variation ID, and check the checkout on mobile as well as desktop.

Troubleshoot when Cash on Delivery still appears

If COD remains visible, work through the likely causes before changing the code. Small details—such as an incorrect ID or a different gateway—can make a valid-looking rule appear ineffective.

Check that the snippet is active and that the IDs in $excluded_ids match the product or variation in the cart. Then confirm that the payment method uses WooCommerce’s cod gateway ID; another plugin may provide a separate COD option.

  • Clear relevant caches and retest in a fresh session.
  • Confirm the cart contains the product you intended to restrict.
  • Check whether a checkout or payment plugin is changing available gateways.

Check compatibility with your theme, plugins, and checkout setup

Checkout behavior can vary depending on how your store displays and processes payments. Test the snippet with your active theme, payment plugins, and checkout experience rather than assuming every setup handles gateway changes in the same way.

If you use the WooCommerce Checkout Block or a customized checkout, verify the rule there specifically. When results differ from the standard checkout, test on a staging site and review the relevant plugin documentation before making further changes.

Review the restriction when products or payment settings change

Your product catalog and payment setup may evolve, so revisit the rule whenever you add variations, replace a gateway, or reorganize products. A quick review helps ensure the restriction still matches your fulfillment policy.

Keep a brief record of the excluded IDs and the reason for each restriction. That makes it easier to maintain the WooCommerce disable COD for specific WooCommerce products setup—and to remove outdated restrictions when they’re no longer needed.

Keep COD Available Where It Works Best

A product-specific rule gives you a practical way to manage delivery and payment risks without removing Cash on Delivery from your entire store. By checking the right product or variation IDs, you can hide COD when a restricted item is in the cart while keeping other payment methods available.

Before relying on the change, test restricted, unrestricted, and mixed-product carts with your actual checkout setup. Clear caches if needed, confirm the correct gateway is being targeted, and revisit your excluded product list as your catalog or payment settings change.

With a little testing and maintenance, this WooCommerce disable COD for specific WooCommerce products snippet can support smoother fulfillment and clearer checkout expectations. Choose restrictions that suit your business, explain them to customers, and keep the payment experience simple.

Leave a Reply

Your email address will not be published. Required fields are marked *

      Written by Maeve Rodriguez

      Maeve is a Business Content Writer and Front-End Developer. She's a versatile professional with a talent for captivating writing and eye-catching design.