Skip to content

Instantly share code, notes, and snippets.

@lorenzocaum
Last active March 4, 2016 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorenzocaum/ea0401828f83826917d4 to your computer and use it in GitHub Desktop.
Save lorenzocaum/ea0401828f83826917d4 to your computer and use it in GitHub Desktop.
Ideas on adjusting Braintree to not require the state, country, and zip code

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