Commit 2bcf9e0a63d for woocommerce
commit 2bcf9e0a63dcfb18e5961bf1c63fa7aec7552dce
Author: Wesley Rosa <wesleyjrosa@gmail.com>
Date: Fri Jul 3 09:10:40 2026 -0300
Add CurrencyPosition enum class for woocommerce_currency_pos option values (#66128)
Add CurrencyPosition enum class and adopt it across the codebase
diff --git a/plugins/woocommerce/changelog/add-currency-position-enum b/plugins/woocommerce/changelog/add-currency-position-enum
new file mode 100644
index 00000000000..344d4c55669
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-currency-position-enum
@@ -0,0 +1,4 @@
+Significance: minor
+Type: add
+
+Add CurrencyPosition enum class for woocommerce_currency_pos option values and adopt it in the Store API and Marketing Campaigns REST API.
diff --git a/plugins/woocommerce/src/Admin/API/MarketingCampaigns.php b/plugins/woocommerce/src/Admin/API/MarketingCampaigns.php
index 7f691357498..6e8cb9b97bf 100644
--- a/plugins/woocommerce/src/Admin/API/MarketingCampaigns.php
+++ b/plugins/woocommerce/src/Admin/API/MarketingCampaigns.php
@@ -10,6 +10,7 @@ namespace Automattic\WooCommerce\Admin\API;
use Automattic\WooCommerce\Admin\Marketing\MarketingCampaign;
use Automattic\WooCommerce\Admin\Marketing\MarketingChannels as MarketingChannelsService;
use Automattic\WooCommerce\Admin\Marketing\Price;
+use Automattic\WooCommerce\Enums\CurrencyPosition;
use WC_REST_Controller;
use WP_Error;
use WP_REST_Request;
@@ -161,12 +162,12 @@ class MarketingCampaigns extends WC_REST_Controller {
// Get $price_format to be passed to wc_price.
$currency_pos = $currency_info['currency_pos'];
$currency_formats = array(
- 'left' => '%1$s%2$s',
- 'right' => '%2$s%1$s',
- 'left_space' => '%1$s %2$s',
- 'right_space' => '%2$s %1$s',
+ CurrencyPosition::LEFT => '%1$s%2$s',
+ CurrencyPosition::RIGHT => '%2$s%1$s',
+ CurrencyPosition::LEFT_SPACE => '%1$s %2$s',
+ CurrencyPosition::RIGHT_SPACE => '%2$s %1$s',
);
- $price_format = $currency_formats[ $currency_pos ] ?? $currency_formats['left'];
+ $price_format = $currency_formats[ $currency_pos ] ?? $currency_formats[ CurrencyPosition::LEFT ];
$price_value = wc_format_decimal( $price->get_value() );
$price_formatted = wc_price(
diff --git a/plugins/woocommerce/src/Enums/CurrencyPosition.php b/plugins/woocommerce/src/Enums/CurrencyPosition.php
new file mode 100644
index 00000000000..a8ab526c41a
--- /dev/null
+++ b/plugins/woocommerce/src/Enums/CurrencyPosition.php
@@ -0,0 +1,41 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace Automattic\WooCommerce\Enums;
+
+/**
+ * Enum class for the possible values of the `woocommerce_currency_pos` option,
+ * which determines where the currency symbol appears relative to the price.
+ *
+ * @since 11.0.0
+ */
+final class CurrencyPosition {
+ /**
+ * Display the currency symbol to the left of the price.
+ *
+ * @var string
+ */
+ public const LEFT = 'left';
+
+ /**
+ * Display the currency symbol to the right of the price.
+ *
+ * @var string
+ */
+ public const RIGHT = 'right';
+
+ /**
+ * Display the currency symbol to the left of the price, separated by a space.
+ *
+ * @var string
+ */
+ public const LEFT_SPACE = 'left_space';
+
+ /**
+ * Display the currency symbol to the right of the price, separated by a space.
+ *
+ * @var string
+ */
+ public const RIGHT_SPACE = 'right_space';
+}
diff --git a/plugins/woocommerce/src/Enums/README.md b/plugins/woocommerce/src/Enums/README.md
index 27c1981af32..bca24cc9812 100644
--- a/plugins/woocommerce/src/Enums/README.md
+++ b/plugins/woocommerce/src/Enums/README.md
@@ -7,6 +7,7 @@ The enum classes make it easier to reference string values and avoid typos. They
## Available Enumerators
- [CatalogVisibility](./CatalogVisibility.php) - Enumerates the possible catalog visibility options for a product.
+- [CurrencyPosition](./CurrencyPosition.php) - Enumerates the possible values of the `woocommerce_currency_pos` option.
- [DefaultCustomerAddress](./DefaultCustomerAddress.php) - Enumerates the possible values of the `woocommerce_default_customer_address` option.
- [DimensionUnit](./DimensionUnit.php) - Enumerates the possible values of the `woocommerce_dimension_unit` option.
- [OrderInternalStatus](./OrderInternalStatus.php) - Enumerates the possible internal statuses of an order (when stored in the database).
diff --git a/plugins/woocommerce/src/StoreApi/Formatters/CurrencyFormatter.php b/plugins/woocommerce/src/StoreApi/Formatters/CurrencyFormatter.php
index 9b12f2b45fa..7a48794e54e 100644
--- a/plugins/woocommerce/src/StoreApi/Formatters/CurrencyFormatter.php
+++ b/plugins/woocommerce/src/StoreApi/Formatters/CurrencyFormatter.php
@@ -1,6 +1,8 @@
<?php
namespace Automattic\WooCommerce\StoreApi\Formatters;
+use Automattic\WooCommerce\Enums\CurrencyPosition;
+
/**
* Currency Formatter.
*
@@ -21,16 +23,16 @@ class CurrencyFormatter implements FormatterInterface {
$suffix = '';
switch ( $position ) {
- case 'left_space':
+ case CurrencyPosition::LEFT_SPACE:
$prefix = $symbol . ' ';
break;
- case 'left':
+ case CurrencyPosition::LEFT:
$prefix = $symbol;
break;
- case 'right_space':
+ case CurrencyPosition::RIGHT_SPACE:
$suffix = ' ' . $symbol;
break;
- case 'right':
+ case CurrencyPosition::RIGHT:
$suffix = $symbol;
break;
}