Skip to content

Instantly share code, notes, and snippets.

@rickalday
Last active March 5, 2026 19:52
Show Gist options
  • Select an option

  • Save rickalday/56e51a6589abda2243f6b15ac13e1cb5 to your computer and use it in GitHub Desktop.

Select an option

Save rickalday/56e51a6589abda2243f6b15ac13e1cb5 to your computer and use it in GitHub Desktop.
Add fund title and ID to Donations endpoint
<?php
add_filter( 'give_api_donations_endpoint', function( $donations ) {
// Check if donations array has the expected structure
if ( ! isset( $donations['donations'] ) || ! is_array( $donations['donations'] ) ) {
return $donations;
}
// Loop through each donation and add the fund title
foreach ( $donations['donations'] as $key => &$donation ) {
// Get the form ID from the donation
if ( isset( $donation['ID'] ) ) {
// Get the fund repository
$fundRepository = give( \GiveFunds\Repositories\Funds::class );
$revenueRepository = give( \GiveFunds\Repositories\Revenue::class );
// Get the fund ID associated with this donation
$fundId = $revenueRepository->getDonationFundId( $donation['ID'] );
if ( $fundId ) {
// Get the fund object
$fund = $fundRepository->getFund( $fundId );
// Add the fund title to the payment meta
$donation['payment_meta']['donation_fund_title'] = $fund->getTitle();
$donation['payment_meta']['donation_fund_id'] = $fundId;
}
}
}
return $donations;
}, 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment