Actions & filters
Action and 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:
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.
Filters
Action filters are used to modify data before sending it to an external service, rendering it in the browser or storing it in a database.
Automatically sync orders on update
qliro_sync_order_on_update
If you want to allow automatic syncing of WooCommerce orders to Qliro whenever an order is updated you can use the qliro_sync_order_on_update filter.
// Enable the automatic order sync for all Qliro orders.
add_filter( 'qliro_sync_order_on_update', '__return_true' );This filter eliminates the need to manually sync orders from WooCommerce to Qliro.
You can also limit the automatic sync to orders based on custom criteria. In the example the order is synced based on a custom meta field:
/**
* Enable automatic order sync for specific orders based on custom criteria.
*
* @param bool $should_sync If the order should be synced automatically or not. Default is false.
* @param int $order_id The WooCommerce order id to maybe sync automatically.
*/
function qliro_enable_automatic_order_sync($should_sync, $order_id)
{
$order = wc_get_order( $order_id );
// Example condition: Sync if the order has a specific custom meta field value.
if ( $order && 'custom_meta_value' === $order->get_meta( 'custom_meta_field' ) ) {
return true;
}
return $should_sync;
}
add_filter( 'qliro_sync_order_on_update', 'qliro_enable_automatic_order_sync', 10, 2 );Display Qliro even on free orders
qliro_check_if_needs_payment
If you have a coupon that brings the total order value down to zero making the order free for the customer, by default this will show the standard WooCommerce checkout instead of Qliro. If you would rather want to show Qliro for this you can use the filter qliro_check_if_needs_payment. And return false instead of true to this filter.
/**
* Filter to change if you want the Qliro checkout to display on free orders or not.
* For example after a coupon has been used.
*/
add_filter( 'qliro_check_if_needs_payment', 'qliro_change_check_if_needs_payment' );
function qliro_change_check_if_needs_payment( $bool ) {
return false;
}Please note that if you use this filter, Qliro is required to be the first active payment method in WooCommerce under WooCommerce → Settings → Payments. Otherwise this filter won’t work.
Modify data sent to Qliro
Filter to force the Qliro country
qliro_one_request_args
If you want to overwrite the WooCommerce default and instead force a Qliro country you can use the qliro_one_request_args filter.
/**
* Filter to force the Qliro country. Overwrites the WooCommerce default, and sets a forced country.
* Change NO to whatever value you want, 2 letter country codes only. Make sure Qliro is available in that country.
*/
add_filter( 'qliro_one_request_args', 'qliro_one_forced_country_request_args' );
/**
* Forces the Country.
*
* @param array $request_args
* @return array
*/
function qliro_one_forced_country_request_args( $request_args ) {
$request_args['Country'] = 'NO';
return $request_args;
}Filter to force the Qliro language
qliro_one_request_args
If you want to overwrite the WooCommerce default and instead force a Qliro language you can use the qliro_one_request_args filter.
/**
* Filter to force the Qliro language. Overwrites the WooCommerce default, and sets a forced language.
* Change 'en-us' to any of the Qliros supported languages.
* https://developers.qliro.com/docs/qliro-checkout/get-started/checkout-basics#supported-languages
*/
add_filter( 'qliro_one_request_args', 'qliro_one_forced_language_request_args' );
/**
* Forces the language.
*
* @param array $request_args
* @return array
*/
function qliro_one_forced_language_request_args( $request_args ) {
$request_args['Language'] = 'en-us';
return $request_args;
}