Hide certain payment method

Topic summary

Goal: Hide the Cash on Delivery (COD) payment method for customers who had an order tagged “HIDE” within the last 30 days.

Key constraints: Payment customization functions in Shopify can’t query a customer’s past orders at runtime; they must run quickly with predefined inputs.

Recommended approach:

  • Follow Shopify’s payment customization tutorial to create the function.
  • Redesign data flow: instead of tagging orders and checking order history, store a customer-level flag.
    • Best: create a customer metafield (e.g., hideCOD) of type date and update it with the qualifying order date. Alternatively, tag the customer.
  • In the function’s run input GraphQL query, fetch the customer metafield and shop.localTime.date, compare the current date to the metafield date, and if within 30 days, hide COD.

Rationale: Moving the signal to a customer metafield enables fast, deterministic checks within the function without querying orders.

Outcome/status: Clear implementation guidance provided; no confirmation from the original poster. Discussion remains open.

Summarized with AI on December 23. AI used: gpt-5.

I want to make an app with payment customization extension to hide a certain payment method (COD) for some customers.

The customers are those who has an order with HIDE tag in last 30 days. How to achieve this.

Please help me on this @garyrgilbert

Hi @bipu,

Sorry for the late reply.

first I would suggest following along with the payment customization tutorial that shopify has.

https://shopify.dev/docs/apps/build/checkout/payments/create-payments-function#step-1-create-the-payment-customization-function

Secondly I would seriously consider redesigning how you want to achieve this, instead of looking at all the orders the customer has and if any one of them in the last 30 days has a hide tag instead tag the customer, or even better create a metafield “hideCOD” and make it a date field. And instead of tagging the order with hide, you update the metafield of the customer with the order date.

then in the run input graphql you ask for that meta field as well as query the shop{localTime{date}} field and compare that to the metafield date taking your 30 day span into consideration, and hide the COD payment method if necessary.

You will not be able to use the function to query the customers orders in the last 30 days. This type of operation needs to be fast, thats why I said to put it all in metafield of the customer.

I hope this helps,

Cheers

Gary