Klarna Docs - Other Implementation Methods

Other Implementation Methods

Alternative methods for OSM implementation, if your theme is incompatible or if otherwise desired.

Using standard WooCommerce actions and hooks (more reading here), you can customize the location to display the Klarna placement, by using these filters:

  • klarna_onsite_messaging_product_target
  • klarna_onsite_messaging_product_priority
  • klarna_onsite_messaging_cart_target
  • klarna_onsite_messaging_cart_priority

PHP
// Change the placement action for the widget.
add_filter( 'klarna_onsite_messaging_cart_target', 'change_klarna_onsite_messaging_cart_location' );
function change_klarna_onsite_messaging_cart_location( $location ) {
    // Here you need to replace the $location variable with the action that you want to use instead of the default.
    // You can also add custom checks to apply different locations depending on your needs.
    $location = 'woocommerce_after_cart';
    return $location;
}

Code example for Cart page location customization

PHP
// Change the priority for the action for the widget.
add_filter( 'klarna_onsite_messaging_cart_priority', 'change_klarna_onsite_messaging_cart_priority );
function change_klarna_onsite_messaging_cart_priority( $priority ) {
	// Here you need to replace the $priority variable with the action that you want to use instead of the default.
    // You can also add custom checks to apply different priority depending on your needs.
    $priority = '10';
    return $priority;
}

Code example for Cart page priority customization

As of version 1.3.0 of the OSM plugin, shortcodes (more reading here) can be used to display placements.

The shortcode [onsite_messaging] uses the following attributes:

  • data-key
  • data-theme (optional)
  • data-purchase-amount (optional)

More information on data-key and theme can be found on the Configuration Settings page.

PHP
[onsite_messaging data-key="credit-promotion-auto-size" data-purchase-amount="17900" data-theme="dark"]

Code example for shortcode implementation option.

WordPress Widgets (more reading here) can also be used to add Klarna placements to your store.

In Appearance Widgets, drag a Klarna On-Site Messaging widget to the desired location, then choose a Title, Placement Key, and Placement Theme.