Commit ede1f104087 for woocommerce

commit ede1f1040878e9edf589803ebc826ea9192c3fbb
Author: Akanshu Singh <61490175+singhakanshu00@users.noreply.github.com>
Date:   Sat Oct 10 01:31:54 2026 +0530

    fix: exclude providerless fulfillments from the Other provider filter (#69217)

diff --git a/plugins/woocommerce/changelog/fix-other-provider-filter-excludes-empty b/plugins/woocommerce/changelog/fix-other-provider-filter-excludes-empty
new file mode 100644
index 00000000000..8e93d026ebe
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-other-provider-filter-excludes-empty
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Stop listing fulfillments without a shipping provider under the "Other" shipping provider filter.
diff --git a/plugins/woocommerce/src/Admin/Features/Fulfillments/FulfillmentsRenderer.php b/plugins/woocommerce/src/Admin/Features/Fulfillments/FulfillmentsRenderer.php
index b91cbcf22b9..51261f7fb97 100644
--- a/plugins/woocommerce/src/Admin/Features/Fulfillments/FulfillmentsRenderer.php
+++ b/plugins/woocommerce/src/Admin/Features/Fulfillments/FulfillmentsRenderer.php
@@ -693,14 +693,20 @@ class FulfillmentsRenderer {
 						INNER JOIN {$meta_table} m ON f.fulfillment_id = m.fulfillment_id
 						WHERE m.meta_key = %s
 						AND m.meta_value IS NOT NULL
-						AND m.meta_value != ''
+						AND m.meta_value NOT IN ( '', %s )
 						AND f.date_deleted IS NULL
 						AND m.date_deleted IS NULL",
-						'_shipment_provider'
+						'_shipment_provider',
+						wp_json_encode( '' )
 					)
 				);
 			} else {
-				$placeholders = implode( ',', array_fill( 0, count( $known_keys ), '%s' ) );
+				// Exclude known providers and both empty string and the JSON-encoded one the data store writes.
+				$excluded     = array_merge(
+					array( '', wp_json_encode( '' ) ),
+					array_map( 'wp_json_encode', $known_keys )
+				);
+				$placeholders = implode( ',', array_fill( 0, count( $excluded ), '%s' ) );
 				$results      = $wpdb->get_col(
 					$wpdb->prepare(
 						"SELECT DISTINCT f.entity_id
@@ -709,10 +715,9 @@ class FulfillmentsRenderer {
 						WHERE m.meta_key = '_shipment_provider'
 						AND m.meta_value NOT IN ({$placeholders})
 						AND m.meta_value IS NOT NULL
-						AND m.meta_value != ''
 						AND f.date_deleted IS NULL
 						AND m.date_deleted IS NULL",
-						...array_map( 'wp_json_encode', $known_keys )
+						...$excluded
 					)
 				);
 			}
diff --git a/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentsRendererTest.php b/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentsRendererTest.php
index af19ae074b5..e1548e50699 100644
--- a/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentsRendererTest.php
+++ b/plugins/woocommerce/tests/php/src/Admin/Features/Fulfillments/FulfillmentsRendererTest.php
@@ -7,7 +7,9 @@ use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableControlle
 use Automattic\WooCommerce\Admin\Features\Fulfillments\Fulfillment;
 use Automattic\WooCommerce\Admin\Features\Fulfillments\FulfillmentsRenderer;
 use Automattic\WooCommerce\Admin\Features\Fulfillments\Providers\AmazonLogisticsShippingProvider;
+use Automattic\WooCommerce\Admin\Features\Fulfillments\Providers\DHLShippingProvider;
 use Automattic\WooCommerce\RestApi\UnitTests\Helpers\OrderHelper;
+use Automattic\WooCommerce\Tests\Admin\Features\Fulfillments\Helpers\FulfillmentsHelper;
 use WC_Helper_Order;
 use WC_Helper_Product;
 use WC_Order;
@@ -395,6 +397,85 @@ class FulfillmentsRendererTest extends \WC_Unit_Test_Case {
 		$this->assertStringContainsString( 'var wcFulfillmentSettings', $output );
 	}

+	/**
+	 * @testdox Should list only unrecognized shipping providers under the "Other" filter.
+	 * @testWith [true]
+	 *           [false]
+	 *
+	 * @param bool $is_known_providers Whether the known shipping provider list is populated.
+	 */
+	public function test_other_shipping_provider_filter_excludes_fulfillments_without_a_provider( bool $is_known_providers ): void {
+		add_filter(
+			'woocommerce_fulfillment_shipping_providers',
+			static function () use ( $is_known_providers ): array {
+				return $is_known_providers ? array( DHLShippingProvider::class ) : array();
+			},
+			999
+		);
+
+		$unknown_provider_order_id = $this->create_order_with_shipment_provider( 'totally-unknown-carrier' );
+		$empty_provider_order_id   = $this->create_order_with_shipment_provider( '' );
+		$known_provider_order_id   = $this->create_order_with_shipment_provider( 'dhl' );
+
+		$_GET['shipping_provider'] = '__other__';
+		$args                      = $this->renderer->filter_orders_by_shipping_provider( array() );
+		unset( $_GET['shipping_provider'] );
+
+		$this->assertContains(
+			$unknown_provider_order_id,
+			$args['post__in'],
+			'A provider outside the known list should match the "Other" filter'
+		);
+		$this->assertNotContains(
+			$empty_provider_order_id,
+			$args['post__in'],
+			'A fulfillment saved without a shipping provider should not match the "Other" filter'
+		);
+
+		if ( $is_known_providers ) {
+			$this->assertNotContains(
+				$known_provider_order_id,
+				$args['post__in'],
+				'A known provider should not match the "Other" filter'
+			);
+		} else {
+			$this->assertContains(
+				$known_provider_order_id,
+				$args['post__in'],
+				'With no known providers, any non-empty provider should match the "Other" filter'
+			);
+		}
+	}
+
+	/**
+	 * Create an order with a single fulfillment carrying the given shipping provider.
+	 *
+	 * @param string $shipment_provider The provider key to store on the fulfillment.
+	 * @return int The order ID.
+	 */
+	private function create_order_with_shipment_provider( string $shipment_provider ): int {
+		$order = OrderHelper::create_order( get_current_user_id() );
+
+		FulfillmentsHelper::create_fulfillment(
+			array(
+				'entity_type' => WC_Order::class,
+				'entity_id'   => (string) $order->get_id(),
+				'status'      => 'fulfilled',
+			),
+			array(
+				'_shipment_provider' => $shipment_provider,
+				'_items'             => array(
+					array(
+						'item_id' => 1,
+						'qty'     => 1,
+					),
+				),
+			)
+		);
+
+		return $order->get_id();
+	}
+
 	/**
 	 * @testdox Filtering by a specific provider returns only the orders whose fulfillment uses it.
 	 */