Klarna Docs - Shopify Plus: custom scripts

Shopify Plus: custom scripts

Learn how to customize your payment methods in Shopify Plus.

Shopify Scripts are being deprecated and will no longer be supported as of August 28, 2025. Scripts are replaced by apps powered by Shopify Functions. For any new integration, you will need to use such an app for checkout customization. Apps such as HidePay, Payfy and BeSure can be utilized to hide Klarna for certain markets, products, or other conditions.

Shopify Plus merchants can use custom scripts to customize their payment methods in Shopify’s checkout, based on available cart data, as documented below.  

Shopify documentation has an example payment script code. Note that Klarna isn’t responsible for this sample code. You have to review and test this code in your store. 

To start using custom scripts, go to the Script Editor app and follow the instructions in Shopify documentation.

Even though the name of Klarna appears differently in checkout with a different translation per language, as documented in this article, Script Editor custom code should reference the name of the payment method configured in the app's payment method extension, which for this integration is Klarna.

For each store, you have to customize the code below to use the appropriate data for the store.

Shopify only allows a single script to be published for each script type, for example, Line Items, Shipping, Payments, etc. The code examples below likely require modifications to be combined into a single script.

The code below was copied from Shopify’s example code for the Reorder payment gateways in the Script Editor app.It is slightly modified to match the payment method/gateway names.
You can view the original Reorder gateways code example published in Shopify documentation.

A screenshot of Shopify's Script editor with the Select script template window.

Shopify offers a script template for reordering payment gateways.

RUBY
desired_order = ["Klarna", "Shopify Payments", “PayPal”]
Output.payment_gateways = Input.payment_gateways.sort_by do |payment_gateway|
  desired_order.index(payment_gateway.name) || Float::INFINITY
end

Sample code to reorder payment gateways.

This code lets you hide payment methods depending on the cart presentment currency, that is, the customer’s local currency.

RUBY
cart = Input.cart
available_gateways = Input.payment_gateways
if cart.presentment_currency != "USD"
  available_gateways = available_gateways.delete_if do |payment_gateway|
    payment_gateway.name == "Klarna"
  end
end
Output.payment_gateways = available_gateways

Sample code to hide payment methods.

This code lets you hide payment gateways for specific countries, based on the customer's shipping address. You can view the original Hide gateways for specific countries code published in Shopify documentation.

RUBY
cart = Input.cart
available_gateways = Input.payment_gateways
if (cart.shipping_address)
  if cart.shipping_address.country_code != "US"
    available_gateways = available_gateways.delete_if do |payment_gateway|
      payment_gateway.name == "Klarna"
    end
  end
end
Output.payment_gateways = available_gateways

Sample code to hide payment gateways for specific countries.

The Shopify API doesn’t provide billing address cart data as parameters for payment gateway custom scripts since the billing address is entered by the customer on the same page where the payment gateway custom script is run.

This code lets you hide payment gateways for specific products, for example, gift cards. You can view the original Hide gateways for specific products code published in Shopify documentation.

RUBY
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 == "Klarna"

Sample code to hide payment gateways for specific products.

This code lets you hide Klarna payment methods based on product tags.

RUBY
available_gateways = Input.payment_gateways
cart = Input.cart
  
TAGS_TO_HIDE = ["hide-klarna", "..."]
  
cart.line_items.each do |item|
  item.variant.product.tags.each do |tag|
    if TAGS_TO_HIDE.include? tag
      available_gateways = available_gateways.delete_if do |payment_gateway|
        payment_gateway.name == "Klarna"

Sample code to hide Klarna payment methods based on product tags.