Get started
Customization
Troubleshooting
Klarna support information
Additional Klarna plugins
Actions & filters
Action & filter hooks in WordPress essentially allow you to change or add code without editing core files. They are used extensively throughout WordPress and WooCommerce and are very useful for developers.
Read more about action and filter hooks here:
In Klarna for WooCommerce there are a few action and filter hooks available.
How and where to insert the code?
To get the functions exemplified in this section to work you need to add the code to your WordPress project. You can add it as its own plugin, through the Code Snippets plugin, your theme’s functions.php file or something similar of your choice.
Actions
Handle the Klarna modal closed event
kp_modal_closed
When the Klarna modal is closed, the kp_modal_closed action will be triggered.
Here is an example of how you could handle it depending on whether the purchase was aborted by the customer or rejected by Klarna:
/**
* Handle the Klarna modal closed event.
*
* @param WC_Order $order The Woo order.
* @param bool $reason TRUE if purchase aborted by the customer. FALSE if rejected by Klarna.
* @return void
*/
function klarna_modal_closed( $order, $reason ) {
if ( $reason ) {
$order->add_order_note( 'Customer aborted.' );
} else {
$order->add_order_note( 'Rejected by Klarna.' );
}
$order->save();
}
add_action( 'kp_modal_closed', 'klarna_modal_closed', 10, 2 );Filters
Mixed payment scenarios
buy_and_default_tokenize
The buy_and_default_tokenize intent is designed for mixed payment scenarios—where an order includes both a one-time high-value purchase and a recurring low-value subscription. A common example is a training equipment (one-time purchase) bundled with a monthly subscription (recurring payment) of supplements.
When using buy_and_default_tokenize, only the recurring portion of the order is tokenized using the pay_now payment method. The initial high-value item can be paid for using financing options (from the pay_over_time category). Without explicitly setting the intent to buy_and_default_tokenize the financing option should still be available, but no recurring token would be created.
/**
* Set the purchase intent.
*
* @param array $request The Klarna request.
* @return array
*/
function merchant_kp_set_purchase_intent( $request ) {
$body = json_decode( $request['body'], true );
$body['intent'] = 'buy';
if ( self::cart_has_subscription() ) {
$body['intent'] = 'buy_and_default_tokenize';
}
$request['body'] = wp_json_encode( $body );
return $request;
}
add_filter( 'wc_klarna_payments_create_session_args', 'merchant_kp_set_purchase_intent' );
add_filter( 'wc_klarna_payments_place_order_args', 'merchant_kp_set_purchase_intent' );
add_filter( 'wc_klarna_payments_create_customer_token_args', 'merchant_kp_set_purchase_intent' );
add_filter( 'wc_klarna_payments_update_session_args', 'merchant_kp_set_purchase_intent' );Modify order & cart data sent to Klarna
kp_wc_api_request_args
Used to modify the order data that is sent to Klarna. In this example the product names are anonymized.
add_filter(
'kp_wc_api_request_args',
function( $request_args ) {
foreach ( $request_args['order_lines'] as $index => $order_line ) {
if ( ! isset( $order_line['type'] ) ) {
$request_args['order_lines'][ $index ]['name'] = md5( $order_line['name'] );
}
}
return $request_args;
}
);This will result in the product names sent to Klarna will be just a random series of letters and numbers:

