Created
February 19, 2026 21:34
-
-
Save rickalday/cceadc24742c07e466ec9516e8f84732 to your computer and use it in GitHub Desktop.
Get amount from url (anchor link fix)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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