Commit 64e7dc6011f for woocommerce
commit 64e7dc6011f1dfe939332aa681a8a9bcbacb940c
Author: Wesley Rosa <wesleyjrosa@gmail.com>
Date: Fri Apr 10 14:50:12 2026 -0300
Add DefaultCustomerAddress enum class for woocommerce_default_customer_address option values (#64091)
* Add OrderItemType enum class for WooCommerce line item types
Co-authored-by: wjrosa <10187816+wjrosa@users.noreply.github.com>
Agent-Logs-Url: https://github.com/wjrosa/woocommerce/sessions/8c722ad0-cb4d-4315-94ff-0c609f9354b9
* Replace raw order item type strings with OrderItemType enum constants across src/
Co-authored-by: wjrosa <10187816+wjrosa@users.noreply.github.com>
Agent-Logs-Url: https://github.com/wjrosa/woocommerce/sessions/cd678828-7e57-48d9-a556-022005be84c4
* Add DefaultCustomerAddress enum class and implement across codebase
Co-authored-by: wjrosa <10187816+wjrosa@users.noreply.github.com>
Agent-Logs-Url: https://github.com/wjrosa/woocommerce/sessions/eb288e26-007e-4630-9484-9b989a0528f2
* Add changefile(s) from automation for the following project(s): woocommerce
* Remove cache priming addition from Orders REST API controller
* Remove unused OrderItemType import from Orders REST API controller
* Address review feedback on OrderItemType enum adoption
* Fix MDX compilation errors caused by HTML comments in docs
* Revert "Fix MDX compilation errors caused by HTML comments in docs"
This reverts commit 895c96aac0aafd4f9283b03abafe49d3eccc8526.
* Add changefile(s) from automation for the following project(s): woocommerce
* Replace raw order item type strings with OrderItemType enum constants across src/
Co-authored-by: wjrosa <10187816+wjrosa@users.noreply.github.com>
Agent-Logs-Url: https://github.com/wjrosa/woocommerce/sessions/cd678828-7e57-48d9-a556-022005be84c4
* Remove unused OrderItemType import from Orders REST API controller
* Address review feedback on OrderItemType enum adoption
* Fix MDX compilation errors caused by HTML comments in docs
* Revert "Fix MDX compilation errors caused by HTML comments in docs"
This reverts commit 895c96aac0aafd4f9283b03abafe49d3eccc8526.
* Add missing enum entries to README and use enum in MaxMind integration
- Add DefaultCustomerAddress, FeaturePluginCompatibility, and ProductTaxStatus
to the Enums README.md
- Fix PaymentGatewayFeatures → PaymentGatewayFeature (correct filename)
- Replace hardcoded 'geolocation'/'geolocation_ajax' strings in
class-wc-integration-maxmind-geolocation.php with DefaultCustomerAddress enum
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix array double arrow alignment lint warnings
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Remove manually created changelog entry
The PR is configured to auto-create the changelog entry on merge.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Revert unrelated README changes, keep only DefaultCustomerAddress entry
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: wjrosa <10187816+wjrosa@users.noreply.github.com>
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
Co-authored-by: Vladimir Reznichenko <kalessil@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
diff --git a/plugins/woocommerce/changelog/64091-trunk b/plugins/woocommerce/changelog/64091-trunk
new file mode 100644
index 00000000000..b907b67559e
--- /dev/null
+++ b/plugins/woocommerce/changelog/64091-trunk
@@ -0,0 +1,4 @@
+Significance: minor
+Type: dev
+
+Introduces and implements constants for default customer address options in the WooCommerce plugin codebase.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/admin/class-wc-admin-notices.php b/plugins/woocommerce/includes/admin/class-wc-admin-notices.php
index 20fc9a2543d..3894c017977 100644
--- a/plugins/woocommerce/includes/admin/class-wc-admin-notices.php
+++ b/plugins/woocommerce/includes/admin/class-wc-admin-notices.php
@@ -7,6 +7,7 @@
*/
use Automattic\Jetpack\Constants;
+use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
use Automattic\WooCommerce\Internal\Utilities\Users;
use Automattic\WooCommerce\Internal\Utilities\WebhookUtil;
@@ -607,7 +608,7 @@ class WC_Admin_Notices {
public static function add_maxmind_missing_license_key_notice() {
$default_address = get_option( 'woocommerce_default_customer_address' );
- if ( ! in_array( $default_address, array( 'geolocation', 'geolocation_ajax' ), true ) ) {
+ if ( ! in_array( $default_address, array( DefaultCustomerAddress::GEOLOCATION, DefaultCustomerAddress::GEOLOCATION_AJAX ), true ) ) {
return;
}
diff --git a/plugins/woocommerce/includes/admin/settings/class-wc-settings-general.php b/plugins/woocommerce/includes/admin/settings/class-wc-settings-general.php
index 97521b57a57..674d4990af4 100644
--- a/plugins/woocommerce/includes/admin/settings/class-wc-settings-general.php
+++ b/plugins/woocommerce/includes/admin/settings/class-wc-settings-general.php
@@ -6,6 +6,7 @@
*/
use Automattic\WooCommerce\Admin\Features\Features;
+use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
use Automattic\WooCommerce\Internal\AddressProvider\AddressProviderController;
defined( 'ABSPATH' ) || exit;
@@ -233,14 +234,14 @@ class WC_Settings_General extends WC_Settings_Page {
'title' => __( 'Default customer location', 'woocommerce' ),
'id' => 'woocommerce_default_customer_address',
'desc_tip' => __( 'This option determines a customers default location. The MaxMind GeoLite Database will be periodically downloaded to your wp-content directory if using geolocation.', 'woocommerce' ),
- 'default' => 'base',
+ 'default' => DefaultCustomerAddress::BASE,
'type' => 'select',
'class' => 'wc-enhanced-select',
'options' => array(
- '' => __( 'No location by default', 'woocommerce' ),
- 'base' => __( 'Shop country/region', 'woocommerce' ),
- 'geolocation' => __( 'Geolocate', 'woocommerce' ),
- 'geolocation_ajax' => __( 'Geolocate (with page caching support)', 'woocommerce' ),
+ DefaultCustomerAddress::NO_DEFAULT => __( 'No location by default', 'woocommerce' ),
+ DefaultCustomerAddress::BASE => __( 'Shop country/region', 'woocommerce' ),
+ DefaultCustomerAddress::GEOLOCATION => __( 'Geolocate', 'woocommerce' ),
+ DefaultCustomerAddress::GEOLOCATION_AJAX => __( 'Geolocate (with page caching support)', 'woocommerce' ),
),
),
diff --git a/plugins/woocommerce/includes/class-wc-cache-helper.php b/plugins/woocommerce/includes/class-wc-cache-helper.php
index 4b4fa283b8c..e6cf0946a86 100644
--- a/plugins/woocommerce/includes/class-wc-cache-helper.php
+++ b/plugins/woocommerce/includes/class-wc-cache-helper.php
@@ -6,6 +6,7 @@
*/
use Automattic\WooCommerce\Caching\CacheNameSpaceTrait;
+use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
defined( 'ABSPATH' ) || exit;
@@ -183,7 +184,7 @@ class WC_Cache_Helper {
* This prevents caching of the wrong data for this request.
*/
public static function geolocation_ajax_redirect() {
- if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) && ! is_checkout() && ! is_cart() && ! is_account_page() && ! is_robots() && ! wp_doing_ajax() && empty( $_POST ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
+ if ( DefaultCustomerAddress::GEOLOCATION_AJAX === get_option( 'woocommerce_default_customer_address' ) && ! is_checkout() && ! is_cart() && ! is_account_page() && ! is_robots() && ! wp_doing_ajax() && empty( $_POST ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
$location_hash = self::geolocation_ajax_get_location_hash();
$current_hash = isset( $_GET['v'] ) ? wc_clean( wp_unslash( $_GET['v'] ) ) : ''; // WPCS: sanitization ok, input var ok, CSRF ok.
if ( empty( $current_hash ) || $current_hash !== $location_hash ) {
@@ -219,7 +220,7 @@ class WC_Cache_Helper {
* ensuring we update the cookie any time the billing country is changed.
*/
public static function update_geolocation_hash() {
- if ( 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' ) ) {
+ if ( DefaultCustomerAddress::GEOLOCATION_AJAX === get_option( 'woocommerce_default_customer_address' ) ) {
wc_setcookie( 'woocommerce_geo_hash', static::geolocation_ajax_get_location_hash(), time() + HOUR_IN_SECONDS );
}
}
diff --git a/plugins/woocommerce/includes/class-wc-frontend-scripts.php b/plugins/woocommerce/includes/class-wc-frontend-scripts.php
index a2237fee33f..ded29a5c1bf 100644
--- a/plugins/woocommerce/includes/class-wc-frontend-scripts.php
+++ b/plugins/woocommerce/includes/class-wc-frontend-scripts.php
@@ -11,6 +11,7 @@
use Automattic\Jetpack\Constants;
use Automattic\WooCommerce\Admin\Features\Features;
+use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
use Automattic\WooCommerce\Internal\AddressProvider\AddressProviderController;
if ( ! defined( 'ABSPATH' ) ) {
@@ -543,7 +544,7 @@ class WC_Frontend_Scripts {
// Only enqueue the geolocation script if the Default Current Address is set to "Geolocate
// (with Page Caching Support) and outside of the cart, checkout, account and customizer preview.
if (
- 'geolocation_ajax' === get_option( 'woocommerce_default_customer_address' )
+ DefaultCustomerAddress::GEOLOCATION_AJAX === get_option( 'woocommerce_default_customer_address' )
&& ! ( is_cart() || is_account_page() || is_checkout() || is_customize_preview() )
) {
$ua = strtolower( wc_get_user_agent() ); // Exclude common bots from geolocation by user agent.
diff --git a/plugins/woocommerce/includes/class-wc-geolocation.php b/plugins/woocommerce/includes/class-wc-geolocation.php
index f5b238e6e61..5a0140b317d 100644
--- a/plugins/woocommerce/includes/class-wc-geolocation.php
+++ b/plugins/woocommerce/includes/class-wc-geolocation.php
@@ -10,6 +10,8 @@
* @version 3.9.0
*/
+use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
+
defined( 'ABSPATH' ) || exit;
/**
@@ -69,7 +71,7 @@ class WC_Geolocation {
* @return bool
*/
private static function is_geolocation_enabled( $current_settings ) {
- return in_array( $current_settings, array( 'geolocation', 'geolocation_ajax' ), true );
+ return in_array( $current_settings, array( DefaultCustomerAddress::GEOLOCATION, DefaultCustomerAddress::GEOLOCATION_AJAX ), true );
}
/**
@@ -357,7 +359,7 @@ class WC_Geolocation {
wc_deprecated_function( 'WC_Geolocation::disable_geolocation_on_legacy_php', '3.9.0' );
if ( self::is_geolocation_enabled( $default_customer_address ) ) {
- $default_customer_address = 'base';
+ $default_customer_address = DefaultCustomerAddress::BASE;
}
return $default_customer_address;
diff --git a/plugins/woocommerce/includes/class-wc-tax.php b/plugins/woocommerce/includes/class-wc-tax.php
index cea9e82cdc3..b700d2be428 100644
--- a/plugins/woocommerce/includes/class-wc-tax.php
+++ b/plugins/woocommerce/includes/class-wc-tax.php
@@ -5,6 +5,7 @@
* @package WooCommerce\Classes
*/
+use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
use Automattic\WooCommerce\Utilities\NumberUtil;
defined( 'ABSPATH' ) || exit;
@@ -473,7 +474,7 @@ class WC_Tax {
if ( ! empty( $customer ) ) {
$location = $customer->get_taxable_address();
- } elseif ( wc_prices_include_tax() || 'base' === get_option( 'woocommerce_default_customer_address' ) || 'base' === get_option( 'woocommerce_tax_based_on' ) ) {
+ } elseif ( wc_prices_include_tax() || DefaultCustomerAddress::BASE === get_option( 'woocommerce_default_customer_address' ) || 'base' === get_option( 'woocommerce_tax_based_on' ) ) {
$location = array(
WC()->countries->get_base_country(),
WC()->countries->get_base_state(),
diff --git a/plugins/woocommerce/includes/integrations/maxmind-geolocation/class-wc-integration-maxmind-geolocation.php b/plugins/woocommerce/includes/integrations/maxmind-geolocation/class-wc-integration-maxmind-geolocation.php
index c55d7a349ab..6e77dd20c06 100644
--- a/plugins/woocommerce/includes/integrations/maxmind-geolocation/class-wc-integration-maxmind-geolocation.php
+++ b/plugins/woocommerce/includes/integrations/maxmind-geolocation/class-wc-integration-maxmind-geolocation.php
@@ -8,6 +8,8 @@
defined( 'ABSPATH' ) || exit;
+use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
+
require_once __DIR__ . '/class-wc-integration-maxmind-database-service.php';
/**
@@ -280,7 +282,7 @@ class WC_Integration_MaxMind_Geolocation extends WC_Integration {
return;
}
- if ( ! in_array( $new_value, array( 'geolocation', 'geolocation_ajax' ), true ) ) {
+ if ( ! in_array( $new_value, array( DefaultCustomerAddress::GEOLOCATION, DefaultCustomerAddress::GEOLOCATION_AJAX ), true ) ) {
$this->remove_missing_license_key_notice();
return;
}
diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
index 917ade52781..42fa79da1ec 100644
--- a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
+++ b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php
@@ -15,6 +15,7 @@ use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Registe
use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer as Order_DataSynchronizer;
use Automattic\WooCommerce\Utilities\{ LoggingUtil, OrderUtil, PluginUtil };
use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils;
+use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
/**
@@ -1480,8 +1481,8 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller {
'geolocation_enabled' => in_array(
get_option( 'woocommerce_default_customer_address' ),
array(
- 'geolocation_ajax',
- 'geolocation',
+ DefaultCustomerAddress::GEOLOCATION_AJAX,
+ DefaultCustomerAddress::GEOLOCATION,
),
true
),
diff --git a/plugins/woocommerce/includes/wc-core-functions.php b/plugins/woocommerce/includes/wc-core-functions.php
index 9d732973e23..1d0d074da7d 100644
--- a/plugins/woocommerce/includes/wc-core-functions.php
+++ b/plugins/woocommerce/includes/wc-core-functions.php
@@ -9,8 +9,9 @@
*/
use Automattic\Jetpack\Constants;
-use Automattic\WooCommerce\Utilities\NumberUtil;
use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils;
+use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
+use Automattic\WooCommerce\Utilities\NumberUtil;
use Automattic\WooCommerce\Internal\Logging\OrderLogsCleanupHelper;
if ( ! defined( 'ABSPATH' ) ) {
@@ -1205,10 +1206,10 @@ function wc_get_customer_geolocation( $fallback = array(
* @return array
*/
function wc_get_customer_default_location() {
- $set_default_location_to = get_option( 'woocommerce_default_customer_address', 'base' );
+ $set_default_location_to = get_option( 'woocommerce_default_customer_address', DefaultCustomerAddress::BASE );
// Unless the location should be blank, use the base location as the default.
- if ( '' !== $set_default_location_to ) {
+ if ( DefaultCustomerAddress::NO_DEFAULT !== $set_default_location_to ) {
$default_location_string = get_option( 'woocommerce_default_country', 'US:CA' );
}
@@ -1234,7 +1235,7 @@ function wc_get_customer_default_location() {
}
// Geolocation takes priority if geolocation is possible.
- if ( in_array( $set_default_location_to, array( 'geolocation', 'geolocation_ajax' ), true ) ) {
+ if ( in_array( $set_default_location_to, array( DefaultCustomerAddress::GEOLOCATION, DefaultCustomerAddress::GEOLOCATION_AJAX ), true ) ) {
$default_location = wc_get_customer_geolocation( $default_location );
}
diff --git a/plugins/woocommerce/includes/wc-update-functions.php b/plugins/woocommerce/includes/wc-update-functions.php
index 7813a09e06a..fd6075ef608 100644
--- a/plugins/woocommerce/includes/wc-update-functions.php
+++ b/plugins/woocommerce/includes/wc-update-functions.php
@@ -21,6 +21,7 @@ defined( 'ABSPATH' ) || exit;
use Automattic\WooCommerce\Admin\Notes\Note;
use Automattic\WooCommerce\Admin\Notes\Notes;
use Automattic\WooCommerce\Database\Migrations\MigrationHelper;
+use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
use Automattic\WooCommerce\Enums\ProductStockStatus;
use Automattic\WooCommerce\Enums\ProductType;
use Automattic\WooCommerce\Internal\Admin\Marketing\MarketingSpecs;
@@ -733,8 +734,8 @@ function wc_update_230_options() {
delete_metadata( 'user', 0, '_last_order', '', true );
// To prevent taxes being hidden when using a default 'no address' in a store with tax inc prices, set the woocommerce_default_customer_address to use the store base address by default.
- if ( '' === get_option( 'woocommerce_default_customer_address', false ) && wc_prices_include_tax() ) {
- update_option( 'woocommerce_default_customer_address', 'base' );
+ if ( DefaultCustomerAddress::NO_DEFAULT === get_option( 'woocommerce_default_customer_address', false ) && wc_prices_include_tax() ) {
+ update_option( 'woocommerce_default_customer_address', DefaultCustomerAddress::BASE );
}
}
diff --git a/plugins/woocommerce/src/Enums/DefaultCustomerAddress.php b/plugins/woocommerce/src/Enums/DefaultCustomerAddress.php
new file mode 100644
index 00000000000..ed23cdd0178
--- /dev/null
+++ b/plugins/woocommerce/src/Enums/DefaultCustomerAddress.php
@@ -0,0 +1,40 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace Automattic\WooCommerce\Enums;
+
+/**
+ * Enum class for the possible values of the 'woocommerce_default_customer_address' option.
+ *
+ * @since 10.8.0
+ */
+final class DefaultCustomerAddress {
+ /**
+ * No default location.
+ *
+ * @var string
+ */
+ public const NO_DEFAULT = '';
+
+ /**
+ * Use the shop's base country/region as the default location.
+ *
+ * @var string
+ */
+ public const BASE = 'base';
+
+ /**
+ * Geolocate the customer's location.
+ *
+ * @var string
+ */
+ public const GEOLOCATION = 'geolocation';
+
+ /**
+ * Geolocate the customer's location with page caching support (via AJAX).
+ *
+ * @var string
+ */
+ public const GEOLOCATION_AJAX = 'geolocation_ajax';
+}
diff --git a/plugins/woocommerce/src/Enums/README.md b/plugins/woocommerce/src/Enums/README.md
index 7f9d967e947..9304b968a18 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.
+- [DefaultCustomerAddress](./DefaultCustomerAddress.php) - Enumerates the possible values of the `woocommerce_default_customer_address` option.
- [OrderInternalStatus](./OrderInternalStatus.php) - Enumerates the possible internal statuses of an order (when stored in the database).
- [OrderItemType](./OrderItemType.php) - Enumerates the possible types of an order line item.
- [OrderStatus](./OrderStatus.php) - Enumerates the possible statuses of an order.