Generally, a full address is recommended for billing information. However, not all countries use or have a zip / postal code so this tutorial will go over how to make that field and others optional.
Add the sample code below to your child theme's functions.php file or in a site specific plugin.
<?php
//* Do NOT include the opening php tag
//* Allow state or province field to be a text field and make it optional
add_filter( 'FHEE__EE_Billing_Attendee_Info_Form__state_field', 'billing_locale_text_field', 10, 1 );
//add_filter( 'FHEE__EE_Billing_Attendee_Info_Form__country_field', 'billing_locale_text_field', 10, 1 );
function billing_locale_text_field( $original_field ) {
return new EE_Text_Input( array( 'required' => false, 'html_class' => 'ee-billing-qstn'));
}
add_filter( 'FHEE__EE_Billing_Attendee_Info_Form__populate_from_attendee', 'billing_autofill_differently', 10, 2 );
function billing_autofill_differently( $autofill_data, $attendee ) {
if( $attendee instanceof EE_Attendee) {
if( $attendee->state_ID() ) {
$autofill_data[ 'state' ] = $attendee->state_name();
} else {
$autofill_data[ 'state' ] = '';
}
if( $attendee->country_ID() ) {
$autofill_data[ 'country' ] = $attendee->country_name();
} else {
$autofill_data[ 'country' ] = '';
}
}
return $autofill_data;
}
//* Allow zip or postal code field to be optional
function ee_braintree_zip_optional( $options, $form ) {
if( $form instanceof EE_Billing_Attendee_Info_Form
&& isset( $options[ 'name' ] )
&& $options[ 'name' ] === 'Braintree_Dropin_Billing_Form'
) {
$zip_input = $options[ 'subsections' ][ 'zip' ];
if( $zip_input instanceof EE_Text_Input ) {
$zip_input->set_required( false );
}
}
return $options;
}
add_filter( 'FHEE__EE_Form_Section_Proper___construct__options_array', 'ee_braintree_zip_optional', 10, 2 );
Need to make all countries available for Event Espresso 4? See this link: https://gist.github.com/lorenzocaum/8293c68d5d1bc3bb6403
References:
https://github.com/eventespresso/ee-code-snippet-library/blob/master/checkout/mn_billing_form_state_and_country_text_inputs.php
https://eventespresso.com/wiki/braintree-payment-gateway/#setup
https://eventespresso.com/topic/braintree-what-are-the-required-fields-on-the-registration-form/
https://eventespresso.com/topic/braintree-installation-for-european-customers/