fc_pro_address_book_entries_before_add_entry

Back to list of all filter and action hooks for Address Book for WooCommerce.

Description #

Modify the address book entries list before adding the new entry to it.

Triggered before the individual new entry is added to the list, and before saving the addresses collection to the database.

Parameters #

  • $address_book_entries (array) All address book entries.
    • address_id (array) Address entry data. for each ID
  • $address_entry (array) New address entry.
    • 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.
  • $user_id (int) User ID.

Examples #

/**
 * Maybe clear default address flags from all existing address book entries.
 *
 * @param   array  $address_book_entries  Existing address book entries.
 * @param   array  $address_entry         Address book being saved.
 * @param   int    $user_id               The user id.
 */
public function maybe_clear_default_address_flags_from_all_addresses( $address_book_entries, $address_entry, $user_id ) {
	// Bail if updating address entry does not have default address flags
	if ( ! is_array( $address_entry ) || ( ! array_key_exists( 'default_shipping', $address_entry ) && ! array_key_exists( 'default_billing', $address_entry ) ) ) { return $address_book_entries; }

	// Maybe clear default shipping flags on all existing addresses
	if ( array_key_exists( 'default_shipping', $address_entry ) && 1 == $address_entry[ 'default_shipping' ] ) {
		// Check if country is allowed for shipping
		if ( FluidCheckout_Steps::instance()->is_country_allowed_for_shipping( $address_entry[ 'country' ] ) ) {
			foreach ( $address_book_entries as $key => $address_book_entry ) {
				$address_book_entries[ $key ][ 'default_shipping' ] = 0;
			}
		}
	}

	// Maybe clear default billing flags on all existing addresses
	if ( array_key_exists( 'default_billing', $address_entry ) && 1 == $address_entry[ 'default_billing' ] ) {
		// Check if country is allowed for billing
		if ( FluidCheckout_Steps::instance()->is_country_allowed_for_billing( $address_entry[ 'country' ] ) ) {
			foreach ( $address_book_entries as $key => $address_book_entry ) {
				$address_book_entries[ $key ][ 'default_billing' ] = 0;
			}
		}
	}

	return $address_book_entries;
}
add_filter( 'fc_pro_address_book_entries_before_add_entry', array( $this, 'maybe_clear_default_address_flags_from_all_addresses' ), 10, 3 );

What are your feelings

Updated on December 15, 2025