How to hide Cash on Delivery by country or product on Shopify
A Shopify store that can only collect cash in one or two countries can still turn on Cash on Delivery. It's a manual payment method, and a customer in any other country can pick it at checkout too. The settings for a ma
A Shopify store that can only collect cash in one or two countries can still turn on Cash on Delivery.
It's a manual payment method, and a customer in any other country can pick it at checkout too. The settings for a manual payment method have a name and instructions for the customer. They don't have a country list or a product list, and Shopify's help page on manual payments doesn't describe a way to limit one to certain countries or products.
I've written before about hiding payment methods with a function and a rules engine. This post starts a step earlier, with what the settings alone can do.
What works without code
Two things, and neither of them hides anything.
The first is the name. Under Settings → Payments → Manual payment methods, a custom manual payment method has a Custom payment method name field, so it can be called something like "Cash on Delivery (UAE only)". Every customer still sees it. They just see the limit too.
The second is a line of theme text on the product page or the cart that says where cash on delivery is available. That's copy, not a setting. Checkout doesn't read it.
What doesn't work
Shipping zones. A zone under Settings → Shipping and delivery sets rates for a group of countries, and Shopify's help docs don't show any field there that ties a payment method to a zone. A separate zone for the cash-on-delivery countries doesn't change which payment methods show up.
To hide a payment method, Shopify's checkout customization docs point one way: "install a payment customization app from the Shopify App Store." If you'd rather write it yourself, the same thing is available to developers as a payment customization function, which Shopify's docs say can "rename, reorder, hide the payment methods available to customers during checkout."
The function
The function gets an input you define with a GraphQL query and returns a list of operations. This query asks for the payment methods, the delivery country, and whether any product in the cart has a no-cod tag:
query RunInput {
paymentMethods { id name }
cart {
deliveryGroups { deliveryAddress { countryCode } }
lines { merchandise { __typename ... on ProductVariant { product { hasAnyTag(tags: ["no-cod"]) } } } }
}
}
It hides cash on delivery when the address is outside the countries you list, or when any line has the tag:
import type { RunInput, CartPaymentMethodsTransformRunResult } from "../generated/api";
const COD_COUNTRIES = ["AE", "SA"]; // where you can collect cash
export function run(input: RunInput): CartPaymentMethodsTransformRunResult {
const cod = input.paymentMethods.find((m) => m.name.toLowerCase().includes("cash on delivery"));
if (!cod) return { operations: [] };
const outsideCodArea = input.cart.deliveryGroups
.map((g) => g.deliveryAddress?.countryCode)
.some((c) => c && !COD_COUNTRIES.includes(c));
const hasNoCodProduct = input.cart.lines.some(
(l) => l.merchandise.__typename === "ProductVariant" && l.merchandise.product.hasAnyTag,
);
return outsideCodArea || hasNoCodProduct
? { operations: [{ paymentMethodHide: { paymentMethodId: cod.id } }] }
: { operations: [] };
}
The query was checked against the 2026-04 API schema, and the function compiles under tsc --strict with types generated from it. It hasn't been built with Shopify CLI or run in a store.
A few things worth knowing before it goes live:
- The target is
cart.payment-methods.transform.run. - It finds the method by name. "Cash on Delivery (UAE only)" still matches. Rename it to "COD" and it doesn't, so the name and the code change together.
- Before the customer enters an address there's no country code, so nothing is hidden yet.
- A store can have at most 25 payment customization functions active.
I'd keep the theme line even after the function is live. Until the address is in, the country check has nothing to go on, so cash on delivery still shows to anyone whose cart has no tagged product.
Takeaway
The manual payment settings decide whether cash on delivery exists. They don't decide who sees it.
If your store offers cash on delivery, could you try one checkout with an address outside the countries where you collect cash and tell me whether it still shows? I haven't run this function in a store yet.
I build HideKit, which does this without code. HideKit is on the Shopify App Store.
This post was drafted with AI help. The facts come from Shopify's docs, my own logs and repo.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.