Commit a154e92eca2 for woocommerce

commit a154e92eca2f61edc75868efd00c8204fafd6649
Author: Luigi Teschio <gigitux@gmail.com>
Date:   Mon Nov 23 17:39:08 2026 +0100

    Require manage_woocommerce for the legacy wc-admin options endpoint (#71200)

    (cherry picked from commit 86ca76ae0e8c87b59898281b826d90b5e73964f7)

    Co-authored-by: Darren Ethier <darren@roughsmootheng.in>

diff --git a/plugins/woocommerce/src/Admin/API/Options.php b/plugins/woocommerce/src/Admin/API/Options.php
index 71698f9a91c..70c72b35432 100644
--- a/plugins/woocommerce/src/Admin/API/Options.php
+++ b/plugins/woocommerce/src/Admin/API/Options.php
@@ -155,7 +155,7 @@ class Options extends \WC_REST_Data_Controller {
 	 * @return array
 	 */
 	public static function get_default_option_permissions() {
-		$is_woocommerce_admin = \Automattic\WooCommerce\Internal\Admin\Homescreen::is_admin_user();
+		$is_woocommerce_admin = current_user_can( 'manage_woocommerce' );

 		/**
 		 * IMPORTANT: This list is frozen for legacy support.
diff --git a/plugins/woocommerce/tests/php/src/Admin/API/OptionsPermissionsTest.php b/plugins/woocommerce/tests/php/src/Admin/API/OptionsPermissionsTest.php
index c8d409e0add..deaab2fa5f5 100644
--- a/plugins/woocommerce/tests/php/src/Admin/API/OptionsPermissionsTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/API/OptionsPermissionsTest.php
@@ -85,6 +85,34 @@ class OptionsPermissionsTest extends WC_REST_Unit_Test_Case {
 		);
 	}

+	/**
+	 * @testdox Allowlisted options require manage_woocommerce.
+	 * @testWith ["shop_manager", 200]
+	 *           ["order_only", 403]
+	 *
+	 * @param string $user_type Tested user: a Shop Manager, or a user with only edit_others_shop_orders.
+	 * @param int    $expected_status Expected status for both the read and the write.
+	 */
+	public function test_allowlisted_options_require_manage_woocommerce( string $user_type, int $expected_status ): void {
+		if ( 'order_only' === $user_type ) {
+			$user = self::factory()->user->create_and_get( array( 'role' => 'subscriber' ) );
+			$user->add_cap( 'edit_others_shop_orders' );
+		} else {
+			$user = self::factory()->user->create_and_get( array( 'role' => 'shop_manager' ) );
+		}
+		wp_set_current_user( $user->ID );
+		$original_value = array( array( 'account_number' => 'original' ) );
+		$new_value      = array( array( 'account_number' => 'changed' ) );
+		update_option( 'woocommerce_bacs_accounts', $original_value );
+
+		$read_response = $this->get_options( array( 'woocommerce_bacs_accounts' ) );
+		$this->assertSame( $expected_status, $read_response->get_status(), "Unexpected read status for {$user_type}." );
+
+		$write_response = $this->post_options( array( 'woocommerce_bacs_accounts' => $new_value ) );
+		$this->assertSame( $expected_status, $write_response->get_status(), "Unexpected write status for {$user_type}." );
+		$this->assertSame( 200 === $expected_status ? $new_value : $original_value, get_option( 'woocommerce_bacs_accounts' ), "Unexpected stored value for {$user_type}." );
+	}
+
 	/**
 	 * @testdox The legacy filter can explicitly grant option access.
 	 */