Last active
April 7, 2026 19:30
-
-
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 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 | |
| // Disable the custom billing address validation rules | |
| add_filter( 'givewp_donation_form_validate_billing_address', function( $errors, $donation, $form_id ) { | |
| // Clear all billing address related validation errors | |
| if ( isset( $errors['billingAddress'] ) ) { | |
| unset( $errors['billingAddress'] ); | |
| } | |
| if ( isset( $errors['billingAddress.city'] ) ) { | |
| unset( $errors['billingAddress.city'] ); | |
| } | |
| if ( isset( $errors['billingAddress.state'] ) ) { | |
| unset( $errors['billingAddress.state'] ); | |
| } | |
| if ( isset( $errors['billingAddress.zip'] ) ) { | |
| unset( $errors['billingAddress.zip'] ); | |
| } | |
| return $errors; | |
| }, 10, 3 ); | |
| // Also add the schema filter to remove them visually | |
| add_action( 'givewp_donation_form_schema', function( $form ) { | |
| $country = $form->getNodeByName( 'country' ); | |
| if ( ! $country ) { | |
| return; | |
| } | |
| $address1 = $form->getNodeByName( 'address1' ); | |
| $city = $form->getNodeByName( 'city' ); | |
| $state = $form->getNodeByName( 'state' ); | |
| $postalCode = $form->getNodeByName( 'zip' ); | |
| $country->required( false ); | |
| $address1->required( false ); | |
| $city->required( false ); | |
| $state->required( false ); | |
| $postalCode->required( false ); | |
| // Remove the custom validation rules | |
| try { | |
| $cityRules = $city->getValidationRules(); | |
| $cityRules->removeRuleWithId( 'city' ); | |
| $stateRules = $state->getValidationRules(); | |
| $stateRules->removeRuleWithId( 'state' ); | |
| $zipRules = $postalCode->getValidationRules(); | |
| $zipRules->removeRuleWithId( 'zip' ); | |
| } catch ( Exception $e ) { | |
| error_log( 'Error removing billing address validation rules: ' . $e->getMessage() ); | |
| } | |
| } ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this CSS code to the form's Custom Styles panel or in GiveWP > Settings > Advanced > Donations Forms > Custom Styles