Skip to content

Instantly share code, notes, and snippets.

@imbolc
Created August 11, 2018 00:20
Show Gist options
  • Save imbolc/33b97e6614449016c5f7a9791d4fa102 to your computer and use it in GitHub Desktop.
Save imbolc/33b97e6614449016c5f7a9791d4fa102 to your computer and use it in GitHub Desktop.
Shopify script to filter country-specific payment methods
def allow_in(gateway, eligible_country_codes)
if Input.cart.shipping_address and eligible_country_codes.include?(Input.cart.shipping_address.country_code)
Output.payment_gateways = Input.payment_gateways
else
Output.payment_gateways = Input.payment_gateways.delete_if do |payment_gateway|
payment_gateway.name == gateway
end
end
end
allow_in('American Express', ['US', 'CA'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment