Get started
Customization
Troubleshooting
- Embedded checkouts in WooCommerce
- Checkout blocks in WooCommerce
- Error codes
- Compatible plugins and themes
- Known compatibility issues
- Files to exclude from optimization
- Shipping Methods in iframe
- FAQ
- Optimizing your checkout when using an Iframe-based checkout
- Callbacks
- Troubleshooting the checkout flow
- Troubleshooting the Pay for order/Hosted Payment Page flow
- Troubleshooting WooCommerce Subscriptions and KCO
- Kustom Developer logs
- Pending payment orders and held stock
Additional related plugins
Actions & filters
As Klarna Checkout transitions to Kustom Checkout, please note that parts of this documentation are still being updated. You may come across references to Klarna, outdated screenshots, or broken links.
We’re working continuously to revise all content, and we appreciate your patience during this process.
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 Kustom Checkout for WooCommerce there are some action and filter hooks available, mainly for modifying the order data sent to Kustom and how the checkout page should be displayed.
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.
Filters
Action filters are used to modify data before sending it to an external service, rendering it in the browser or storing it in a database. The most common occasion this might be used in the plugin is if you want to modify the order/cart data sent to Kustom before the KCO checkout is rendered.
Modify order data sent to Kustom
kco_wc_api_request_args
To modify the order data sent to Kustom (actually the cart data since the WooCommerce order isn’t created until after the purchase is finalized in Kustom Checkout), you use the filter kco_wc_api_request_args
as described in the following example:
/**
* Use together with Kustom Checkout for WooCommerce (v3 platform)
*
* Filter the purchase country sent to Kustom.
* Add this code to your themes functions.php file or include it in a separate functionality plugin (https://css-tricks.com/wordpress-functionality-plugins/).
**/
add_filter( 'kco_wc_api_request_args', 'krokedil_change_klarna_country' );
function krokedil_change_klarna_country( $request_args ) {
if ( method_exists( WC()->customer, 'shipping_country' ) ) {
$request_args['purchase_country'] = WC()->customer->shipping_country;
}
return $request_args;
}
Information about available parameters in Klarnas API can be found here.
Change the locale sent to Kustom
kco_locale
The filter hook kco_locale
let you change the locale that is sent to Kustom. The locale is the combination of a two-letter language code (see RFC 5646), and country code (see ISO 3166-1 alpha-2) separated by a dash (e.g., en-US
).
function kco_custom_locale( $locale ) {
return 'en-SE';
}
add_filter( 'kco_locale', 'kco_custom_locale');
Anonymize product names sent to Kustom
kco_wc_api_request_args
To modify the order data sent to Kustom, to anonymize the product names, you can add this filter. You can use the Code Snippets plugin, or something similar of your choice.
add_filter(
'kco_wc_api_request_args',
function ( $request_args ) {
foreach ( $request_args['order_lines'] as $index => $order_line ) {
$request_args['order_lines'][ $index ]['name'] = md5( $order_line['name'] );
}
return $request_args;
}
);
This will result in the product names sent to Kustom 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 Kustom’s system where the name is anonymized/censored.
Display Kustom Checkout even on free orders
kco_check_if_needs_payment
If you have a coupon that brings the total order value down to zero making the order free for the customer, by default this will show the standard WooCommerce checkout instead of the Kustom Checkout. If you would rather want to show the Kustom Checkout for this you can use the filter kco_check_if_needs_payment
. And return false instead of true to this filter.
/**
* Use together with Kustom Checkout for WooCommerce (v3 platform)
*
* Filter to change if you want the Kustom Checkout iFrame to display on free orders or not.
* For example after a coupon has been used.
*/
add_filter( 'kco_check_if_needs_payment', 'kco_change_check_if_needs_payment' );
function kco_change_check_if_needs_payment( $bool ) {
return false;
}
Set a forced purchase country
kco_wc_api_request_args
If you need to set a forced purchase country for any reason other then what the store country is and you don’t want to use geolocation, then you can use this snippet to do so. Simply change SE for any other two letter country code that you want to use.
<?php
/**
* Filter to change the purchase country. Overwrites the WooCommerce default, and sets a forced purchase country.
* Change SE to whatever value you want, 2 letter country codes only.
*/
add_filter( 'kco_wc_api_request_args', 'kco_wc_change_purchase_country' );
/**
* Changes the purchase country.
*
* @param array $request_args The KCO v3 request args.
* @return array
*/
function kco_wc_change_purchase_country( $request_args ) {
$request_args['purchase_country'] = 'SE';
return $request_args;
}
Only accept purchases from customer over 18 years of age.
kco_wc_api_request_args
Code example on how to only accept purchases from people over 18 years of age with Kustom Checkout for WooCommerce
This only works if Kustom has activated the “Age verification service” setting in your account.
Read more and contact Kustom here.
You also need to make sure the settings Date of birth mandatory and National identification number mandatory are disabled in the checkout settings of the plugin.
/**
* Kustom Checkout for WooCommerce (v3 platform)
* https://wordpress.org/plugins/klarna-checkout-for-woocommerce/
*
* Only accept purchases from customer over 18 years of age.
* This will only work if Kustom has activated the "Age verification service"setting in your account at Kustom.
*/
add_filter( 'kco_wc_api_request_args', 'my_verify_age_kco_wc_api_request_args' );
function my_verify_age_kco_wc_api_request_args( $request_args ) {
$request_args['options']['verify_age']['minimum_age'] = 18;
return $request_args;
}
Legacy feature – National Identification Handling
Using the options
national_identification_number_mandatory
andverify_national_identification_number
is still fully supported, but no longer the recommended integration approach for Kustom Checkout.
Add additional checkboxes
kco_additional_checkboxes
There are times when you might want to add an additional checkbox, like a newsletter sign-up or something else.
To show the checkbox with associated text in the Kustom Checkout we need to send the info about this to Kustom along with all other order/cart information. We do this by adding the filter kco_additional_checkboxes in the following way:
<?php
/**
* Filter the additional checkboxes to add to the Kustom Checkout iframe. Works with Kustom Checkout for WooCommerce 2.4.3 and above.
*/
add_filter( 'kco_additional_checkboxes', 'add_custom_checkboxes' );
function add_custom_checkboxes( $additional_checkboxes ) {
$additional_checkboxes[] = array(
'id' => 'custom_checkbox', // The ID to be used in the backend to read when we get the order during the checkout process.
'text' => 'Custom checkbox', // The text that you want to display to the customer.
'checked' => false, // true if it should be automatically checked, false if not.
'required' => true, // true if its required to be able to place an order, false if not.
);
return $additional_checkboxes;
}
Text – In the field text you can add the text that you want to display in connection with this checkbox.
Checked – In the field checked you set whether you want the box checked (true) or unchecked (false) on the initial load of the checkout.
Required – In the field required you can set if this checkbox is required (true) or not (false) to be able to complete the order.
Save the result in the order
kco_wc_payment_complete
When the purchase is completed by the customer and are redirected to the Thank you page we can collect the information, which is whether the customer checked the box or not. We do this with the action hook kco_wc_payment_complete in the following way:
<?php
add_action( 'kco_wc_payment_complete', 'kco_process_checkboxes' );
function kco_process_checkboxes( $order_id ) {
$klarna_order_id = get_post_meta( $order_id, '_transaction_id', true );
$klarna_order = KCO_WC()->api->get_klarna_order( $klarna_order_id );
if ( isset( $klarna_order['merchant_requested']['additional_checkboxes'] ) ) {
foreach ( $klarna_order['merchant_requested']['additional_checkboxes'] as $checkbox ) {
if ( 'newsletter' === $checkbox['id'] && $checkbox['checked'] ) {
// Do something with the newsletter checkbox.
}
}
}
}
Please note that
kco_wc_payment_complete
only runs once the order is accepted by Kustom and the payment is completed; so if the user has any actions that needs to be run only in this scenario, this filter could be used.
kco_wc_confirm_klarna_order
is run regardless if the order is accepted, rejected, pending etc in Kustom. Perhaps this could be useful for some customizations.
Note that this is only an example on how you save the information with the order and we can’t guarantee that we have all the updated info on how a specific plugin other than our own handles things, so you need to look this up for yourself.
Modify payment method icon
wc_klarna_checkout_icon_html
An icon is displayed next to the payment method name on the checkout page.
If you want to change this icon there is a filter available for that.
By using the filter wc_klarna_checkout_icon_html
in the following way you can change it to your needs.
<?php
/**
* Filter hook wc_klarna_checkout_icon_html
* Modify the icon displayed for Kustom Checkout payment method in checkout.
*
* Add this code to your themes functions.php file or include it in a separate functionality plugin (https://css-tricks.com/wordpress-functionality-plugins/).
*/
add_filter( 'wc_klarna_checkout_icon_html', 'krokedil_wc_klarna_checkout_icon_html' );
function krokedil_wc_klarna_checkout_icon_html( $icon_html ) {
// Standard image is https://cdn.klarna.com/1.0/shared/image/generic/logo/en_us/basic/logo_black.png?width=100.
$icon_src = 'https://x.klarnacdn.net/payment-method/assets/badges/generic/black/klarna.png?width=100';
$new_icon_html = '<img src="' . $icon_src . '" alt="Kustom Checkout"/>';
// Return the modified image html.
return $new_icon_html;
}
A set of different logos/badges to use can be found at the Klarna Developers site.
Customer type changed
kco_customer_type_changed
The hook kco_customer_type_changed
is triggered whenever the customer switches between organization and person in the checkout.
function kco_customer_changed( $customer_type ) {
// The customer type is either 'b2b' or 'b2c'.
if ( 'b2c' === $customer_type ) {
// Do something.
} elseif ( 'b2b' === $customer_type ) {
// Do something else.
}
}
add_action( 'kco_customer_type_changed', 'kco_customer_changed' );