The real name of the product is still visible in the WooCommerce order. It is only in Klarna’s system where the name is anonymized/censored.
Modify the customer object for Klarna Payments
kp_get_customer_type
This filter allows you to customize the customer object before it is sent to Klarna, adding support for both B2C and B2B customers in the same store.
/**
* Modify the customer object for Klarna Payments.
* This filter allows you to customize the customer object before it is sent to Klarna.
*/
add_filter(
'kp_get_customer_type',
function ( $customer, $customer_type ) {
if ( 'b2b' === $customer_type ) {
// Modify the customer object as needed for B2B.
}
return $customer;
},
10,
2
);Change the base region for API requests
klarna_base_region
If you have a European Merchant ID (MID) but also have “Global offering” enabled, Klarna Payments may allow USD as currency.
For Klarna Payments to work the currency must match the country, meaning that you can’t have USD currency when the region is Europe for example.
This filter, where the region can be manually selected, fixes this issue.
/**
* This filter let you change the base region for API requests. Possible values:
* - Europe → '' (leave empty)
* - North America → '-na'
* - Oceania → '-oc'
*
* Default: ''
*/
add_filter(
'klarna_base_region',
function ( $region ) {
return '-na';
}
);
Change the label on the WooCommerce pay button
kp_blocks_order_button_label
If you are using the WooCommerce Checkout block and want to change the label on the Pay button, you can use the kp_blocks_order_button_label filter.
This is hard coded by default, but by changing the return value (in this example “Pay with Klarna”) you can set a label of your choosing.
<?php
function change_kp_order_button_label( $label ) {
return 'Pay with Klarna';
}
add_filter('kp_blocks_order_button_label', 'change_kp_order_button_label');Disable display of scheduled actions in the Order Management metabox
kom_skip_scheduled_actions
With the kom_skip_scheduled_actions filter you can disable the display of scheduled actions in the Order Management metabox, on the admin order page.
add_filter( 'kom_skip_scheduled_actions', '__return_true' );Disable Klarna Payments for subscriptions
wc_klarna_payments_supports
It is not possible to disable subscriptions in the Klarna account for Klarna Payments. If you want to disable Klarna Payments as a payment method for subscriptions you can use the wc_klarna_payments_supports filter to remove subscriptions support from Klarna Payments.
* Remove subscriptions support from Klarna Payments.
*
* @param array $supports The supported features.
* @return array The filtered supported features.
*/
add_filter(
'wc_klarna_payments_supports',
function ( $supports ) {
$subscriptions_support = array(
'subscriptions',
'subscription_cancellation',
'subscription_suspension',
'subscription_reactivation',
'subscription_amount_changes',
'subscription_date_changes',
'subscription_payment_method_change',
'subscription_payment_method_change_customer',
'subscription_payment_method_change_admin',
'multiple_subscriptions',
);
foreach ( $subscriptions_support as $subscription_support ) {
$key = array_search( $subscription_support, $supports, true );
if ( $key !== false ) {
unset( $supports[ $key ] );
}
}
return $supports;
}
);Force locale to a specific country and language
kp_locale
The Klarna plugin uses the WordPress funktion get_locale() to set the locale. With this snippet you can force a specific country and language, American English in the example below.
Locales should be formatted as a language tag consisting of a two-letter language code combined with a two-letter country code according to RFC 1766. Examples are en-us for US English, en-gb for British English and sv-se for Swedish (in Sweden).
Countries are handled as two-letter country codes according to ISO 3166 alpha-2. Examples are us for the United States, gb for Great Britain and se for Sweden.
You can also find more Klarna specific info in their API reference for data types.
/* Force English, US locale. */
add_filter(
'kp_locale',
function( $locale ) {
return 'en-US';
}
);The following values are applicable:
AT: “de-AT”, “de-DE”, “en-DE”
BE: “be-BE”, “nl-BE”, “fr-BE”, “en-BE”
CH: “it-CH”, “de-CH”, “fr-CH”, “en-CH”
DE: “de-DE”, “de-AT”, “en-DE”
DK: “da-DK”, “en-DK”
ES: “es-ES”, “ca-ES”, “en-ES”
FI: “fi-FI”, “sv-FI”, “en-FI”
GB: “en-GB”
IT: “it-IT”, “en-IT”
NL: “nl-NL”, “en-NL”
NO: “nb-NO”, “en-NO”
PL: “pl-PL”, “en-PL”
SE: “sv-SE”, “en-SE”
US: “en-US”.
Modify the request timeout time
wc_kp_request_timeout
Modify the timeout time for all http requests sent to Klarna (measured in seconds). Default is 10 seconds.
<?php
/**
* Filter hook wc_kp_request_timeout
* Modify the timeout time used for http requests sent to Klarna.
*/
add_filter( 'wc_kp_request_timeout', 'custom_wc_kp_request_timeout' );
function custom_wc_kp_request_timeout( $time ) {
return 20;
}
?>