Back to list of all filter and action hooks for Address Book for WooCommerce.
Description #
Allows setting custom validation criteria to determine if an address entry should be available to use at checkout.
This filter is applied within the is_address_book_entry_valid_for_checkout() method, which checks existing addresses in the user’s address book when selected during checkout. It does not apply to newly added addresses.
Parameters #
$address_entry_valid(bool) Current validation status.$address_entry(array) Address entry data:first_name(string) First name.last_name(string) Last name.address_1(string) Address line 1.address_2(string) Address line 2.city(string) City.state(string) State/Province.postcode(string) Postal code.country(string) Country code.company(string) Company name.phone(string) Phone number.email(string) Email address.
$address_type(string) Address type. Acceptsshippingorbilling.
Examples #
/**
* Require that German address have a company name provided for the address to be available at checkout.
*/
function germany_company_name_field_validation( $valid, $address_entry, $address_type ) {
// Bail if not a German address, do not validate company field in this case
if ( 'DE' !== $address_entry['country'] ) {
return $valid;
}
// Make address invalid for checkout, if missing company name
if ( ! array_key_exists( 'company', $address_entry ) || empty( $address_entry['company'] ) ) {
return false;
}
return $valid;
}
add_filter( 'fc_pro_address_book_is_address_entry_valid_for_checkout', 'germany_company_name_field_validation', 10, 3 );
