Collecting only the Zipcode for Stripe payments through the mandatory address field that needs to be used

By: paulus macaulus | Asked: 08/21/2023
ForumsCategory: How-toCollecting only the Zipcode for Stripe payments through the mandatory address field that needs to be used
paulus macaulus asked 11 months ago

Hi, As im aware, Stripe will take a valid credit card number, expiry and CVV to transact, but for added authorisation, First and Last name and a ZipCode also help.

 

In the Formidable Forms area to take Stripe payments, the Address field seems mandatory to include, but for the use case, only the zipcode would be preferable for the user to have to fill in, instead of their entire address.

 

Is there a way to only display the ZipCode from the Address field for the user to enter for the Stripe transaction? I have tried to use CSS to display: none; for the other fields but this breaks validation.

 

The Address field needs to be set as required. Is there a way around this? Some way to not have to use the Address field in the formidable settings on the form? or a coding way to get around this?

 

Paul

1 Answers
paulus macaulus answered 11 months ago

I found some PHP in the Formidable Forms Knowledge Base that shows how to remove 'line2' from the Address Field using frm_address_sub_fields. I changed this to remove the other fields, leaving only the zip/postcode field.
I've tested it, and it seems to have transacted properly in Stripes test mode, I will find out later today from the client if everything looks good on their Stripe Test Dashboard, but in the backend of the Formidable Forms plugin, the payment entry looks good to me.Below is the adapted code I used.

add_filter( 'frm_address_sub_fields', 'customize_address_field', 10, 2 );
function customize_address_field( $sub_fields, $field ) {
	$target_field_id = 262; // Change this to the ID of your address field.
	
	if ( $target_field_id !== (int) $field['id'] ) {
		return $sub_fields;
	}

	// Remove the fields we don't want.
	unset( $sub_fields['line1'] );
	unset( $sub_fields['line2'] );
	unset( $sub_fields['city'] );
	unset( $sub_fields['state'] );

	return $sub_fields;
}

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right