Automattic\WooCommerce\Blocks\Domain\Services
CheckoutFieldsFrontend::save_address_fields
For the My Account page, save address fields. This uses the Store API endpoint for saving addresses so extensibility hooks are consistent across the codebase.
The caller saves the customer object if there are no errors. Nonces are checked before this method executes.
Метод класса: CheckoutFieldsFrontend{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$CheckoutFieldsFrontend = new CheckoutFieldsFrontend(); $CheckoutFieldsFrontend->save_address_fields( $user_id, $address_type, $address, $customer );
- $user_id(int) (обязательный)
- User ID.
- $address_type(строка) (обязательный)
- Type of address (billing or shipping).
- $address(массив)
- Address fields.
По умолчанию: [] - $customer(WC_Customer)
- Customer object.
По умолчанию: null
Код CheckoutFieldsFrontend::save_address_fields() CheckoutFieldsFrontend::save address fields WC 10.4.2
public function save_address_fields( $user_id, $address_type, $address = [], $customer = null ) {
try {
$customer = $customer ?? new WC_Customer( $user_id );
$result = $this->update_additional_fields_for_customer( $customer, 'address', $address_type );
if ( is_wp_error( $result ) ) {
foreach ( $result->get_error_messages() as $error_message ) {
wc_add_notice( $error_message, 'error' );
}
}
$customer->save();
} catch ( \Exception $e ) {
wc_add_notice(
sprintf(
/* translators: %s: Error message. */
__( 'An error occurred while saving address details: %s', 'woocommerce' ),
esc_html( $e->getMessage() )
),
'error'
);
}
}