Shopify Hide Payment Method: Hide Cash on Delivery with a Function

How to hide a payment method at Shopify checkout, like Cash on Delivery above an order total or for tagged customers, with a Payment Customization Function.

Shopify checkout hiding Cash on Delivery above an order total

Shopify has no setting that hides a payment method based on the cart or the customer. To hide one, for example Cash on Delivery on orders over $300 or for customers you've tagged, you need a Payment Customization Function. That's a small piece of code inside an app that runs at checkout and tells Shopify which payment methods to remove. You can install a public App Store app that offers this, which works on any plan, or build your own. A custom app that contains a function only works on Shopify Plus.

This guide builds the function in JavaScript: hide Cash on Delivery above a cart total, or for customers with a no-cod tag. The limit is stored in a metafield, so you can change it without redeploying.

What a payment customization can and can't do

From Shopify's Payment Customization Function API reference, API version 2026-10:

Question Answer
What it can do Hide, rename or reorder payment methods at checkout
Functions per store A maximum of 25 active payment customization functions
Where it runs Checkout, B2B, draft order checkout, pre-order and Try Before You Buy
Where it doesn't run Cart, POS, the Shopify admin, order edits and subscription renewals
Plus-only parts Hiding specific placements (for example only the express button), B2B review requirements and payment terms
Shop Pay "In Shop Pay, payment customization functions only apply operations on the native gift card field"
Renaming You can't rename methods whose name is a logo, such as Shop Pay, Apple Pay and Google Pay

Two of these trip people up. A function that hides Cash on Delivery won't stop a buyer who pays with Shop Pay from seeing Shop Pay's own options, and the rule doesn't apply to orders staff create in POS or the admin.

And the plan rule, from Shopify's Functions overview: "Only stores on a Shopify Plus plan can use custom apps that contain Shopify Function APIs." Stores on any plan can use public App Store apps that contain functions. I explain the difference in Shopify custom app vs public app.

Build the function

You need a Partner account or Dev Dashboard access, a dev store, Node.js and the latest Shopify CLI. Create the app with shopify app init if you don't have one, then generate the extension and pick JavaScript:

shopify app generate extension --template payment_customization --name hide-cod

The CLI writes the shopify.extension.toml for you, with the target cart.payment-methods.transform.run. Make sure shopify.app.toml requests the scope that the activation step needs:

[access_scopes]
scopes = "write_payment_customizations"

The input query

The input query decides what data the function receives. This one asks for the cart total, whether the customer has the no-cod tag, the payment methods on offer and the configuration metafield. It follows the shape of Shopify's own "cart total" and "customer tags" examples:

query CartPaymentMethodsTransformRunInput {
  cart {
    cost {
      totalAmount {
        amount
      }
    }
    buyerIdentity {
      customer {
        hasTags(tags: ["no-cod"]) {
          hasTag
          tag
        }
      }
    }
  }
  paymentMethods {
    id
    name
  }
  paymentCustomization {
    metafield(namespace: "$app", key: "function-configuration") {
      jsonValue
    }
  }
}

The run function

The function returns a list of operations. Each paymentMethodHide removes one method by its ID. Payment method IDs aren't fixed across stores, so the function finds the method by name, the same way Shopify's "hide gift card payment methods" example does.

// src/cart_payment_methods_transform_run.js
const NO_CHANGES = { operations: [] };

export function cartPaymentMethodsTransformRun(input) {
  const config = input.paymentCustomization?.metafield?.jsonValue ?? {};
  const match = (config.methodName ?? "cash on delivery").toLowerCase();
  const maxTotal = Number(config.maxTotal ?? 0);

  const total = parseFloat(input.cart.cost.totalAmount.amount);
  const tagged = (input.cart.buyerIdentity?.customer?.hasTags ?? []).some((t) => t.hasTag);
  const overLimit = maxTotal > 0 && total > maxTotal;
  if (!overLimit && !tagged) return NO_CHANGES;

  const operations = input.paymentMethods
    .filter((method) => method.name.toLowerCase().includes(match))
    .map((method) => ({ paymentMethodHide: { paymentMethodId: method.id } }));
  return { operations };
}

A few choices here are deliberate:

  • > not >=. A cart of exactly $300 keeps Cash on Delivery. Decide which one you want, and test that exact amount.
  • No configuration means no change. If the metafield is missing or maxTotal is 0, only the tag rule applies. A typo in the setup doesn't hide payment methods for every buyer.
  • Guests are handled. A guest checkout has no customer, so buyerIdentity.customer is null and the tag rule is skipped.
  • The name is configurable. If your store calls the method something else, set methodName in the metafield to part of the name shown under Settings → Payments.

