Commit 9595ba62c85 for woocommerce
commit 9595ba62c85f02eca340ee43419ea83d0afce3c6
Author: Taha Paksu <3295+tpaksu@users.noreply.github.com>
Date: Fri Apr 10 19:30:54 2026 +0300
Fix shipping provider filter meta key mismatch (#64096)
* Fix shipping provider filter using wrong meta key in SQL queries
The fulfillment model stores the provider under `_shipment_provider`,
but the filter queries and the in-use check were looking for
`_shipping_provider`, causing the filter to always return no results
and allowing deletion of providers still in use.
* Add changelog entry for shipping provider filter fix
* JSON-encode values when comparing against fulfillment meta
The data store saves meta values with wp_json_encode(), so a string
like "dhl" is stored as "\"dhl\"" in the database. The filter queries
and the in-use check were comparing raw strings, which never matched.
diff --git a/plugins/woocommerce/changelog/fix-shipping-provider-filter-meta-key-mismatch b/plugins/woocommerce/changelog/fix-shipping-provider-filter-meta-key-mismatch
new file mode 100644
index 00000000000..b5eb9a757c8
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-shipping-provider-filter-meta-key-mismatch
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix shipping provider filter on orders list using wrong meta key, causing no results to appear.
diff --git a/plugins/woocommerce/includes/class-wc-ajax.php b/plugins/woocommerce/includes/class-wc-ajax.php
index 7851b3ee695..2df165ee07c 100644
--- a/plugins/woocommerce/includes/class-wc-ajax.php
+++ b/plugins/woocommerce/includes/class-wc-ajax.php
@@ -4057,12 +4057,12 @@ class WC_AJAX {
$wpdb->prepare(
"SELECT 1 FROM {$fulfillments_table} f
INNER JOIN {$meta_table} m ON f.fulfillment_id = m.fulfillment_id
- WHERE m.meta_key = '_shipping_provider'
+ WHERE m.meta_key = '_shipment_provider'
AND m.meta_value = %s
AND f.date_deleted IS NULL
AND m.date_deleted IS NULL
LIMIT 1",
- $provider_slug
+ wp_json_encode( $provider_slug )
)
);
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
diff --git a/plugins/woocommerce/src/Admin/Features/Fulfillments/FulfillmentsRenderer.php b/plugins/woocommerce/src/Admin/Features/Fulfillments/FulfillmentsRenderer.php
index f6511f73a48..f8e6d232cd7 100644
--- a/plugins/woocommerce/src/Admin/Features/Fulfillments/FulfillmentsRenderer.php
+++ b/plugins/woocommerce/src/Admin/Features/Fulfillments/FulfillmentsRenderer.php
@@ -687,7 +687,7 @@ class FulfillmentsRenderer {
AND m.meta_value != ''
AND f.date_deleted IS NULL
AND m.date_deleted IS NULL",
- '_shipping_provider'
+ '_shipment_provider'
)
);
} else {
@@ -697,13 +697,13 @@ class FulfillmentsRenderer {
"SELECT DISTINCT f.entity_id
FROM {$fulfillments_table} f
INNER JOIN {$meta_table} m ON f.fulfillment_id = m.fulfillment_id
- WHERE m.meta_key = '_shipping_provider'
+ 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",
- ...$known_keys
+ ...array_map( 'wp_json_encode', $known_keys )
)
);
}
@@ -713,11 +713,11 @@ class FulfillmentsRenderer {
"SELECT DISTINCT f.entity_id
FROM {$fulfillments_table} f
INNER JOIN {$meta_table} m ON f.fulfillment_id = m.fulfillment_id
- WHERE m.meta_key = '_shipping_provider'
+ WHERE m.meta_key = '_shipment_provider'
AND m.meta_value = %s
AND f.date_deleted IS NULL
AND m.date_deleted IS NULL",
- $shipping_provider
+ wp_json_encode( $shipping_provider )
)
);
}