The ag_opayo_modify_basket filter allows developers to modify the $basket string in the get_cart_items() function before it’s returned. This filter is helpful for customising the basket structure by adding, modifying, or removing items and data within the $basket string.
The ag_opayo_modify_basket filter enables developers to hook into the get_cart_items() function, allowing them to modify the basket details of an order dynamically. This could include adjusting item details, fees, or adding custom entries like discounts or promotional items without directly altering the core codebase.
$basket = apply_filters( 'ag_opayo_modify_basket', $basket, $order );ag_opayo_modify_basket: The unique identifier for this filter, which developers will use to hook into and modify the $basket data.WC_Order object from WooCommerce, providing access to detailed order data for the current transaction.A developer can then hook into this filter using add_filter() to modify the $basket content:
// Create new basket payload
add_filter( 'ag_opayo_modify_basket', 'modify_basket_payload', 10, 2 );
function modify_basket_payload( $basket, $order ) {
// Custom modifications to the $basket
// $basket will pull old basket data from get_cart_items()
$newBasket = ':Custom Item:1:10.00:0.00:10.00:10.00';
return $newBasket;
}In this callback:
modify_basket_payload receives both $basket and $order.$newBasket and returns the modified string, which will then be used in the get_cart_items() output.Was this helpful?

Our team are on hand to provide fast, helpful and professional support.
Start exploring our fully functional demo site today.
Gain exclusive admin access to see what's possible.