Woocommerce

WooCommerce Payment Gateways by Category (2026)

PHP Snippet, Full Plugin, Block Checkout Support & No-Code Alternatives

Why Restrict Payment Gateways by Category?

Not every payment method makes sense for every product you sell. A store that sells a mix of budget accessories and high-value electronics faces a real problem: PayPal may be fine for a ₹500 phone case, but for a ₹50,000 laptop, the 2.9% fee is significant — and a bank transfer is considerably cheaper. For a store selling digital subscriptions, Cash on Delivery makes no sense at all.

Restricting WooCommerce payment gateways by product category is one of those optimizations that pays for itself quickly — in reduced transaction fees, improved checkout conversion, and better fraud prevention on high-risk order types.

This guide covers every approach: a quick PHP snippet for developers, a full OOP plugin for maintainability, block checkout compatibility (often missed by other guides), and no-code plugin options for store owners who prefer not to write PHP. We also include the gateway ID reference table you need to filter the right methods.

Common Reasons Stores Restrict Payment by Category

High-value products: Force bank transfer for orders above a threshold or from premium product categories to cut transaction fees. Digital products: Disable Cash on Delivery (COD) since delivery never occurs. Subscription products: Disable PayPal for recurring billing categories where card-on-file is required. International categories: Enable only region-specific gateways for internationally-shipped product lines. Regulated items: Accept only verified payment methods for age-restricted or controlled product categories.

WooCommerce Gateway ID Reference

Every WooCommerce payment gateway has a unique string ID. You need this ID to target the correct gateway in your code. Built-in WooCommerce gateways and their IDs:

Gateway NameGateway ID (use in code)
PayPal Standardpaypal
Stripestripe
Cash on Deliverycod
Direct Bank Transfer (BACS)bacs
Cheque Paymentcheque
WooPayments (WooCommerce Payments)woocommerce_payments
Razorpayrazorpay
PayU (India)payu
Cashfreecashfree
Custom / Third-party gatewaysCheck WooCommerce > Settings > Payments for the gateway’s slug

How to Find Any Gateway’s ID

Go to WooCommerce > Settings > Payments. Right-click any payment method and inspect its HTML — look for the name or id attribute containing the gateway slug. Alternatively, add a temporary error_log( print_r( array_keys( WC()->payment_gateways()->payment_gateways() ), true ) ); inside the filter function, trigger checkout, and check your server error log for the complete list.

Method 1 — Lightweight PHP Snippet (Fastest for Developers)

Difficulty: Intermediate | Setup time: 5 minutes

Best for: Simple use cases — disable one gateway for one category

Add to: Child theme functions.php or a custom mu-plugin file

This is the simplest approach for disabling a single payment gateway when a specific product category is in the cart. In the example below, we disable Cash on Delivery (cod) when any product from the ‘digital-products’ category is in the cart.

Step 1 — Find Your Category ID or Slug

Go to Products > Categories in your WordPress admin. Click any category and look at the URL — the term_id number in the URL is the category ID. Alternatively, use the category slug as shown below.

Step 2 — Add the Filter to functions.php

Method 2 — Multiple Categories and Multiple Gateways

For stores with complex rules — different gateways disabled for different categories — use an associative array to map category slugs to the gateway IDs that should be removed when those categories are in the cart.

Block Checkout Compatibility (WooCommerce 8+ — Critical)

If your store uses the WooCommerce Checkout block (introduced in WooCommerce 8.0 and now the default in many themes), the woocommerce_available_payment_gateways filter works differently. The filter still fires, but it fires in a different context — and the is_checkout() check may return false on initial page load when the block renders.

Block Checkout Note

For the Checkout block, the woocommerce_available_payment_gateways filter is called via a REST API endpoint during the block’s initialisation, not on a regular page load. The is_checkout() and is_admin() checks still work correctly for this endpoint in most tested configurations as of WooCommerce 9.x. However, always test your filter on a staging environment with the Checkout block enabled before deploying to production.

Handling the ‘Pay for Order’ Page

When a customer pays for an existing order from the My Account page, the cart is empty — so WC()->cart->get_cart() returns nothing and your filter cannot check categories. Handle this separately by fetching order items from the order object:

add_filter( ‘woocommerce_available_payment_gateways’, ‘wcc_pay_for_order_restriction’, 10, 1 );
 
