Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\Emails\Schema

EmailsSettingsSchema::get_groupsprivateWC 1.0

Get grouped settings structure with field metadata.

Method of the class: EmailsSettingsSchema{}

No Hooks.

Returns

Array.

Usage

// private - for code of main (parent) class only
$result = $this->get_groups( $email ): array;
$email(WC_Email) (required)
Email instance.

EmailsSettingsSchema::get_groups() code WC 10.4.3

private function get_groups( WC_Email $email ): array {
	$group = array(
		'title'       => __( 'Email Settings', 'woocommerce' ),
		'description' => '',
		'order'       => 1,
		'fields'      => array(),
	);

	$form_fields = $email->get_form_fields();
	foreach ( $form_fields as $id => $field ) {
		$field_type = $field['type'] ?? 'text';

		// Skip non-data fields.
		if ( in_array( $field_type, array( 'title', 'sectionend' ), true ) ) {
			continue;
		}

		$field_schema = array(
			'id'    => $id,
			'label' => $field['title'] ?? $id,
			'type'  => $field_type,
			'desc'  => $field['description'] ?? '',
		);

		// Add options for select/multiselect fields.
		if ( isset( $field['options'] ) && is_array( $field['options'] ) ) {
			$field_schema['options'] = $field['options'];
		}

		$group['fields'][] = $field_schema;
	}

	if ( empty( $group['fields'] ) ) {
		return array();
	}

	return array( 'settings' => $group );
}