Automattic\WooCommerce\Internal\Features

FeaturesController::add_feature_settings()privateWC 1.0

Handler for the 'woocommerce_get_settings_advanced' hook, it adds the settings UI for all the existing features.

Note that the settings added via the woocommerce_settings_features will be displayed in the non-experimental features section.

{} Это метод класса: FeaturesController{}

Возвращает

Массив. The updated settings array.

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

// private - только в коде основоного (родительского) класса
$result = $this->add_feature_settings( $settings, $current_section ): array;
$settings(массив) (обязательный)
The existing settings for the corresponding settings section.
$current_section(строка) (обязательный)
The section to get the settings for.

Код FeaturesController::add_feature_settings() WC 7.1.0

private function add_feature_settings( $settings, $current_section ): array {
	if ( 'features' !== $current_section ) {
		return $settings;
	}

	// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment
	/**
	 * Filter allowing WooCommerce Admin to be disabled.
	 *
	 * @param bool $disabled False.
	 */
	$admin_features_disabled = apply_filters( 'woocommerce_admin_disabled', false );
	// phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment

	$feature_settings =
		array(
			array(
				'title' => __( 'Features', 'woocommerce' ),
				'type'  => 'title',
				'desc'  => __( 'Start using new features that are being progressively rolled out to improve the store management experience.', 'woocommerce' ),
				'id'    => 'features_options',
			),
		);

	$features = $this->get_features( true );

	$feature_ids              = array_keys( $features );
	$experimental_feature_ids = array_filter(
		$feature_ids,
		function( $feature_id ) use ( $features ) {
			return $features[ $feature_id ]['is_experimental'];
		}
	);
	$mature_feature_ids       = array_diff( $feature_ids, $experimental_feature_ids );
	$feature_ids              = array_merge( $mature_feature_ids, array( 'mature_features_end' ), $experimental_feature_ids );

	foreach ( $feature_ids as $id ) {
		if ( 'mature_features_end' === $id ) {
			// phpcs:disable WooCommerce.Commenting.CommentHooks.MissingSinceComment
			/**
			 * Filter allowing to add additional settings to the WooCommerce Advanced - Features settings page.
			 *
			 * @param bool $disabled False.
			 */
			$additional_features = apply_filters( 'woocommerce_settings_features', $features );
			// phpcs:enable WooCommerce.Commenting.CommentHooks.MissingSinceComment

			$feature_settings = array_merge( $feature_settings, $additional_features );

			if ( ! empty( $experimental_feature_ids ) ) {
				$feature_settings[] = array(
					'type' => 'sectionend',
					'id'   => 'features_options',
				);

				$feature_settings[] = array(
					'title' => __( 'Experimental features', 'woocommerce' ),
					'type'  => 'title',
					'desc'  => __( 'These features are either experimental or incomplete, enable them at your own risk!', 'woocommerce' ),
					'id'    => 'experimental_features_options',
				);
			}
			continue;
		}

		$feature_settings[] = $this->get_setting_for_feature( $id, $features[ $id ], $admin_features_disabled );
	}

	$feature_settings[] = array(
		'type' => 'sectionend',
		'id'   => empty( $experimental_feature_ids ) ? 'features_options' : 'experimental_features_options',
	);

	return $feature_settings;
}