Documentation

Add_filter | Edit basket

Note

Just a heads-up: This document is a friendly guide intended for developers and designers. A bit of PHP know-how is needed to get the most out of it.

Please remember, while we love to be helpful, our support policy doesn’t extend to customizations.

Think of any sample code we provide as a starting point or inspiration for your projects!

Overview

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.

Purpose

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.

Syntax

$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.
  • $basket: A string containing formatted data for all items, fees, shipping, discounts, tax, and the order total.
  • $order: The WC_Order object from WooCommerce, providing access to detailed order data for the current transaction.

Example Usage

A developer can then hook into this filter using add_filter() to modify the $basket content:

In this callback:

  • modify_basket_payload receives both $basket and $order.
  • The function appends a custom item string to $newBasket and returns the modified string, which will then be used in the get_cart_items() output.

Was this helpful?

Opayo

Don't already have the plugin? Get access now.

Still need help?

Our team are on hand to provide fast, helpful and professional support.

Support request
All systems operational

Back End Demo

Start exploring our fully functional demo site today.
Gain exclusive admin access to see what's possible.

Create your demo now

Front End Demo

Test drive our plugin on the demo site.

View Demo