Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ideas on adjusting Sage Pay (UK) to not require the state/province or the zip/postal 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_sagepay_zip_optional( $options, $form ) {
	if( $form instanceof EE_Billing_Attendee_Info_Form 
		&& isset( $options[ 'name' ] ) 
		&& $options[ 'name' ] === 'Sage_Pay_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_sagepay_zip_optional', 10, 2 );

Need to make all countries available for Event Espresso 4? See this link: https://gist.github.com/lorenzocaum/8293c68d5d1bc3bb6403

You can’t perform that action at this time.