Actions & filters
Last modified:
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
Show or hide checkout fields in Dintero Checkout Express
dintero_standard_woocommerce_fields
The filter is the list of checkout fields Dintero recognizes.
On the list → the field stays off-screen and the customer never sees it.
Off the list → the field is moved into view, in the box below the order review.
Hide a field from the customer
/**
* Hides checkout fields from the Dintero Checkout Express layout.
*
* List the fields you do not want shown below the order review. They stay in the off-screen
* checkout form, so WooCommerce still submits them — but the customer never sees them.
*
* Only hide fields that are optional, or that something else fills in for you. Hiding a required
* field does not stop WooCommerce validating it, and the customer will not be able to complete
* the order. In the example below, 'createaccount' is hidden along with the two account fields
* so that the "Create an account?" checkbox stays unticked and WooCommerce skips the check.
*
* @param string[] $fields Fields that Dintero keeps in the hidden checkout form.
* @return string[]
*/
function my_dintero_hide_checkout_fields( $fields ) {
$hide = array(
'createaccount',
'account_username',
'account_password',
);
return array_merge( $fields, $hide );
}
add_filter( 'dintero_standard_woocommerce_fields', 'my_dintero_hide_checkout_fields' );Show a field to the customer
/**
* Shows checkout fields in the Dintero Checkout Express layout.
*
* List the standard WooCommerce fields you want the customer to fill in themselves. They are
* moved into the box below the order review, alongside the order notes.
*
* Dintero only writes its own value to the order if the field is empty, so what the customer
* enters here is kept.
*
* @param string[] $fields Fields that Dintero keeps in the hidden checkout form.
* @return string[]
*/
function my_dintero_show_checkout_fields( $fields ) {
$show = array(
'billing_company',
);
return array_values( array_diff( $fields, $show ) );
}
add_filter( 'dintero_standard_woocommerce_fields', 'my_dintero_show_checkout_fields' );Available field names
The names are the name attributes of the checkout inputs. The default list is:
billing_first_name | billing_last_name | billing_company | billing_address_1 |
billing_address_2 | billing_postcode | billing_city | billing_state |
billing_country | billing_phone | billing_email | |
shipping_first_name | shipping_last_name | shipping_company | shipping_address_1 |
shipping_address_2 | shipping_postcode | shipping_city | shipping_state |
shipping_country | shipping_phone | shipping_email | |
terms | terms-field | _wp_http_referer |
or a field added by another plugin, inspect the checkout page – the name is on the <input>, and its wrapper is <p id="<name>_field">.