Extra merchant data (EMD)

Extra merchant data (EMD)

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.

Filter order data sent to Kustom for adding EMD (Extra Merchant Data). Add-on functionality for Kustom Checkout for WooCommerce.

This code is not needed for WooCommerce Subscriptions since the function for subscription data is already implemented in Kustom Checkout.

<?php
/**
 * Filter order data sent to Kustom for adding EMD (Extra Merchant Data).
 *
 * Add-on functionality to Kustom Checkout for WooCommerce.
 * This should be used for Kustoms new platform V3.
 *
 * Learn more about available attachment types here: https://docs.klarna.com/kustom-checkout/popular-use-cases/extra-merchant-data/#how-its-done
 **/

add_filter('kco_wc_api_request_args', 'emd_kco_wc_api_request_args');
function emd_kco_wc_api_request_args( $request_args ) {
	
	if( is_user_logged_in() ) {
		
		// User is logged in - add user_login as unique_account_identifier
		$current_user = wp_get_current_user();
		
		$klarna_emd_info = array(
			'unique_account_identifier'		=> $current_user->user_login,
			'account_registration_date'		=> date( 'Y-m-d\TH:i', strtotime( $current_user->user_registered ) ),
			'account_last_modified'			=> date( 'Y-m-d\TH:i' ),
		);
		$klarna_emd_info = array( $klarna_emd_info );
		
	
	} else {
		
		// User is not logged in - send empty params
		$klarna_emd_info = array(
			'unique_account_identifier'		=> '',
		);
		$klarna_emd_info = array( $klarna_emd_info );
		
	}
    
	$body_attachment = json_encode( array(
			'customer_account_info' => $klarna_emd_info
		) );
			
	$request_args['attachment']['content_type'] = 'application/vnd.klarna.internal.emd-v2+json';
	$request_args['attachment']['body']         = $body_attachment;
	
	return $request_args;
}

Adding the code


There are several ways to add code to your site, a couple of examples are:

Please note that we at Krokedil do not offer support for third party plugins.