Hiding payment method by country with Shopify Scripts

0 Shares
0
0
0
0
0
0
0

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'
ELIGIBLE_COUNTRY_CODES = ['US', 'CA']
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 == PAYMENT_METHOD
  end
end

Reference: http://gavinballard.com/hiding-credit-card-payment-methods-by-country-with-shopify-scripts/