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.

Filters

Override the printer ID

lcfwc_print_label_printer_id

If you need to override the printer ID sent sent to Cargonizer when printing a shipping label you can use this lcfwc_print_label_printer_id filter.

You can use this to select a different printer based on order properties, user roles, or other custom logic.
Example: Use a different printer for orders with shipping to a specific country.

/**
 * Filter the printer ID used for printing shipping labels.
 *
 * This filter allows you to override the printer ID that is sent to Cargonizer when printing a shipping label.
 * You can use this to select a different printer based on order properties, user roles, or other custom logic.
 *
 * @param string   $printer_id The default printer ID from plugin settings or order.
 * @param WC_Order $order The WooCommerce order object.
 * @return string The printer ID to use.
 */
function custom_printer_id_filter( $printer_id, $order ) {
    // Example: Use a different printer for orders with shipping to a specific country.
    if ( $order->get_shipping_country() === 'SE' ) {
        return 'printer_id_for_sweden';
    }
    return $printer_id;
}
add_filter( 'lcfwc_print_label_printer_id', 'custom_printer_id_filter', 10, 2 );