WC_REST_Setting_Options_V2_Controller::get_group_settings()publicWC 3.0.0

Get all settings in a group.

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

Хуки из метода

Возвращает

Массив|WP_Error.

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

$WC_REST_Setting_Options_V2_Controller = new WC_REST_Setting_Options_V2_Controller();
$WC_REST_Setting_Options_V2_Controller->get_group_settings( $group_id );
$group_id(строка) (обязательный)
Group ID.

Список изменений

С версии 3.0.0 Введена.

Код WC_REST_Setting_Options_V2_Controller::get_group_settings() WC 9.3.3

public function get_group_settings( $group_id ) {
	if ( empty( $group_id ) ) {
		return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
	}

	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
	$settings = apply_filters( 'woocommerce_settings-' . $group_id, array() );

	if ( empty( $settings ) ) {
		return new WP_Error( 'rest_setting_setting_group_invalid', __( 'Invalid setting group.', 'woocommerce' ), array( 'status' => 404 ) );
	}

	$filtered_settings = array();
	foreach ( $settings as $setting ) {
		$option_key = $setting['option_key'];
		$setting    = $this->filter_setting( $setting );
		$default    = isset( $setting['default'] ) ? $setting['default'] : '';
		// Get the option value.
		if ( is_array( $option_key ) ) {
			$option           = get_option( $option_key[0] );
			$setting['value'] = isset( $option[ $option_key[1] ] ) ? $option[ $option_key[1] ] : $default;
		} else {
			$admin_setting_value = WC_Admin_Settings::get_option( $option_key, $default );
			$setting['value']    = $admin_setting_value;
		}

		if ( 'multi_select_countries' === $setting['type'] ) {
			$setting['options'] = WC()->countries->get_countries();
			$setting['type']    = 'multiselect';
		} elseif ( 'single_select_country' === $setting['type'] ) {
			$setting['type']    = 'select';
			$setting['options'] = $this->get_countries_and_states();
		}

		$filtered_settings[] = $setting;
	}

	return $filtered_settings;
}