Add_filter | Form, Server & Direct | Modify the Payload Sent to Opayo
Overview
This filter allows developers to modify the payload data being sent to the Opayo API before the transaction is processed. It’s useful if you want to inject custom fields, change values, or perform conditional logic based on the order data.
Usage
To use the ag_opayo_modify_payload filter, add the following snippet to your functions.php file or a custom plugin:
php
12345678910111213141516
/**
* Modify the Opayo Direct payload before it's sent to the API.
*
* This example adds a custom description.
*/
add_filter( 'ag_opayo_modify_payload', 'modify_opayo_payload_example', 10, 2 );
function modify_opayo_payload_example( $data, $order ) {
// Example: Add a custom field to the description
if ( $order instanceof WC_Order ) {
$data['description'] = 'Order #' . $order->get_order_number() . ' - Custom Store';
}
return $data;
}Parameters
- $data (array) The full payload array that will be sent to the Opayo API. You can inspect or modify any fields here.
- $order (WC_Order) The WooCommerce order object related to the transaction.
Caution
Ensure that any changes made still comply with Opayo’s payload format, or the transaction may be rejected.
If you’re adding custom data not expected by Opayo, it may cause payment errors.
Was this helpful?