Automattic\WooCommerce\Blocks\Domain\Services

CheckoutFields::process_checkbox_fieldprivateWC 1.0

Processes the options for a checkbox field and returns the new field_options array.

Метод класса: CheckoutFields{}

Хуков нет.

Возвращает

Массив|false. The updated $field_data array or false if an error was encountered.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->process_checkbox_field( $field_data, $options );
$field_data(массив) (обязательный)
The field data array to be updated.
$options(массив) (обязательный)
The options supplied during field registration.

Код CheckoutFields::process_checkbox_field() WC 10.3.6

private function process_checkbox_field( $field_data, $options ) {
	$id                     = $options['id'];
	$field_data['required'] = $options['required'] ?? false;

	if ( false === $field_data['required'] && ! empty( $options['error_message'] ) ) {
		$message = sprintf( 'Passing an error message to a non-required checkbox "%s" will have no effect. The error message has been removed from the field.', $id );
		_doing_it_wrong( 'woocommerce_register_additional_checkout_field', esc_html( $message ), '9.8.0' );
		unset( $field_data['error_message'] );
	}

	if ( isset( $options['error_message'] ) && ! is_string( $options['error_message'] ) ) {
		$message = sprintf( 'The error_message property for field with id: "%s" must be a string, you passed %s. A default message will be shown.', $id, gettype( $options['error_message'] ) );
		_doing_it_wrong( 'woocommerce_register_additional_checkout_field', esc_html( $message ), '9.8.0' );
		unset( $field_data['error_message'] );
	}

	// Get the error message property and set it to errorMessage for use in JS.
	if ( isset( $field_data['error_message'] ) ) {
		$field_data['errorMessage'] = $field_data['error_message'];
		unset( $field_data['error_message'] );
	}

	return $field_data;
}