Hiding payment method by country with Shopify Scripts

A quick Shopify script to hide a specific payment method (eg credit card) from customers located outside specific countries.

You should be able to copy and paste this into the Shopify Script editor after clicking “Create script” and then choosing a blank “Payment gateways” script. You may have to tweak the value for PAYMENT_METHOD depending on the gateway you’re using.

PAYMENT_METHOD = 'Credit Card'

if Input.cart.shipping_address and ELIGIBLE_COUNTRY_CODES.include?(Input.cart.shipping_address.country_code)
  Output.payment_gateways = Input.payment_gateways
  Output.payment_gateways = Input.payment_gateways.delete_if do |payment_gateway|
    payment_gateway.name == PAYMENT_METHOD