Created
March 11, 2025 19:47
-
-
Save rickalday/d55c125d62a4e676934f99f4293b593c to your computer and use it in GitHub Desktop.
Unrequire billing address block field for US in GiveWP visual builder forms
This file contains 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_filter('give_get_country_locale', 'give_custom_requirements'); | |
function give_custom_requirements() { | |
$countries = array( | |
'US' => [ | |
'state' => [ | |
'required' => false, | |
], | |
'address1' => [ | |
'required' => false, | |
], | |
'city' => [ | |
'required' => false, | |
], | |
'zip' => [ | |
'required' => false, | |
], | |
] | |
); | |
return $countries; | |
} | |
function more_countries_without_postcodes( $countries ) { | |
$newcountries = [ | |
'US' => esc_html__( 'United States', 'give' ), | |
]; | |
array_push( $countries, $newcountries ); | |
return $countries; | |
} | |
add_filter( 'give_countries_without_postcodes', 'more_countries_without_postcodes'); | |
add_filter( 'give_city_not_required_country_list', 'more_countries_without_postcodes'); | |
add_filter( 'give_states_not_required_country_list', 'more_countries_without_postcodes'); | |
add_action('givewp_donation_form_schema', function($form) { | |
/** @var \Give\Framework\FieldsAPI\Amount $field */ | |
$country = $form->getNodeByName('country'); | |
// if the country is not found, return | |
if (!$country) { | |
return; | |
} | |
$address1 = $form->getNodeByName('address1'); | |
$city = $form->getNodeByName('city'); | |
$state = $form->getNodeByName('state'); | |
$postalCode = $form->getNodeByName('zip'); | |
// unrequire fields | |
$country->required(false); | |
$address1->required(false); | |
$city->required(false); | |
$state->required(false); | |
$postalCode->required(false); | |
$city->rules('optional'); | |
$state->rules('optional'); | |
$postalCode->rules('optional'); | |
//$field->defaultValue($defaultAmount); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment