@@ -115,6 +115,51 @@ public function allowed_setting_keys( $key ) {
115
115
) );
116
116
}
117
117
118
+ /**
119
+ * Get all settings in a group.
120
+ *
121
+ * @param string $group_id Group ID.
122
+ * @return array|WP_Error
123
+ */
124
+ public function get_group_settings ( $ group_id ) {
125
+ if ( empty ( $ group_id ) ) {
126
+ return new WP_Error ( 'rest_setting_setting_group_invalid ' , __ ( 'Invalid setting group. ' , 'woocommerce ' ), array ( 'status ' => 404 ) );
127
+ }
128
+
129
+ $ settings = apply_filters ( 'woocommerce_settings- ' . $ group_id , array () );
130
+
131
+ if ( empty ( $ settings ) ) {
132
+ return new WP_Error ( 'rest_setting_setting_group_invalid ' , __ ( 'Invalid setting group. ' , 'woocommerce ' ), array ( 'status ' => 404 ) );
133
+ }
134
+
135
+ $ filtered_settings = array ();
136
+ foreach ( $ settings as $ setting ) {
137
+ $ option_key = $ setting ['option_key ' ];
138
+ $ setting = $ this ->filter_setting ( $ setting );
139
+ $ default = isset ( $ setting ['default ' ] ) ? $ setting ['default ' ] : '' ;
140
+ // Get the option value
141
+ if ( is_array ( $ option_key ) ) {
142
+ $ option = get_option ( $ option_key [0 ] );
143
+ $ setting ['value ' ] = isset ( $ option [ $ option_key [1 ] ] ) ? $ option [ $ option_key [1 ] ] : $ default ;
144
+ } else {
145
+ $ admin_setting_value = WC_Admin_Settings::get_option ( $ option_key , $ default );
146
+ $ setting ['value ' ] = $ admin_setting_value ;
147
+ }
148
+
149
+ if ( 'multi_select_countries ' === $ setting ['type ' ] ) {
150
+ $ setting ['options ' ] = WC ()->countries ->get_countries ();
151
+ $ setting ['type ' ] = 'multiselect ' ;
152
+ } elseif ( 'single_select_country ' === $ setting ['type ' ] ) {
153
+ $ setting ['type ' ] = 'select ' ;
154
+ $ setting ['options ' ] = $ this ->get_countries_and_states ();
155
+ }
156
+
157
+ $ filtered_settings [] = $ setting ;
158
+ }
159
+
160
+ return $ filtered_settings ;
161
+ }
162
+
118
163
/**
119
164
* Get the settings schema, conforming to JSON Schema.
120
165
*
0 commit comments