Commit 565bc3cdcb2 for woocommerce

commit 565bc3cdcb285c4b7e9494b2a5f8196e0047d4fd
Author: Chris Lilitsas <1105590+xristos3490@users.noreply.github.com>
Date:   Wed Sep 23 13:49:57 2026 +0300

    Fix Screen Options fatal with Back in Stock Notifications (trunk) (#68997)

    Fix Screen Options fatal with Back in Stock Notifications (#68986)

    * fix(stock-notifications): prevent Screen Options fatal

    Back in Stock Notifications attaches to the global set-screen-option hook. WordPress passes false for unrelated custom options, but the callback declared an int return type and stopped the save with a TypeError.

    Allow the hook status to pass through and cover both unrelated and handled options.

    * chore(changelog): Add entry for Screen Options fatal fix

    The Screen Options fix changes merchant-visible behavior. Record the correction in the WooCommerce release changelog.

    * test(stock-notifications): simplify Screen Options regression tests

    The regression tests registered a controller and manually removed its hooks after each assertion. WC_Unit_Test_Case already restores the hook snapshot between tests, so that cleanup duplicated the base lifecycle. Remove the teardown and unused controller property while keeping coverage of the global Screen Options filter.

    (cherry picked from commit d3d6ed93478aa6520e66c25d519624dc11afca73)

    Co-authored-by: Oleksandr Aratovskyi <79862886+oaratovskyi@users.noreply.github.com>

diff --git a/plugins/woocommerce/changelog/fix-stock-notifications-screen-options-fatal b/plugins/woocommerce/changelog/fix-stock-notifications-screen-options-fatal
new file mode 100644
index 00000000000..49646d4b89e
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-stock-notifications-screen-options-fatal
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix a fatal error when saving Screen Options with Back in Stock Notifications enabled.
diff --git a/plugins/woocommerce/src/Internal/StockNotifications/Admin/MenusController.php b/plugins/woocommerce/src/Internal/StockNotifications/Admin/MenusController.php
index c8b96041b51..b58f684d303 100644
--- a/plugins/woocommerce/src/Internal/StockNotifications/Admin/MenusController.php
+++ b/plugins/woocommerce/src/Internal/StockNotifications/Admin/MenusController.php
@@ -86,13 +86,13 @@ class MenusController {
 	/**
 	 * Save screen options.
 	 *
-	 * @param int    $status The status of the screen option.
-	 * @param string $option The option name.
-	 * @param int    $value The value of the screen option.
+	 * @param bool|int $status The status of the screen option.
+	 * @param string   $option The option name.
+	 * @param int      $value The value of the screen option.
 	 *
-	 * @return int
+	 * @return bool|int
 	 */
-	public function set_screen_option( $status, $option, $value ): int {
+	public function set_screen_option( $status, $option, $value ) {
 		if ( 'stock_notifications_per_page' === $option ) {
 			return (int) $value;
 		}
diff --git a/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Admin/MenusControllerTests.php b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Admin/MenusControllerTests.php
new file mode 100644
index 00000000000..79396a749c0
--- /dev/null
+++ b/plugins/woocommerce/tests/php/src/Internal/StockNotifications/Admin/MenusControllerTests.php
@@ -0,0 +1,35 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace Automattic\WooCommerce\Tests\Internal\StockNotifications\Admin;
+
+use Automattic\WooCommerce\Internal\StockNotifications\Admin\MenusController;
+
+/**
+ * Tests for the Customer Stock Notifications admin menu controller.
+ */
+class MenusControllerTests extends \WC_Unit_Test_Case {
+
+	/**
+	 * Register the controller's hooks.
+	 */
+	public function setUp(): void {
+		parent::setUp();
+		new MenusController();
+	}
+
+	/**
+	 * @testdox An unrelated screen option leaves WordPress's false status unchanged.
+	 */
+	public function test_unrelated_screen_option_preserves_false_status(): void {
+		$this->assertFalse( apply_filters( 'set-screen-option', false, 'edit_approved_directories_per_page', 25 ) );
+	}
+
+	/**
+	 * @testdox The stock notifications screen option saves its submitted page size.
+	 */
+	public function test_stock_notifications_screen_option_returns_page_size(): void {
+		$this->assertSame( 25, apply_filters( 'set-screen-option', false, 'stock_notifications_per_page', '25' ) );
+	}
+}