Hooks (action & filter)

Hooks (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 Payments for WooCommerce there aren’t many action and filter hooks available. But there can be some, mainly for modifying the order data sent to Klarna.

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 theme’s functions.php. You can add it as its own plugin or through the Code Snippets plugin, or something similiar of your choice.


Anonymize product names sent to Klarna

To modify the order data that is sent to Klarna, to anonymize the product names, you can add this filter. You can use the Code Snippets plugin, or something similar of your choice.

	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.

Change the base region for API requests

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: ''
	function ( $region ) {
		return '-na';

Force locale to a specific country and language

Klarna Payments listens to https://developer.wordpress.org/reference/functions/get_locale/ to set the locale. With this snippet you can force a specific country and language, United States and 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. */
	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”.