Skip to content

Instantly share code, notes, and snippets.

@rickalday
Last active July 2, 2026 19:50
Show Gist options
  • Select an option

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

Select an option

Save rickalday/2b2b8a746a31d26636bef777bfe675e8 to your computer and use it in GitHub Desktop.
Custom Address Fields with conditional display
<?php
use Give\Framework\FieldsAPI\Text;
add_action('givewp_donation_form_schema', function($form, $formId) {
//Country field
$country = Text::make('country')
->showInReceipt()
->receiptLabel(__('Country', 'give-tributes'))
->label(__('Country', 'give-tributes'))
->emailTag('tributeCountry')
->showIf('enableTribute', '=', 'show')
->andShowIf('tributesSendNotification', '=', 'send');
//Address 1 field
$address1 = Text::make('address1')
->showInReceipt()
->receiptLabel(__('Address Line 1', 'give-tributes'))
->label(__('Address Line 1', 'give-tributes'))
->emailTag('tributeAddress1')
->showIf('enableTribute', '=', 'show')
->andShowIf('tributesSendNotification', '=', 'send');
//Address 2 field
$address2 = Text::make('address2')
->showInReceipt()
->receiptLabel(__('Address Line 2', 'give-tributes'))
->label(__('Address Line 2', 'give-tributes'))
->emailTag('tributeAddress2')
->showIf('enableTribute', '=', 'show')
->andShowIf('tributesSendNotification', '=', 'send');
//City field
$city = Text::make('city')
->showInReceipt()
->receiptLabel(__('City', 'give-tributes'))
->label(__('City', 'give-tributes'))
->emailTag('tributeCity')
->showIf('enableTribute', '=', 'show')
->andShowIf('tributesSendNotification', '=', 'send');
//State field
$state = Text::make('state')
->showInReceipt()
->receiptLabel(__('State/Province', 'give-tributes'))
->label(__('State/Province', 'give-tributes'))
->emailTag('tributeState')
->showIf('enableTribute', '=', 'show')
->andShowIf('tributesSendNotification', '=', 'send');
//Zip field
$zip = Text::make('zip')
->showInReceipt()
->receiptLabel(__('Zip/Postal Code', 'give-tributes'))
->label(__('Zip/Postal Code', 'give-tributes'))
->emailTag('tributeZip')
->showIf('enableTribute', '=', 'show')
->andShowIf('tributesSendNotification', '=', 'send');
// Insert after the 'tributes'
$form->insertAfter('tributes', $address1);
$form->insertAfter('address1', $address2);
$form->insertAfter('address2', $city);
$form->insertAfter('city', $state);
$form->insertAfter('state', $zip);
$form->insertAfter('zip', $country);
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment