Automattic\WooCommerce\Blocks\Shipping
PickupLocation::has_valid_pickup_location()
Checks if a given address is complete.
Method of the class: PickupLocation{}
No Hooks.
Return
true|false
.
Usage
// protected - for code of main (parent) or child class $result = $this->has_valid_pickup_location( $address );
- $address(array) (required)
- Address.
PickupLocation::has_valid_pickup_location() PickupLocation::has valid pickup location code WC 9.8.1
protected function has_valid_pickup_location( $address ) { // Normalize address. $address_fields = wp_parse_args( (array) $address, array( 'city' => '', 'postcode' => '', 'state' => '', 'country' => '', ) ); // Country is always required. if ( empty( $address_fields['country'] ) ) { return false; } // If all fields are provided, we can skip further checks. if ( ! empty( $address_fields['city'] ) && ! empty( $address_fields['postcode'] ) && ! empty( $address_fields['state'] ) ) { return true; } // Check validity based on requirements for the country. $country_address_fields = wc()->countries->get_address_fields( $address_fields['country'], 'shipping_' ); foreach ( $country_address_fields as $field_name => $field ) { $key = str_replace( 'shipping_', '', $field_name ); if ( isset( $address_fields[ $key ] ) && true === $field['required'] && empty( $address_fields[ $key ] ) ) { return false; } } return true; }