Skip to content

Instantly share code, notes, and snippets.

@rickalday
Created February 19, 2026 21:34
Show Gist options
  • Select an option

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

Select an option

Save rickalday/cceadc24742c07e466ec9516e8f84732 to your computer and use it in GitHub Desktop.
Get amount from url (anchor link fix)
<?php
add_action('givewp_donation_form_schema', function($form) {
/** @var \Give\Framework\FieldsAPI\Amount $field */
$field = $form->getNodeByName('amount');
if (!$field) {
return;
}
$defaultAmount = $field->getDefaultValue();
// Direct query string
if (isset($_GET['amount'])) {
$defaultAmount = (float) give_clean($_GET['amount']);
// Referrer fallback
} elseif (!empty($_SERVER['HTTP_REFERER'])) {
$urlParts = parse_url($_SERVER['HTTP_REFERER']);
if (!empty($urlParts['query'])) {
parse_str($urlParts['query'], $query);
if (!empty($query['amount'])) {
$defaultAmount = (float) give_clean($query['amount']);
}
}
}
if ($defaultAmount === $field->getDefaultValue()) {
return;
}
$field->defaultValue($defaultAmount);
if (!empty($field->getFixedAmountValue())) {
$field->fixedAmountValue($defaultAmount);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment