Commit ad8ab163d8a for woocommerce
commit ad8ab163d8a0110fc053785be6bf7b5bd653a87e
Author: James Kemp <me@jckemp.com>
Date: Mon Apr 27 22:53:12 2026 +0100
Add stock and product status indicators to admin order product selector (#64426)
* Add stock and product status indicators to admin order product selector
* Add changefile(s) from automation for the following project(s): woocommerce
* Regenerate PHPStan baseline to remove resolved errors
* Fix stock quantity format specifier to preserve filtered values
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/64426-add-stock-status-admin-order-selector b/plugins/woocommerce/changelog/64426-add-stock-status-admin-order-selector
new file mode 100644
index 00000000000..1d62a97c6f1
--- /dev/null
+++ b/plugins/woocommerce/changelog/64426-add-stock-status-admin-order-selector
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Add stock status and product status indicators to the admin order product selector so admins can see which variations are out of stock, on backorder, or disabled.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/class-wc-ajax.php b/plugins/woocommerce/includes/class-wc-ajax.php
index f605d3d65f2..55369cc6c64 100644
--- a/plugins/woocommerce/includes/class-wc-ajax.php
+++ b/plugins/woocommerce/includes/class-wc-ajax.php
@@ -1811,7 +1811,7 @@ class WC_AJAX {
foreach ( $ids as $id ) {
$product_object = wc_get_product( $id );
- if ( ! wc_products_array_filter_readable( $product_object ) ) {
+ if ( ! $product_object || ! wc_products_array_filter_readable( $product_object ) ) {
continue;
}
@@ -1822,11 +1822,33 @@ class WC_AJAX {
continue;
}
- if ( $managing_stock && ! empty( $_GET['display_stock'] ) ) {
- $stock_amount = $product_object->get_stock_quantity();
- /* Translators: %d stock amount */
- $formatted_name .= ' – ' . sprintf( __( 'Stock: %d', 'woocommerce' ), wc_format_stock_quantity_for_display( $stock_amount, $product_object ) );
- }
+ if ( ! empty( $_GET['display_stock'] ) ) {
+ $stock_parts = array();
+
+ if ( $managing_stock ) {
+ $stock_amount = $product_object->get_stock_quantity();
+ /* Translators: %s stock amount */
+ $stock_parts[] = sprintf( __( 'Stock: %s', 'woocommerce' ), wc_format_stock_quantity_for_display( $stock_amount, $product_object ) );
+ }
+
+ $stock_status = $product_object->get_stock_status();
+ if ( ProductStockStatus::OUT_OF_STOCK === $stock_status ) {
+ $stock_parts[] = __( 'Out of stock', 'woocommerce' );
+ } elseif ( ProductStockStatus::ON_BACKORDER === $stock_status ) {
+ $stock_parts[] = __( 'On backorder', 'woocommerce' );
+ }
+
+ if ( ! empty( $stock_parts ) ) {
+ $formatted_name .= ' (' . implode( ' – ', $stock_parts ) . ')';
+ }
+
+ $product_status = $product_object->get_status();
+ if ( ProductStatus::PRIVATE === $product_status ) {
+ $formatted_name .= ' (' . __( 'Disabled', 'woocommerce' ) . ')';
+ } elseif ( ProductStatus::DRAFT === $product_status ) {
+ $formatted_name .= ' (' . __( 'Draft', 'woocommerce' ) . ')';
+ }
+ }//end if
$products[ $product_object->get_id() ] = rawurldecode( wp_strip_all_tags( $formatted_name ) );
}
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 884312d580a..3600a214636 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -8721,13 +8721,13 @@ parameters:
-
message: '#^Cannot call method get_formatted_name\(\) on WC_Product\|false\|null\.$#'
identifier: method.nonObject
- count: 2
+ count: 1
path: includes/class-wc-ajax.php
-
message: '#^Cannot call method get_id\(\) on WC_Product\|false\|null\.$#'
identifier: method.nonObject
- count: 5
+ count: 4
path: includes/class-wc-ajax.php
-
@@ -8766,12 +8766,6 @@ parameters:
count: 1
path: includes/class-wc-ajax.php
- -
- message: '#^Cannot call method get_stock_quantity\(\) on WC_Product\|false\|null\.$#'
- identifier: method.nonObject
- count: 1
- path: includes/class-wc-ajax.php
-
-
message: '#^Cannot call method get_total\(\) on WC_Order\|WC_Order_Refund\|false\.$#'
identifier: method.nonObject
@@ -8784,12 +8778,6 @@ parameters:
count: 2
path: includes/class-wc-ajax.php
- -
- message: '#^Cannot call method get_type\(\) on WC_Product\|false\|null\.$#'
- identifier: method.nonObject
- count: 1
- path: includes/class-wc-ajax.php
-
-
message: '#^Cannot call method get_zone_name\(\) on bool\|WC_Shipping_Zone\.$#'
identifier: method.nonObject
@@ -8805,7 +8793,7 @@ parameters:
-
message: '#^Cannot call method managing_stock\(\) on WC_Product\|false\|null\.$#'
identifier: method.nonObject
- count: 3
+ count: 2
path: includes/class-wc-ajax.php
-
@@ -8994,12 +8982,6 @@ parameters:
count: 1
path: includes/class-wc-ajax.php
- -
- message: '#^Parameter \#1 \$product of function wc_products_array_filter_readable expects WC_Product, WC_Product\|false\|null given\.$#'
- identifier: argument.type
- count: 1
- path: includes/class-wc-ajax.php
-
-
message: '#^Parameter \#1 \$product_object of function wc_render_invalid_variation_notice expects WC_Product, WC_Product\|false\|null given\.$#'
identifier: argument.type
@@ -9144,12 +9126,6 @@ parameters:
count: 1
path: includes/class-wc-ajax.php
- -
- message: '#^Parameter \#2 \$product of function wc_format_stock_quantity_for_display expects WC_Product, WC_Product\|false\|null given\.$#'
- identifier: argument.type
- count: 1
- path: includes/class-wc-ajax.php
-
-
message: '#^Parameter \#2 \$product_type of static method WC_Product_Factory\:\:get_product_classname\(\) expects string, array\|string given\.$#'
identifier: argument.type