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.

These filters available in Wasa Kredit Checkout for WooCommerce are mainly added so that you as a merchant or developer have the possibility to change what is sent in the requests between your webshop and Wasa Kredit’s system.

To add a filter you can use the Code Snippets plugin, or something similar of your choice.

If you are new to filters in WordPress you can read more in this article.

Read more about action and filter hooks here:

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 similar of your choice.


Modify order data sent to Wasa Kredit

 * Filter hook wasa_kredit_request_args
 * Modify the order data sent to Wasa Kredit.
 * 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( 'wasa_kredit_request_args', 'my_wasa_create_order_args' );

function my_wasa_create_order_args( $request_args ) {

    // Get the WooCommerce order ID from order key passed in the request.
    $order_references = $request_args['order_references'];
    $order_key = '';
    foreach($order_references as $order_reference ) {
        if('wasa_kredit_woocommerce_order_key' === $order_reference['key']) {
            $order_key = $order_reference['value'];

    // Get the order.
    $order_id = wc_get_order_id_by_order_key( $order_key );
    $order = wc_get_order( $order_id );

    if( ! is_object( $order ) ) {
        return $request_args;

    // Get meta data from order.
    $org_nr = $order->get_meta( '_billing_org_nr', true );

    // Add customer organization number from WooCommerce order if it exist.
    if( ! empty( $org_nr ) ) {
        $request_args['customer_organization_number'] = $org_nr;
    return $request_args;