Automattic\WooCommerce\StoreApi\Routes\V1
CartUpdateCustomer::get_customer_billing_address()
Get full customer billing address.
Метод класса: CartUpdateCustomer{}
Хуков нет.
Возвращает
Массив
.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_customer_billing_address( $customer );
- $customer(\WC_Customer) (обязательный)
- Customer object.
Код CartUpdateCustomer::get_customer_billing_address() CartUpdateCustomer::get customer billing address WC 8.7.0
protected function get_customer_billing_address( \WC_Customer $customer ) { $validation_util = new ValidationUtils(); $billing_country = $customer->get_billing_country(); $billing_state = $customer->get_billing_state(); $additional_fields = $this->additional_fields_controller->get_all_fields_from_customer( $customer ); $additional_fields = array_reduce( array_keys( $additional_fields ), function( $carry, $key ) use ( $additional_fields ) { if ( 0 === strpos( $key, '/billing/' ) ) { $value = $additional_fields[ $key ]; $key = str_replace( '/billing/', '', $key ); $carry[ $key ] = $value; } return $carry; }, array() ); /** * There's a bug in WooCommerce core in which not having a state ("") would result in us validating against the store's state. * This resets the state to an empty string if it doesn't match the country. * * @todo Removing this handling once we fix the issue with the state value always being the store one. */ if ( ! $validation_util->validate_state( $billing_state, $billing_country ) ) { $billing_state = ''; } return array_merge( [ 'first_name' => $customer->get_billing_first_name(), 'last_name' => $customer->get_billing_last_name(), 'company' => $customer->get_billing_company(), 'address_1' => $customer->get_billing_address_1(), 'address_2' => $customer->get_billing_address_2(), 'city' => $customer->get_billing_city(), 'state' => $billing_state, 'postcode' => $customer->get_billing_postcode(), 'country' => $billing_country, 'phone' => $customer->get_billing_phone(), 'email' => $customer->get_billing_email(), ], $additional_fields ); }