How To Conditionally Remove The PayPal Payment Gateway In Shopify

So I recently had a job where we needed to remove the PayPal payment gateway in the Shopify checkout for particular products.

So a simple way for the client to manage this, is for them to tag those products they don’t want to be purchasable by PayPal, and then for us to write a script that detects those tags for those products in the checkout, and then removes that payment gateway.

Now it’s not possible to modify the checkout experience for standard Shopify stores. But if you’re a Shopify Plus customer then you can use the Script Editor App which does allow you to programatically modify the checkout experience. The API for this is here.

Now my language of expertise is JavaScript, and to use the Script Editor you have to use Ruby. This wasn’t actually too bad to learn. As someone that has done a lot of programming, looking up the syntax online for how to do something was quite easy. Particularly with the help of some Ruby pros in slack chats.

So, back to the problem at hand. If the client just added a tag called ‘no-paypal’ to whatever product they wanted to trigger the removal of the PayPal payment gateway, this is how we did it:

View this gist on GitHub

A gotcha I had trouble figuring out on my own: when you create a new script in the Script Editor, be sure to choose the correct script template. This is because the different types of scripts have different data objects available to them at runtime. In this case, I thus needed to choose the “Payment gateways” template.

Any questions/comments, let me know!

4 responses to “How To Conditionally Remove The PayPal Payment Gateway In Shopify”

  1. Hi Andrew, thank you for this. I have a quick question. Just to a quick question, we have numerous products that PayPal will no longer accept. On the payments gateway template page would I have to change line one for the product and then add the script for each individual product?

    • Hey Russell. From what I remember with this script, all you need to do is tag the products that you don’t want to be purchasable via PayPal with “no-paypal”. So no changes to the script needed.

  2. Hi Andrew,
    Thanks so much.
    I am trying to rewrite the scipt for blocking Paypal not for certain products but for tagged customers.
    Any idea how to change this?

Leave a Reply

Your email address will not be published.