Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\Account

Controller{}WC 1.0└─ AbstractController

REST API Account Settings Controller Class.

Hooks from the class

Usage

$Controller = new Controller();
// use class methods

Methods

  1. public get_all_settings()
  2. public do_action( 'woocommerce_settings_updated', $updated_settings, $this->rest_base )
  3. public sanitize_text_field( $setting_id )
  4. public array(
  5. public foreach ( $values_to_update as $setting_id => $setting_value )
  6. public if ( ! empty( $updated_settings ) )
  7. public array_column( $settings, null, 'id' )
  8. public array_map( 'sanitize_text_field', $value )
  9. public update_option( $setting_id, $value )
  10. public WP_Error(
  11. public function ( $def )
  12. public rest_ensure_response( $response )
  13. public array_filter(
  14. public WC_Settings_Accounts()
  15. public get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE )
  16. public __( 'Sorry, you are not allowed to edit account settings.', 'woocommerce' )
  17. public empty( $value )
  18. public get_item( $request )
  19. public get_item_permissions_check( $request )
  20. public update_item_permissions_check( $request )
  21. public get_item_schema()
  22. public get_json_params()
  23. public rest_get_endpoint_args_for_schema( $this->get_item_schema(), $method )
  24. public get_schema()
  25. public get_settings()
  26. public register_routes()
  27. public isset( $def['id'] ) && ! in_array( $type, array( 'title', 'sectionend' ), true )
  28. public init( AccountSettingsSchema $schema )
  29. public wc_bool_to_string( $value )
  30. public update_item( $request )
  31. ERROR: no method name found on line `*`
  32. ERROR: no method name found on line `*/`
  33. ERROR: no method name found on line `/**`
  34. ERROR: no method name found on line `*`
  35. ERROR: no method name found on line `*/`
  36. ERROR: no method name found on line `* @return WC_Settings_Accounts`
  37. ERROR: no method name found on line ``
  38. ERROR: no method name found on line ``
  39. ERROR: no method name found on line ``
  40. ERROR: no method name found on line `/**`
  41. ERROR: no method name found on line `*/`
  42. ERROR: no method name found on line `return $validation_result;`
  43. ERROR: no method name found on line ``
  44. ERROR: no method name found on line `* @param WP_REST_Request $request Request object.`
  45. ERROR: no method name found on line `* Fires when WooCommerce settings are updated.`
  46. ERROR: no method name found on line `}`
  47. ERROR: no method name found on line ``
  48. ERROR: no method name found on line `*/`
  49. ERROR: no method name found on line `);`
  50. ERROR: no method name found on line ``
  51. ERROR: no method name found on line `case 'textarea':`
  52. ERROR: no method name found on line `case 'number':`
  53. ERROR: no method name found on line `// Check if the request contains a 'values' field with the flat key-value mapping.`
  54. ERROR: no method name found on line `* @return array Array of setting definitions.`
  55. ERROR: no method name found on line ``
  56. private validate_setting_value( $setting_id, $value )
  57. ERROR: no method name found on line ``
  58. ERROR: no method name found on line ``
  59. ERROR: no method name found on line ``
  60. ERROR: no method name found on line `* @param string $setting_id Setting ID.`
  61. ERROR: no method name found on line ``
  62. ERROR: no method name found on line `/**`
  63. protected get_item_response( $item, WP_REST_Request $request )
  64. ERROR: no method name found on line ``
  65. ERROR: no method name found on line `* @param mixed $value Setting value.`
  66. private get_settings_account_instance()
  67. ERROR: no method name found on line ``
  68. ERROR: no method name found on line ``
  69. ERROR: no method name found on line ``
  70. ERROR: no method name found on line `'woocommerce_rest_account_settings_error',`
  71. ERROR: no method name found on line ``
  72. ERROR: no method name found on line `}`
  73. ERROR: no method name found on line ``
  74. ERROR: no method name found on line ``
  75. ERROR: no method name found on line `// Security check: only allow updating valid WooCommerce account settings.`
  76. ERROR: no method name found on line ``
  77. ERROR: no method name found on line ``
  78. ERROR: no method name found on line ``
  79. ERROR: no method name found on line `* @return array`
  80. ERROR: no method name found on line `}`
  81. ERROR: no method name found on line `* Check permissions for reading account settings.`
  82. ERROR: no method name found on line ``
  83. ERROR: no method name found on line `return 0;`
  84. ERROR: no method name found on line ``
  85. ERROR: no method name found on line `* @param WP_REST_Request $request Full details about the request.`
  86. ERROR: no method name found on line ``
  87. ERROR: no method name found on line ``
  88. ERROR: no method name found on line `*`
  89. ERROR: no method name found on line `// Check if the request contains a 'values' field with the flat key-value mapping.`
  90. ERROR: no method name found on line `/**`
  91. ERROR: no method name found on line `// Sanitize the setting ID.`
  92. ERROR: no method name found on line `// Exclude non-editable markers like 'title' and 'sectionend'.`
  93. ERROR: no method name found on line `// Log the update if settings were changed.`
  94. ERROR: no method name found on line ``
  95. ERROR: no method name found on line ``
  96. ERROR: no method name found on line `* Fires when WooCommerce settings are updated.`
  97. ERROR: no method name found on line `continue;`
  98. ERROR: no method name found on line `// Security check: only allow updating valid WooCommerce account settings.`
  99. ERROR: no method name found on line ``
  100. ERROR: no method name found on line ``
  101. ERROR: no method name found on line ``
  102. ERROR: no method name found on line ``
  103. ERROR: no method name found on line `}`
  104. ERROR: no method name found on line `/**`
  105. ERROR: no method name found on line `* @param AccountSettingsSchema $schema Schema class.`
  106. ERROR: no method name found on line ``
  107. ERROR: no method name found on line ``
  108. ERROR: no method name found on line `*/`
  109. ERROR: no method name found on line `/**`
  110. ERROR: no method name found on line ``
  111. ERROR: no method name found on line ``
  112. ERROR: no method name found on line `* Get the WC_Settings_Accounts instance.`
  113. ERROR: no method name found on line `$this->schema = $schema;`
  114. ERROR: no method name found on line `*`
  115. ERROR: no method name found on line ``
  116. ERROR: no method name found on line `}`
  117. ERROR: no method name found on line `*`
  118. ERROR: no method name found on line ``
  119. ERROR: no method name found on line `}`
  120. ERROR: no method name found on line ``
  121. ERROR: no method name found on line `require_once WC_ABSPATH . 'includes/admin/class-wc-admin-settings.php';`
  122. ERROR: no method name found on line `'single_select_page' => 'select',`
  123. ERROR: no method name found on line ``
  124. ERROR: no method name found on line `}`
  125. ERROR: no method name found on line ``
  126. ERROR: no method name found on line `}`
  127. ERROR: no method name found on line `}`
  128. ERROR: no method name found on line ``
  129. ERROR: no method name found on line `}`
  130. ERROR: no method name found on line ``
  131. ERROR: no method name found on line `}`
  132. ERROR: no method name found on line `}`
  133. ERROR: no method name found on line ``
  134. ERROR: no method name found on line `continue;`
  135. ERROR: no method name found on line ``
  136. ERROR: no method name found on line `*/`
  137. ERROR: no method name found on line `}`
  138. ERROR: no method name found on line `*`
  139. ERROR: no method name found on line ``
  140. ERROR: no method name found on line `// Exclude non-editable markers like 'title' and 'sectionend'.`
  141. ERROR: no method name found on line `* @param WP_REST_Request $request Full details about the request.`
  142. ERROR: no method name found on line `*`
  143. ERROR: no method name found on line `* @param array $updated_settings Array of updated settings IDs.`
  144. ERROR: no method name found on line ``
  145. ERROR: no method name found on line ``
  146. private sanitize_setting_value( $setting_type, $value )
  147. ERROR: no method name found on line `*`
  148. ERROR: no method name found on line `*`
  149. ERROR: no method name found on line `* @param WP_REST_Request $request Full details about the request.`
  150. ERROR: no method name found on line `*`
  151. ERROR: no method name found on line ``
  152. ERROR: no method name found on line `// Get all account settings definitions.`
  153. ERROR: no method name found on line ``
  154. ERROR: no method name found on line ``
  155. ERROR: no method name found on line `* @return bool|WP_Error`
  156. ERROR: no method name found on line `/**`
  157. ERROR: no method name found on line `}`
  158. ERROR: no method name found on line `* @return bool|WP_Error`
  159. ERROR: no method name found on line `* @param WP_REST_Request $request Full details about the request.`
  160. ERROR: no method name found on line ``
  161. ERROR: no method name found on line `/**`
  162. ERROR: no method name found on line ``
  163. ERROR: no method name found on line `}`
  164. ERROR: no method name found on line ``
  165. ERROR: no method name found on line ``
  166. ERROR: no method name found on line `return true;`
  167. ERROR: no method name found on line ``
  168. ERROR: no method name found on line ``
  169. ERROR: no method name found on line `/**`
  170. ERROR: no method name found on line ``
  171. ERROR: no method name found on line ``
  172. ERROR: no method name found on line ``
  173. ERROR: no method name found on line `}`
  174. ERROR: no method name found on line `}`
  175. ERROR: no method name found on line `/**`
  176. ERROR: no method name found on line `}`
  177. ERROR: no method name found on line ``
  178. ERROR: no method name found on line `}`
  179. ERROR: no method name found on line ``
  180. ERROR: no method name found on line `*`
  181. ERROR: no method name found on line `} else {`
  182. ERROR: no method name found on line `}`
  183. ERROR: no method name found on line `return true;`
  184. ERROR: no method name found on line `$type = $def['type'] ?? '';`
  185. ERROR: no method name found on line `* @param WP_REST_Request $request Full details about the request.`
  186. ERROR: no method name found on line ``
  187. ERROR: no method name found on line `);`
  188. ERROR: no method name found on line `}`
  189. ERROR: no method name found on line `* @param WP_REST_Request $request Full details about the request.`
  190. ERROR: no method name found on line ``
  191. ERROR: no method name found on line `* Validate a setting value before updating.`
  192. ERROR: no method name found on line `}`
  193. ERROR: no method name found on line ``
  194. ERROR: no method name found on line `* @param WP_REST_Request $request Full details about the request.`
  195. ERROR: no method name found on line `protected $settings_account_instance;`
  196. ERROR: no method name found on line `* @var string`
  197. ERROR: no method name found on line ``
  198. ERROR: no method name found on line `*`
  199. ERROR: no method name found on line ``
  200. ERROR: no method name found on line ``
  201. ERROR: no method name found on line ``
  202. ERROR: no method name found on line `$validated_settings[ $setting_id ] = $sanitized_value;`
  203. ERROR: no method name found on line `}`
  204. ERROR: no method name found on line ``
  205. ERROR: no method name found on line ``
  206. ERROR: no method name found on line `}`
  207. ERROR: no method name found on line ``
  208. ERROR: no method name found on line ``
  209. ERROR: no method name found on line ``
  210. ERROR: no method name found on line `),`
  211. ERROR: no method name found on line ``
  212. ERROR: no method name found on line ``
  213. ERROR: no method name found on line ``
  214. ERROR: no method name found on line `* Register routes.`
  215. ERROR: no method name found on line `*`
  216. ERROR: no method name found on line `),`
  217. ERROR: no method name found on line ``
  218. ERROR: no method name found on line `$setting_type = $type_map[ $setting_type ] ?? $setting_type;`
  219. ERROR: no method name found on line `/**`
  220. ERROR: no method name found on line `/**`
  221. ERROR: no method name found on line ``
  222. ERROR: no method name found on line `* @internal`
  223. ERROR: no method name found on line ``
  224. ERROR: no method name found on line `// Ensure we have a scalar value for checkbox settings.`
  225. ERROR: no method name found on line ``
  226. ERROR: no method name found on line ``
  227. ERROR: no method name found on line ``
  228. ERROR: no method name found on line ``
  229. ERROR: no method name found on line ``
  230. ERROR: no method name found on line `case 'checkbox':`
  231. ERROR: no method name found on line `}`
  232. ERROR: no method name found on line ``
  233. ERROR: no method name found on line ``
  234. ERROR: no method name found on line ``
  235. ERROR: no method name found on line `'rest_forbidden',`
  236. ERROR: no method name found on line `/**`
  237. ERROR: no method name found on line `* @return bool|WP_Error`
  238. ERROR: no method name found on line `/**`
  239. ERROR: no method name found on line ``
  240. ERROR: no method name found on line `}`
  241. ERROR: no method name found on line ``
  242. ERROR: no method name found on line `*/`
  243. ERROR: no method name found on line `'/' . $this->rest_base,`
  244. ERROR: no method name found on line `require_once WC_ABSPATH . 'includes/admin/class-wc-admin-settings.php';`
  245. ERROR: no method name found on line ``
  246. ERROR: no method name found on line `*`
  247. ERROR: no method name found on line `*/`
  248. ERROR: no method name found on line `'rest_forbidden',`
  249. ERROR: no method name found on line ``
  250. ERROR: no method name found on line ``
  251. ERROR: no method name found on line `continue;`
  252. ERROR: no method name found on line ``
  253. ERROR: no method name found on line `// Ensure we have a scalar value for checkbox settings.`
  254. ERROR: no method name found on line ``
  255. ERROR: no method name found on line `// Normalize WooCommerce setting types to REST API schema types.`
  256. ERROR: no method name found on line `* @param WP_REST_Request $request Request object.`
  257. ERROR: no method name found on line `}`
  258. ERROR: no method name found on line `// Return updated settings.`
  259. ERROR: no method name found on line ``
  260. ERROR: no method name found on line ``
  261. ERROR: no method name found on line ``
  262. ERROR: no method name found on line `*/`
  263. ERROR: no method name found on line `/**`
  264. ERROR: no method name found on line `}`
  265. ERROR: no method name found on line `$this->schema = $schema;`
  266. ERROR: no method name found on line `*`
  267. ERROR: no method name found on line `}`
  268. ERROR: no method name found on line `* Register routes.`
  269. ERROR: no method name found on line ``
  270. ERROR: no method name found on line `*/`
  271. ERROR: no method name found on line `);`
  272. ERROR: no method name found on line `return $this->settings_account_instance;`
  273. ERROR: no method name found on line ``
  274. ERROR: no method name found on line `* @param WP_REST_Request $request Full details about the request.`
  275. ERROR: no method name found on line `*/`
  276. ERROR: no method name found on line ``
  277. ERROR: no method name found on line ``
  278. ERROR: no method name found on line `*`
  279. ERROR: no method name found on line `*`
  280. ERROR: no method name found on line `}`
  281. ERROR: no method name found on line `)`
  282. ERROR: no method name found on line `* @return bool|WP_Error`
  283. ERROR: no method name found on line `/**`
  284. ERROR: no method name found on line ``
  285. ERROR: no method name found on line ``
  286. ERROR: no method name found on line ``
  287. ERROR: no method name found on line `// Check if the request contains a 'values' field with the flat key-value mapping.`
  288. ERROR: no method name found on line ``
  289. ERROR: no method name found on line ``
  290. ERROR: no method name found on line `case 'text':`
  291. ERROR: no method name found on line `'woocommerce_rest_account_settings_error',`
  292. ERROR: no method name found on line `*`
  293. ERROR: no method name found on line `*/`
  294. ERROR: no method name found on line `* @internal`
  295. ERROR: no method name found on line `),`
  296. ERROR: no method name found on line `}`
  297. ERROR: no method name found on line `* @param AccountSettingsSchema $schema Schema class.`
  298. ERROR: no method name found on line `*/`
  299. ERROR: no method name found on line `}`
  300. ERROR: no method name found on line `}`
  301. ERROR: no method name found on line `/**`
  302. ERROR: no method name found on line `* @var WC_Settings_Accounts`
  303. ERROR: no method name found on line `* @param AccountSettingsSchema $schema Schema class.`
  304. ERROR: no method name found on line `* @param AccountSettingsSchema $schema Schema class.`
  305. ERROR: no method name found on line ``
  306. ERROR: no method name found on line `'rest_forbidden',`
  307. ERROR: no method name found on line `* Schema instance.`
  308. ERROR: no method name found on line ``
  309. ERROR: no method name found on line ``
  310. ERROR: no method name found on line ``
  311. ERROR: no method name found on line `* @return WC_Settings_Accounts`
  312. ERROR: no method name found on line `* @return WC_Settings_Accounts`
  313. ERROR: no method name found on line ``
  314. ERROR: no method name found on line `/**`
  315. ERROR: no method name found on line `/**`
  316. ERROR: no method name found on line `}`
  317. ERROR: no method name found on line `'rest_forbidden',`
  318. ERROR: no method name found on line `*/`
  319. ERROR: no method name found on line `'/' . $this->rest_base,`
  320. ERROR: no method name found on line `*/`
  321. ERROR: no method name found on line ``
  322. ERROR: no method name found on line `'methods' => WP_REST_Server::READABLE,`
  323. ERROR: no method name found on line ``
  324. ERROR: no method name found on line `}`
  325. ERROR: no method name found on line `*/`
  326. ERROR: no method name found on line `* Check permissions for updating account settings.`
  327. ERROR: no method name found on line `// Additional validation for specific settings.`
  328. ERROR: no method name found on line `}`
  329. ERROR: no method name found on line `*/`
  330. ERROR: no method name found on line ``
  331. ERROR: no method name found on line `}`
  332. ERROR: no method name found on line `return true;`
  333. ERROR: no method name found on line `try {`
  334. ERROR: no method name found on line `}`
  335. ERROR: no method name found on line `$values_to_update = $params['values'];`
  336. ERROR: no method name found on line `return $validation_result;`
  337. ERROR: no method name found on line `*`
  338. ERROR: no method name found on line ``
  339. ERROR: no method name found on line `default:`
  340. ERROR: no method name found on line `return 0;`
  341. ERROR: no method name found on line ``
  342. ERROR: no method name found on line `*`
  343. ERROR: no method name found on line `* @param WP_REST_Request $request Full details about the request.`
  344. ERROR: no method name found on line `* @param WP_REST_Request $request Full details about the request.`
  345. ERROR: no method name found on line `*`
  346. ERROR: no method name found on line ``
  347. ERROR: no method name found on line ``
  348. ERROR: no method name found on line ``
  349. ERROR: no method name found on line `* Get the endpoint args for item schema.`
  350. ERROR: no method name found on line ``
  351. ERROR: no method name found on line `* @param string $rest_base The REST base of the settings.`
  352. ERROR: no method name found on line `* @param array $updated_settings Array of updated settings IDs.`
  353. ERROR: no method name found on line `case 'text':`
  354. ERROR: no method name found on line `// No specific validation for account settings yet.`
  355. ERROR: no method name found on line ``
  356. ERROR: no method name found on line ``

Controller{} code WC 10.5.0

class Controller extends AbstractController {
	/**
	 * Route base.
	 *
	 * @var string
	 */
	protected $rest_base = 'settings/account';

	/**
	 * WC_Settings_Accounts instance.
	 *
	 * @var WC_Settings_Accounts
	 */
	protected $settings_account_instance;

	/**
	 * Schema instance.
	 *
	 * @var AccountSettingsSchema
	 */
	protected $schema;

	/**
	 * Initialize the controller.
	 *
	 * @param AccountSettingsSchema $schema Schema class.
	 * @internal
	 */
	final public function init( AccountSettingsSchema $schema ) {
		$this->schema = $schema;
	}

	/**
	 * Get the WC_Settings_Accounts instance.
	 *
	 * @return WC_Settings_Accounts
	 */
	private function get_settings_account_instance() {
		if ( is_null( $this->settings_account_instance ) ) {
			// We need to mock the admin environment to get the settings.
			if ( ! class_exists( 'WC_Admin_Settings' ) ) {
				require_once WC_ABSPATH . 'includes/admin/class-wc-admin-settings.php';
			}
			$this->settings_account_instance = new WC_Settings_Accounts();
		}
		return $this->settings_account_instance;
	}

	/**
	 * Register routes.
	 */
	public function register_routes() {
		register_rest_route(
			$this->namespace,
			'/' . $this->rest_base,
			array(
				array(
					'methods'             => WP_REST_Server::READABLE,
					'callback'            => array( $this, 'get_item' ),
					'permission_callback' => array( $this, 'get_item_permissions_check' ),
				),
				array(
					'methods'             => WP_REST_Server::EDITABLE,
					'callback'            => array( $this, 'update_item' ),
					'permission_callback' => array( $this, 'update_item_permissions_check' ),
					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
				),
				'schema' => array( $this, 'get_item_schema' ),
			)
		);
	}

	/**
	 * Check permissions for reading account settings.
	 *
	 * @param WP_REST_Request $request Full details about the request.
	 * @return bool|WP_Error
	 */
	public function get_item_permissions_check( $request ) {
		if ( ! wc_rest_check_manager_permissions( 'settings', 'read' ) ) {
			return new WP_Error(
				'rest_forbidden',
				__( 'Sorry, you are not allowed to access account settings.', 'woocommerce' ),
				array( 'status' => rest_authorization_required_code() )
			);
		}
		return true;
	}

	/**
	 * Check permissions for updating account settings.
	 *
	 * @param WP_REST_Request $request Full details about the request.
	 * @return bool|WP_Error
	 */
	public function update_item_permissions_check( $request ) {
		if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
			return new WP_Error(
				'rest_forbidden',
				__( 'Sorry, you are not allowed to edit account settings.', 'woocommerce' ),
				array( 'status' => rest_authorization_required_code() )
			);
		}
		return true;
	}

	/**
	 * Get account settings.
	 *
	 * @param WP_REST_Request $request Full details about the request.
	 * @return WP_REST_Response|WP_Error
	 */
	public function get_item( $request ) {
		try {
			$settings = $this->get_all_settings();
		} catch ( \Exception $e ) {
			return new WP_Error(
				'woocommerce_rest_account_settings_error',
				$e->getMessage(),
				array( 'status' => 500 )
			);
		}

		$response = $this->get_item_response( $settings, $request );
		return rest_ensure_response( $response );
	}

	/**
	 * Update account settings.
	 *
	 * @param WP_REST_Request $request Full details about the request.
	 * @return WP_REST_Response|WP_Error
	 */
	public function update_item( $request ) {
		$params = $request->get_json_params();

		if ( ! is_array( $params ) || empty( $params ) ) {
			return new WP_Error(
				'rest_invalid_param',
				__( 'Invalid or empty request body.', 'woocommerce' ),
				array( 'status' => 400 )
			);
		}

		// Check if the request contains a 'values' field with the flat key-value mapping.
		$values_to_update = array();
		if ( isset( $params['values'] ) && is_array( $params['values'] ) ) {
			$values_to_update = $params['values'];
		} else {
			// Fallback to the old format for backward compatibility.
			$values_to_update = $params;
		}

		// Get all account settings definitions.
		$settings       = $this->get_all_settings();
		$settings_by_id = array_column( $settings, null, 'id' );

		// Exclude non-editable markers like 'title' and 'sectionend'.
		$settings_by_id = array_filter(
			$settings_by_id,
			static function ( $def ) {
				$type = $def['type'] ?? '';
				return isset( $def['id'] ) && ! in_array( $type, array( 'title', 'sectionend' ), true );
			}
		);

		$valid_setting_ids  = array_keys( $settings_by_id );
		$validated_settings = array();

		// Process each setting in the payload.
		foreach ( $values_to_update as $setting_id => $setting_value ) {
			// Sanitize the setting ID.
			$setting_id = sanitize_text_field( $setting_id );

			// Security check: only allow updating valid WooCommerce account settings.
			if ( ! in_array( $setting_id, $valid_setting_ids, true ) ) {
				continue;
			}

			// Sanitize the value based on the setting type.
			$setting_definition = $settings_by_id[ $setting_id ];
			$setting_type       = $setting_definition['type'] ?? 'text';
			$sanitized_value    = $this->sanitize_setting_value( $setting_type, $setting_value );

			// Additional validation for specific settings.
			$validation_result = $this->validate_setting_value( $setting_id, $sanitized_value );
			if ( is_wp_error( $validation_result ) ) {
				return $validation_result;
			}

			// Store validated values first.
			$validated_settings[ $setting_id ] = $sanitized_value;
		}

		// After validation loop, update all settings.
		$updated_settings = array();
		foreach ( $validated_settings as $setting_id => $value ) {
			$update_result = update_option( $setting_id, $value );
			if ( $update_result ) {
				$updated_settings[] = $setting_id;
			}
		}

		// Log the update if settings were changed.
		if ( ! empty( $updated_settings ) ) {
			/**
			* Fires when WooCommerce settings are updated.
			*
			* @param array $updated_settings Array of updated settings IDs.
			* @param string $rest_base The REST base of the settings.
			* @since 4.0.0
			*/
			do_action( 'woocommerce_settings_updated', $updated_settings, $this->rest_base );
		}

		// Get all settings after update.
		$settings = $this->get_all_settings();

		// Return updated settings.
		$response = $this->get_item_response( $settings, $request );
		return rest_ensure_response( $response );
	}

	/**
	 * Validate a setting value before updating.
	 *
	 * @param string $setting_id Setting ID.
	 * @param mixed  $value      Setting value.
	 * @return bool|WP_Error True if valid, WP_Error if invalid.
	 */
	private function validate_setting_value( $setting_id, $value ) {
		// No specific validation for account settings yet.
		return true;
	}

	/**
	 * Sanitize setting value based on its type.
	 *
	 * @param string $setting_type Setting type.
	 * @param mixed  $value        Setting value.
	 * @return mixed Sanitized value.
	 */
	private function sanitize_setting_value( $setting_type, $value ) {
		// Normalize WooCommerce setting types to REST API schema types.
		$type_map     = array(
			'single_select_page'             => 'select',
			'single_select_page_with_search' => 'select',
		);
		$setting_type = $type_map[ $setting_type ] ?? $setting_type;

		switch ( $setting_type ) {
			case 'text':
				return sanitize_text_field( $value );

			case 'textarea':
				return sanitize_textarea_field( $value );

			case 'number':
				if ( ! is_numeric( $value ) ) {
					return 0;
				}

				return filter_var( $value, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE ) ?? floatval( $value );

			case 'checkbox':
				// Ensure we have a scalar value for checkbox settings.
				if ( is_array( $value ) ) {
					$value = ! empty( $value ); // Convert array to boolean based on emptiness.
				}
				return wc_bool_to_string( $value );

			case 'select':
				return sanitize_text_field( $value );

			case 'multiselect':
				if ( is_array( $value ) ) {
					return array_map( 'sanitize_text_field', $value );
				}

				if ( is_string( $value ) ) {
					return array( sanitize_text_field( $value ) );
				}

				if ( is_scalar( $value ) ) {
					return array( sanitize_text_field( (string) $value ) );
				}

				return array();

			default:
				// If a type is not explicitly handled, treat it as text.
				return sanitize_text_field( $value );
		}
	}

	/**
	 * Get all account settings definitions.
	 *
	 * @return array Array of setting definitions.
	 */
	private function get_all_settings(): array {
		$settings_instance = $this->get_settings_account_instance();
		return $settings_instance->get_settings();
	}

	/**
	 * Get the schema for the current resource.
	 *
	 * @return array
	 */
	public function get_schema(): array {
		return $this->schema->get_item_schema();
	}

	/**
	 * Get the item schema for the controller.
	 *
	 * @return array
	 */
	public function get_item_schema(): array {
		return $this->get_schema();
	}

	/**
	 * Get the item response for a single settings group.
	 *
	 * @param mixed           $item Settings data.
	 * @param WP_REST_Request $request Request object.
	 * @return array
	 */
	protected function get_item_response( $item, WP_REST_Request $request ): array {
		return $this->schema->get_item_response( $item, $request );
	}

	/**
	 * Get the endpoint args for item schema.
	 *
	 * @param string $method HTTP method of the request.
	 * @return array Endpoint arguments.
	 */
	public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ): array {
		return rest_get_endpoint_args_for_schema( $this->get_item_schema(), $method );
	}
}