Skip to main content

 

Affirm Merchant Help

Hide Affirm for Certain SKUs (Shopify Plus only)

Merchants using Shopify Plus can hide Affirm as a payment option when the customer's cart contains items with certain SKUs.

  1. Go to the Shopify script editor
  2. Click Create Script
  3. Choose Payment Gateway for the script type
  4. Choose Blank Template
  5. Click Create Script
  6. In the Title box, enter Affirm Hide Based on SKU as the script name
  7. Click Code to open the Ruby source code console
  8. Paste the following code into the console. Replace SKU-1234 with your SKUs and add as many as you need (this is a comma separated list).
available_gateways = Input.payment_gateways
cart = Input.cart

SKUS_TO_HIDE = ["SKU-1234", "..."]

cart.line_items.each do |item|
  item.variant.skus.each do |sku|
    if SKUS_TO_HIDE.include? sku
      available_gateways = available_gateways.delete_if do |payment_gateway|
        payment_gateway.name == "Affirm"
      end
    end
  end
end
Output.payment_gateways = available_gateways
  1. Click Run Script
  2. Click Save and Publish
  • Was this article helpful?