I tested this function's logic in Node with seven cases shaped like Shopify's documented input: under the limit, exactly at the limit, one cent over, a tagged customer, a guest, no metafield, and a custom method name. All seven passed. Test it on your own dev store as well (see below), because your store's payment method names are what the match depends on.

Activate it on the store

Deploying the function doesn't turn it on. You create a payment customization that points to it with the paymentCustomizationCreate mutation, which needs the write_payment_customizations scope. Start shopify app dev, press g to open GraphiQL, and run:

mutation CreatePaymentCustomization($input: PaymentCustomizationInput!) {
  paymentCustomizationCreate(paymentCustomization: $input) {
    paymentCustomization {
      id
      title
      enabled
    }
    userErrors {
      field
      message
    }
  }
}

With these variables:

{
  "input": {
    "functionHandle": "hide-cod",
    "title": "Hide Cash on Delivery over $300",
    "enabled": true,
    "metafields": [
      {
        "namespace": "$app",
        "key": "function-configuration",
        "type": "json",
        "value": "{\"maxTotal\":300}"
      }
    ]
  }
}

I checked this mutation and its variables against the 2026-10 Admin GraphQL schema. In that version, PaymentCustomizationInput takes functionHandle (the handle in your shopify.extension.toml), title, enabled and metafields. There's no function ID to look up. To change the limit later, update the metafield. You don't need a new deploy.

When it works on the dev store, run shopify app deploy, install that app version on the live store and run the mutation there. Keep the id the mutation returns. You need it to update the customization or turn it off later with paymentCustomizationUpdate.

Testing before buyers see it

  • Test each boundary. Try carts at $299.99, $300.00 and $300.01, then log in as a customer with the no-cod tag and check out with a small cart.
  • Feed it a hand-made cart. shopify app function run --input input.json runs the function locally on a JSON input, and shopify app function replay reruns a real checkout execution from your dev store.
  • Try every checkout you use. Shop Pay, express buttons and draft order checkouts behave differently, as the table above shows.
  • Watch the currency. If you sell in more than one currency, add currencyCode next to amount in the input query and check which currency a test checkout reports. A single maxTotal of 300 shouldn't mean 300 dollars for one buyer and 300 yen for another, so store a limit per currency if you need to.

Common mistakes

  1. Deploying but never creating the customization. Without the mutation, the function never runs.
  2. A custom app on a non-Plus store. The function deploys, but the store can't use it. On other plans, use a public App Store app.
  3. Hard-coding payment method IDs. They differ between your dev store and the live store. Match by name or store the IDs in the metafield.
  4. Mismatched metafield namespace or key. The namespace and key in the mutation must match the input query exactly, or metafield comes back null.
  5. Expecting it to cover POS or admin orders. Payment customizations don't run there.

If a payment Script used to do this for you, this is the API that replaces it: Shopify retired Scripts on June 30, 2026, and they no longer run on any store. I covered the other Script types in replace Shopify Scripts with Functions. For the same problem on WooCommerce, see hide a payment method for a specific product in WooCommerce.

FAQ

Can I hide a payment method in Shopify without an app?

No. Shopify's payment settings turn a method on or off for every buyer. Hiding it for some carts or customers needs a Payment Customization Function, which always comes inside an app.

Do I need Shopify Plus to hide a payment method?

Not if you use a public App Store app that offers payment customizations, which works on any plan. You need Plus to run your own custom app with a function. Hiding a method only from specific placements, such as express checkout buttons, is also Plus-only.

How do I hide Cash on Delivery for large orders in Shopify?

Use a Payment Customization Function that reads the cart total and returns paymentMethodHide for the Cash on Delivery method when the total is over your limit, as in the code above. Keep the limit in a metafield so you can change it without redeploying.

Can a Shopify function hide Shop Pay, Apple Pay or Google Pay?

Partly. You can't rename methods that are shown as logos, and in Shop Pay a function only affects the gift card field. Test any rule that targets express methods on your own checkout before relying on it.

How many payment customizations can a Shopify store have?

Up to 25 active payment customization functions per store. Put several rules in one function where you can, as in this guide.

When to get help

If you need payment rules your checkout can't do today, or a payment rule you lost when Shopify retired Scripts needs rebuilding, I build and test these as custom apps for Plus stores and as public apps for everyone else. See Shopify app development.

Have a project in mind? Let’s talk.

Tell me what you are building and where you need support. I’ll respond with a clear, practical next step.

Start your project
  • Free audit
  • Fixed quote in USD
  • 50% upfront, 50% on delivery
  • 15 days free support
  • Reply within 24 hours