Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFieldsFrontend::save_account_form_fieldspublicWC 1.0

Validates and saves additional address fields to the customer object on the My Account page.

Customer is not provided by this hook so we handle save here.

Method of the class: CheckoutFieldsFrontend{}

No Hooks.

Returns

null. Nothing (null).

Usage

$CheckoutFieldsFrontend = new CheckoutFieldsFrontend();
$CheckoutFieldsFrontend->save_account_form_fields( $user_id );
$user_id(int) (required)
User ID.

CheckoutFieldsFrontend::save_account_form_fields() code WC 10.7.0

public function save_account_form_fields( $user_id ) {
	try {
		$customer = new WC_Customer( $user_id );
		$result   = $this->update_additional_fields_for_customer( $customer, 'contact', 'other' );

		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 account details: %s', 'woocommerce' ),
				esc_html( $e->getMessage() )
			),
			'error'
		);
	}
}