function wcc_pay_for_order_restriction( $available_gateways ) {
 
    if ( is_admin() ) return $available_gateways;
 
    // Handle the ‘Pay for order’ page on My Account
    $order_id = absint( get_query_var( ‘order-pay’ ) );
    if ( ! $order_id ) return $available_gateways;
 
    $order = wc_get_order( $order_id );
    if ( ! $order ) return $available_gateways;
 
    foreach ( $order->get_items() as $item ) {
        $product_id = $item->get_product_id();
 
        if ( has_term( ‘digital-products’, ‘product_cat’, $product_id ) ) {
            unset( $available_gateways[‘cod’] );
            break;
        }
    }
 
    return $available_gateways;
}

Block Checkout Compatibility (WooCommerce 8+ — Critical)

If your store uses the WooCommerce Checkout block (introduced in WooCommerce 8.0 and now the default in many themes), the woocommerce_available_payment_gateways filter works differently. The filter still fires, but it fires in a different context — and the is_checkout() check may return false on initial page load when the block renders.

Block Checkout Note

For the Checkout block, the woocommerce_available_payment_gateways filter is called via a REST API endpoint during the block’s initialisation, not on a regular page load. The is_checkout() and is_admin() checks still work correctly for this endpoint in most tested configurations as of WooCommerce 9.x. However, always test your filter on a staging environment with the Checkout block enabled before deploying to production.

Handling the ‘Pay for Order’ Page

When a customer pays for an existing order from the My Account page, the cart is empty — so WC()->cart->get_cart() returns nothing and your filter cannot check categories. Handle this separately by fetching order items from the order object: 

No-Code Plugin Alternatives (for Store Owners)

Difficulty: Beginner — no PHP required | Setup: 2–10 minutes

Best for: Stores without regular developer access or complex multi-rule scenarios

Most plugins support: category rules, product rules, user role rules, country rules, cart total rules

For store owners who need more control than a simple snippet provides — or who want to manage rules from the WordPress admin without touching code — these plugins are the established options in 2026.

Plugin A — Conditional Payment Gateways (Free + Premium)

• Free version: Rule by cart total, product quantity, and basic category logic

•  Premium: Rules by category, product tag, user role, shipping method, country, currency, order weight

•  Visual rule builder — no code needed

•  Available at: wordpress.org/plugins/woo-conditional-payment-gateways/

•  Rotates gateways: enable PayPal for even orders, Stripe for odd orders — unique feature

Plugin B — Payment Methods by Product & Country (Free + Pro)

• Free: Show/hide payment gateways by product category or product tag

•  Pro: Country-level rules, product-level rules, fallback gateway configuration

•  Particularly useful for stores with international shipping needing regional gateway logic

•  Available at: wordpress.org/plugins/payment-gateways-per-product-categories-for-woocommerce/

Plugin C — WooCommerce Conditional Payment Methods (Official Extension)

• Built and maintained by the WooCommerce team — highest compatibility guarantee

• GUI-based rule builder within WooCommerce > Settings

• Supports: product category, product type, cart total, user role, shipping zone, country

• Available at: woocommerce.com/products/conditional-payment-methods-for-woocommerce/

• Premium — no free tier

PluginFree Tier
Conditional Payment GatewaysYes (basic)
Payment Methods by Product & CountryYes
WooCommerce Conditional Payment MethodsNo (premium)

Common Mistakes to Avoid

MistakeWhy It Fails & What to Do Instead
Missing is_admin() guardWithout this check, the filter fires in the WooCommerce admin payment settings page and removes gateways from the settings list. Always include if ( is_admin() ) return $available_gateways; as the first check.
Missing is_checkout() guardThe woocommerce_available_payment_gateways filter fires on multiple pages — cart, checkout, My Account. Without a checkout guard, your gateway restriction logic may run where the cart context is unavailable. Add if ( ! is_checkout() ) return $available_gateways;
Not handling empty cart / null cartIf WC()->cart is null (e.g., during AJAX calls or REST requests), calling get_cart() throws a fatal error. Always check is_null( WC()->cart ) before accessing cart items.
Forgetting the ‘Pay for Order’ pageWhen customers pay for existing orders from My Account, the cart is empty. Your category restriction won’t apply. Build a separate check using get_query_var(‘order-pay’) to handle this page.
Hardcoding category IDs that changeCategory term IDs can change between environments (dev, staging, production). Use category slugs with has_term() instead of term IDs for portable code.
Disabling gateways that don’t existAlways use isset( $available_gateways[ $gateway_id ] ) before calling unset() to prevent PHP notices on stores where that gateway is not installed.
Adding code to parent theme functions.phpParent theme files are overwritten on theme updates. Use a child theme’s functions.php or a mu-plugin at wp-content/mu-plugins/wc-gateway-rules.php.

