Get started
Customization
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.
There are several action filters available in the Nexi Checkout plugin. These filters 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 Nexi’s system.
Nexi Checkout was previously known as Nets Easy (and DIBS Easy before that) and there may be some remnants of this in the documentation or plugin. For instance in the code snippets and/or some of the settings.
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.
Filter
Fraud prevention / reduction
The following code snippet allow you to limit card payments to specific countries by adding the name of the allowed country to the “issuerCountries” list.
The country name is specified according to the ISO 3166-1 alpha-3 code standard. Find all country codes on Wikipedia.
This example prevents paying with card for cards issued from, e.g., the US and Canada.
function nets_easy_add_payment_methods( $args ) {
$args['paymentMethods'] = array(
array(
'name' => 'Card',
'type' => 'PaymentType',
'issuerCountries' => array(
'AUT', // Austria.
'BEL', // Belgium.
'BGR', // Bulgaria.
'HRV', // Croatia.
'CYP', // Cyprus.
'CZE', // Czech Republic.
'DNK', // Denmark.
'EST', // Estonia.
'FIN', // Finland.
'FRA', // France.
'DEU', // Germany.
'GRC', // Greece.
'HUN', // Hungary.
'ISL', // Iceland.
'IRL', // Ireland.
'ITA', // Italy.
'LVA', // Latvia.
'LIE', // Liechtenstein.
'LTU', // Lithuania.
'LUX', // Luxemborg.
'MLT', // Malta.
'NLD', // Netherlands.
'NOR', // Norway.
'POL', // Poland.
'PRT', // Portugal.
'ROU', // Romania.
'SVK', // Slovakia.
'SVN', // Slovenia.
'ESP', // Spain.
'SWE', // Sweden.
),
),
);
return $args;
}
add_filter( 'dibs_easy_create_order_args', 'nets_easy_add_payment_methods' );
Modify order / cart data sent in initial create payment request
- Filter:
dibs_easy_create_order_args
- Usage: Modify the information in the initial create payment ID request from Woo to Nexi.
- Nexi API reference: https://developers.nets.eu/nets-easy/en-EU/api/payment-v1/#v1-payments-post
<?php
/**
* Filter hook dibs_easy_create_order_args
* Modify the order/cart data sent to Nexi.
*
* 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( 'dibs_easy_create_order_args', 'my_dibs_easy_create_order_args' );
function my_dibs_easy_create_order_args( $request_args ) {
// Default value = false, if set to true the checkout will not load any user data.
$request_args['checkout']['publicDevice'] = true;
return $request_args;
}
Example how to charge the transaction automatically after reservation have been accepted without calling the Charge API. This will not work if the store offer invoice payments via Nexi Checkout.
<?php
/**
* Filter hook dibs_easy_create_order_args
* Modify the order/cart data sent to Nexi.
*
* 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( 'dibs_easy_create_order_args', 'my_dibs_easy_create_order_args_2' );
function my_dibs_easy_create_order_args_2( $request_args ) {
// Default value = false, if set to true the transaction will be charged automatically after reservation have been accepted without calling the Charge API.
// Does not work if payment method is invoice.
$request_args['checkout']['charge'] = true;
return $request_args;
}
Example on how to set a 00000 placeholder for countries that lack postal code, e.g. Qatar or UAE.
<?php
/**
* Filter hook dibs_easy_create_order_args
* Modify the order/cart data sent to NExi.
*
* 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( 'dibs_easy_create_order_args', 'my_dibs_easy_create_order_args' );
function my_dibs_easy_create_order_args( $request_args ) {
// Default value = false, if set to true the checkout will not load any user data.
if ($request_args['checkout']['consumer']['shippingAddress']['country'] == 'ARE') {
$request_args['checkout']['consumer']['shippingAddress']['postalCode'] = '00000';
}
return $request_args;
}
Example on how to add a temporary custom order reference sent to Nexi. Will be overwritten by the WooCommerce order number when payment is placed.
<?php
/**
* Filter hook nets_easy_embedded_order_reference
* Modify the initial order reference sent to Nexi.
* Only used in embedded checkout flow.
* Can be a string or number. This is a temporary order reference that will be overwritten by the WooCommerce order number when payment is finalized..
*
* 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('nets_easy_embedded_order_reference', 'my_nets_easy_embedded_order_reference');
function my_nets_easy_embedded_order_reference() {
return 'Order from my-woo-store.com';
}
Modify order / cart data in update payment request
dibs_easy_update_order_args
- Usage: Modify the information in the update request from Woo to Nexi.
- Nexi API reference: https://developers.nets.eu/nets-easy/en-EU/api/payment-v1/#v1-payments-paymentid-orderitems-put
<?php
/**
* Filter hook dibs_easy_update_order_args
* Modify the order/cart data sent to Net on update requests.
*
* 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( 'dibs_easy_update_order_args', 'my_dibs_easy_update_order_args' );
function my_dibs_easy_update_order_args( $request_args ) {
// Confirm that shipping cost is specified.
$request_args['shipping']['costSpecified'] = true;
return $request_args;
}
Modify the timeout time for all http requests sent to Nexi
nets_easy_set_timeout
- Usage: Modify the timeout time for all http requests sent to Nexi (measured in seconds). Used together with the Nexi Checkout for WooCommerce plugin.
<?php
/**
* Filter hook nets_easy_set_timeout
* Modify the timeout time used during the order creation process in Woocommerce.
*
* Used together with Nexi Checkout for WooCommerce plugin.
*
* 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( 'nets_easy_set_timeout', 'custom_nets_easy_set_timeout' );
function custom_nets_easy_set_timeout( $time ) {
return 20;
}
?>
Make the checkout address field “State” not required
When you are selling to some countries the checkout field State in the address is required in WooCommerce. Nexi does not have the field State in their system, only City and Country.
With this filter you can make the State field optional to avoid a checkout error in the communication with Nexi when you have the Embedded checkout flow.
add_filter( 'woocommerce_billing_fields', 'nets_filter_state_billing', 10, 1 );
add_filter( 'woocommerce_shipping_fields', 'nets_filter_state_shipping', 10, 1 );
function nets_filter_state_billing( $address_fields ) {
$address_fields['billing_state']['required'] = false;
return $address_fields;
}
function nets_filter_state_shipping( $address_fields ) {
$address_fields['shipping_state']['required'] = false;
return $address_fields;
}