Edit fields on Address Field

By: Sergio Pinheiro | Asked: 10/17/2022
ForumsCategory: How-toEdit fields on Address Field
Sergio Pinheiro asked 2 years ago
Hi, I would like  instead of doing all Address Field required, to make only the field City and the field Country required. Can this be done? Thank in advance for any help provided.      
2 Answers
Rob LeVineRob LeVine answered 2 years ago

You can make some of the "subfields" of the address field required (or remove the requirement) using the frm_validate_field_entry hook.  If the past I've done something like the following (which removes the requirement from the line 1, line 2, state and zip fields) :

add_filter('frm_validate_field_entry', 'your_method_name, 10, 4);
function your_method_name($errors, $posted_field, $posted_value, $args) {
	$addressFieldId = ???; // put your field id here
	
	if ($posted_field->id == $addressFieldId) {
		unset($errors['field' . $posted_field->id]);
		unset($errors['field' . $posted_field->id . '-line1']);
		unset($errors['field' . $posted_field->id . '-line2']);
		unset($errors['field' . $posted_field->id . '-state']);
		unset($errors['field' . $posted_field->id . '-zip']);
	}
}
Sergio Pinheiro answered 2 years ago
Thank you @Rob LeVine for sharing. I going try.

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