Step-by-Step Implementation Guide

1.     Identify the product categories you want to restrict — note their slugs from Products > Categories

2.     Identify the gateway IDs to restrict — use the Gateway ID Reference Table above or the debug logging method

3.     Choose your approach: lightweight snippet (Method 1), multi-rule snippet (Method 2), or a plugin

4.     For code approach: add your snippet to a child theme functions.php or a mu-plugin file — never the parent theme

5.     Place a test order with a product from the restricted category and verify the target payment method is hidden at checkout

6.     Test the ‘Pay for Order’ page via My Account > Orders > Pay Now to confirm the restriction applies there too

7.     Test with an empty category cart to confirm the restricted gateway reappears when no restricted products are present

8.     Check your error log for PHP notices — resolve any isset() or null cart warnings

Conclusion: Control Your Checkout, Control Your Margins

Restricting WooCommerce payment gateways by product category is one of those practical optimizations that has a direct effect on your bottom line — through lower transaction fees on high-value orders, cleaner checkout experiences for customers, and better compliance for restricted product types.

The lightweight snippet in Method 1 handles most use cases in under 30 lines of code. If your rules grow in complexity — multiple categories, country overlaps, user role conditions — one of the three plugins recommended above manages it from the admin with zero code. And regardless of your approach, always test the ‘Pay for Order’ page and block checkout compatibility before going live.

Frequently Asked Questions

Q1: How do I disable PayPal for a specific product category in WooCommerce?

Use the woocommerce_available_payment_gateways filter hook with has_term() to check if any cart product belongs to your target category, then unset the ‘paypal’ gateway ID from the available gateways array. Always include is_admin() and is_checkout() guards at the top of the function. See Method 1 above for a complete, production-ready code example you can add directly to your child theme’s functions.php.

Q2: What is the woocommerce_available_payment_gateways filter?

woocommerce_available_payment_gateways is a WordPress filter hook that WooCommerce fires at checkout to determine which payment methods to display. It passes an array of active gateway objects. You use add_filter() to hook into it, modify the array by unsetting unwanted gateway IDs, and return the modified array. The filter is the officially supported, non-destructive way to show or hide payment methods conditionally — it does not permanently disable gateways, only hides them for that specific checkout session. 

Q3: Does restricting payment gateways by category work with WooCommerce block checkout?

Yes, with caveats. The woocommerce_available_payment_gateways filter fires via REST API when the Checkout block initialises, and the is_admin() and is_checkout() guards work correctly in this context as of WooCommerce 9.x. However, always test on a staging environment with the block checkout enabled. For complex restrictions, the three no-code plugins listed in this guide (Conditional Payment Gateways, Payment Methods by Product & Country, WooCommerce Conditional Payment Methods) all explicitly support block checkout.

Q4: How do I find the gateway ID for my payment method?

Go to WooCommerce > Settings > Payments, right-click a payment method and inspect the HTML to find its gateway slug. Alternatively, add a temporary error_log( print_r( array_keys( WC()->payment_gateways()->payment_gateways() ), true ) ); inside your filter function, trigger a checkout page load, and check your PHP error log for the complete list of installed gateway IDs. Remove the debug line once you have the IDs you need.

Q5: What is the best free plugin to restrict WooCommerce payment gateways by category?

The best free option is Conditional Payment Gateways (wordpress.org/plugins/woo-conditional-payment-gateways/), which includes category-based rules in its free tier along with order total conditions. Payment Methods by Product & Country (wordpress.org/plugins/payment-gateways-per-product-categories-for-woocommerce/) is also free and particularly strong for category and country-based restrictions. Both are actively maintained as of 2026 and support WooCommerce block checkout.

Q6: Why do my payment gateway restrictions not work on the ‘Pay for Order’ page?

The ‘Pay for Order’ page on the My Account section works differently — the customer’s cart is empty or contains different items because they are paying for a previously placed order, not checking out fresh. Your category check using WC()->cart->get_cart() finds nothing and returns all gateways unchanged. The fix is to detect this page using get_query_var(‘order-pay’), fetch the order with wc_get_order(), then loop through the order’s items to apply your category rules. See the full code example in the Block Checkout section of this guide.

    Leave a Reply