Commit df14861c456 for woocommerce
commit df14861c4568c73f3725822ce41e53144c747ec0
Author: Wesley Rosa <wesleyjrosa@gmail.com>
Date: Wed Jul 22 09:20:09 2026 -0300
Add StockDisplayFormat enum class for woocommerce_stock_format option values (#66802)
Add StockDisplayFormat enum class and adopt it across the codebase
diff --git a/plugins/woocommerce/changelog/add-stock-display-format-enum b/plugins/woocommerce/changelog/add-stock-display-format-enum
new file mode 100644
index 00000000000..2d14de30c39
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-stock-display-format-enum
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Add StockDisplayFormat enum class for woocommerce_stock_format option values and adopt it in the Store API product schema.
diff --git a/plugins/woocommerce/src/Enums/README.md b/plugins/woocommerce/src/Enums/README.md
index bca24cc9812..14c862137b3 100644
--- a/plugins/woocommerce/src/Enums/README.md
+++ b/plugins/woocommerce/src/Enums/README.md
@@ -17,6 +17,7 @@ The enum classes make it easier to reference string values and avoid typos. They
- [ProductStatus](./ProductStatus.php) - Enumerates the possible statuses of a product.
- [ProductStockStatus](./ProductStockStatus.php) - Enumerates the possible stock statuses of a product.
- [ProductType](./ProductType.php) - Enumerates the possible types of a product.
+- [StockDisplayFormat](./StockDisplayFormat.php) - Enumerates the possible values of the `woocommerce_stock_format` option.
- [TaxBasedOn](./TaxBasedOn.php) - Enumerates the possible values of the `woocommerce_tax_based_on` option.
- [TaxDisplayMode](./TaxDisplayMode.php) - Enumerates the possible values of the `woocommerce_tax_display_shop` and `woocommerce_tax_display_cart` options.
- [WeightUnit](./WeightUnit.php) - Enumerates the possible values of the `woocommerce_weight_unit` option.
diff --git a/plugins/woocommerce/src/Enums/StockDisplayFormat.php b/plugins/woocommerce/src/Enums/StockDisplayFormat.php
new file mode 100644
index 00000000000..2895fe2934f
--- /dev/null
+++ b/plugins/woocommerce/src/Enums/StockDisplayFormat.php
@@ -0,0 +1,33 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace Automattic\WooCommerce\Enums;
+
+/**
+ * Enum class for the possible values of the 'woocommerce_stock_format' option.
+ *
+ * @since 11.1.0
+ */
+final class StockDisplayFormat {
+ /**
+ * Always show the quantity remaining in stock (e.g. "12 in stock").
+ *
+ * @var string
+ */
+ public const ALWAYS_SHOW = '';
+
+ /**
+ * Only show the quantity remaining in stock when it is low (e.g. "Only 2 left in stock").
+ *
+ * @var string
+ */
+ public const LOW_AMOUNT = 'low_amount';
+
+ /**
+ * Never show the quantity remaining in stock.
+ *
+ * @var string
+ */
+ public const NEVER = 'no_amount';
+}
diff --git a/plugins/woocommerce/src/StoreApi/Schemas/V1/ProductSchema.php b/plugins/woocommerce/src/StoreApi/Schemas/V1/ProductSchema.php
index 91ec9ebac16..c9accd279b3 100644
--- a/plugins/woocommerce/src/StoreApi/Schemas/V1/ProductSchema.php
+++ b/plugins/woocommerce/src/StoreApi/Schemas/V1/ProductSchema.php
@@ -7,6 +7,7 @@ use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema;
use Automattic\WooCommerce\StoreApi\Utilities\QuantityLimits;
use Automattic\WooCommerce\Blocks\Utils\ProductAvailabilityUtils;
use Automattic\WooCommerce\Enums\ProductStockStatus;
+use Automattic\WooCommerce\Enums\StockDisplayFormat;
use Automattic\WooCommerce\Enums\TaxDisplayMode;
/**
@@ -693,7 +694,7 @@ class ProductSchema extends AbstractSchema {
$stock_format = get_option( 'woocommerce_stock_format' );
// Don't show the low stock badge if the settings doesn't allow it.
- if ( 'no_amount' === $stock_format ) {
+ if ( StockDisplayFormat::NEVER === $stock_format ) {
return null;
}