Commit 5cbef918737 for woocommerce
commit 5cbef9187374d8eed61f616396e2047627aaa8a7
Author: Wesley Rosa <wesleyjrosa@gmail.com>
Date: Wed Apr 22 08:20:35 2026 -0300
Add TaxBasedOn enum class for woocommerce_tax_based_on option values (#64104)
* Add TaxBasedOn enum class for woocommerce_tax_based_on option values
Co-authored-by: wjrosa <10187816+wjrosa@users.noreply.github.com>
Agent-Logs-Url: https://github.com/wjrosa/woocommerce/sessions/b2cc1cfd-3344-4125-abb6-16cf58408f16
* 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>
* Add changefile(s) from automation for the following project(s): woocommerce
* Remove duplicate changelog entry for tax-based-on enum
The 64104-trunk changelog already covers this change.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Making the TaxBasedOn enum class final
---------
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/64104-trunk b/plugins/woocommerce/changelog/64104-trunk
new file mode 100644
index 00000000000..dcfb32bfec4
--- /dev/null
+++ b/plugins/woocommerce/changelog/64104-trunk
@@ -0,0 +1,4 @@
+Significance: minor
+Type: dev
+
+Introduces and implements constants for tax based on options in the WooCommerce plugin codebase.
\ No newline at end of file
diff --git a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php
index a21c69f667a..7412ae06e9f 100644
--- a/plugins/woocommerce/includes/abstracts/abstract-wc-order.php
+++ b/plugins/woocommerce/includes/abstracts/abstract-wc-order.php
@@ -14,6 +14,7 @@ use Automattic\WooCommerce\Caches\OrderCache;
use Automattic\WooCommerce\Enums\OrderStatus;
use Automattic\WooCommerce\Enums\ProductTaxStatus;
use Automattic\WooCommerce\Enums\ProductType;
+use Automattic\WooCommerce\Enums\TaxBasedOn;
use Automattic\WooCommerce\Internal\CostOfGoodsSold\CogsAwareTrait;
use Automattic\WooCommerce\Internal\Customers\SearchService as CustomersSearchService;
use Automattic\WooCommerce\Internal\Orders\PaymentInfo;
@@ -1769,17 +1770,17 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
protected function get_tax_location( $args = array() ) {
$tax_based_on = get_option( 'woocommerce_tax_based_on' );
- if ( 'shipping' === $tax_based_on && ! $this->get_shipping_country() ) {
- $tax_based_on = 'billing';
+ if ( TaxBasedOn::SHIPPING === $tax_based_on && ! $this->get_shipping_country() ) {
+ $tax_based_on = TaxBasedOn::BILLING;
}
$args = wp_parse_args(
$args,
array(
- 'country' => 'billing' === $tax_based_on ? $this->get_billing_country() : $this->get_shipping_country(),
- 'state' => 'billing' === $tax_based_on ? $this->get_billing_state() : $this->get_shipping_state(),
- 'postcode' => 'billing' === $tax_based_on ? $this->get_billing_postcode() : $this->get_shipping_postcode(),
- 'city' => 'billing' === $tax_based_on ? $this->get_billing_city() : $this->get_shipping_city(),
+ 'country' => TaxBasedOn::BILLING === $tax_based_on ? $this->get_billing_country() : $this->get_shipping_country(),
+ 'state' => TaxBasedOn::BILLING === $tax_based_on ? $this->get_billing_state() : $this->get_shipping_state(),
+ 'postcode' => TaxBasedOn::BILLING === $tax_based_on ? $this->get_billing_postcode() : $this->get_shipping_postcode(),
+ 'city' => TaxBasedOn::BILLING === $tax_based_on ? $this->get_billing_city() : $this->get_shipping_city(),
)
);
@@ -1803,11 +1804,11 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
// Set shop base address as a tax location if order has local pickup shipping method.
if ( $apply_base_tax && count( array_intersect( $shipping_method_ids, $local_pickup_methods ) ) > 0 ) {
- $tax_based_on = 'base';
+ $tax_based_on = TaxBasedOn::BASE;
}
// Default to base.
- if ( 'base' === $tax_based_on || empty( $args['country'] ) ) {
+ if ( TaxBasedOn::BASE === $tax_based_on || empty( $args['country'] ) ) {
$args['country'] = WC()->countries->get_base_country();
$args['state'] = WC()->countries->get_base_state();
$args['postcode'] = WC()->countries->get_base_postcode();
diff --git a/plugins/woocommerce/includes/admin/settings/views/settings-tax.php b/plugins/woocommerce/includes/admin/settings/views/settings-tax.php
index 7a02fd78300..b1546800ec9 100644
--- a/plugins/woocommerce/includes/admin/settings/views/settings-tax.php
+++ b/plugins/woocommerce/includes/admin/settings/views/settings-tax.php
@@ -7,6 +7,8 @@
defined( 'ABSPATH' ) || exit;
+use Automattic\WooCommerce\Enums\TaxBasedOn;
+
$settings = array(
array(
@@ -32,13 +34,13 @@ $settings = array(
'title' => __( 'Calculate tax based on', 'woocommerce' ),
'id' => 'woocommerce_tax_based_on',
'desc_tip' => __( 'This option determines which address is used to calculate tax.', 'woocommerce' ),
- 'default' => 'shipping',
+ 'default' => TaxBasedOn::SHIPPING,
'type' => 'select',
'class' => 'wc-enhanced-select',
'options' => array(
- 'shipping' => __( 'Customer shipping address', 'woocommerce' ),
- 'billing' => __( 'Customer billing address', 'woocommerce' ),
- 'base' => __( 'Shop base address', 'woocommerce' ),
+ TaxBasedOn::SHIPPING => __( 'Customer shipping address', 'woocommerce' ),
+ TaxBasedOn::BILLING => __( 'Customer billing address', 'woocommerce' ),
+ TaxBasedOn::BASE => __( 'Shop base address', 'woocommerce' ),
),
),
diff --git a/plugins/woocommerce/includes/class-wc-customer.php b/plugins/woocommerce/includes/class-wc-customer.php
index fe40efceecf..8b0d2f7f13f 100644
--- a/plugins/woocommerce/includes/class-wc-customer.php
+++ b/plugins/woocommerce/includes/class-wc-customer.php
@@ -8,6 +8,8 @@
defined( 'ABSPATH' ) || exit;
+use Automattic\WooCommerce\Enums\TaxBasedOn;
+
require_once __DIR__ . '/legacy/class-wc-legacy-customer.php';
/**
@@ -187,15 +189,15 @@ class WC_Customer extends WC_Legacy_Customer {
// Check shipping method at this point to see if we need special handling.
if ( true === apply_filters( 'woocommerce_apply_base_tax_for_local_pickup', true ) && count( array_intersect( wc_get_chosen_shipping_method_ids(), apply_filters( 'woocommerce_local_pickup_methods', array( 'legacy_local_pickup', 'local_pickup' ) ) ) ) > 0 ) {
- $tax_based_on = 'base';
+ $tax_based_on = TaxBasedOn::BASE;
}
- if ( 'base' === $tax_based_on ) {
+ if ( TaxBasedOn::BASE === $tax_based_on ) {
$country = WC()->countries->get_base_country();
$state = WC()->countries->get_base_state();
$postcode = WC()->countries->get_base_postcode();
$city = WC()->countries->get_base_city();
- } elseif ( 'billing' === $tax_based_on ) {
+ } elseif ( TaxBasedOn::BILLING === $tax_based_on ) {
$country = $this->get_billing_country();
$state = $this->get_billing_state();
$postcode = $this->get_billing_postcode();
diff --git a/plugins/woocommerce/includes/class-wc-tax.php b/plugins/woocommerce/includes/class-wc-tax.php
index b700d2be428..427476a7f81 100644
--- a/plugins/woocommerce/includes/class-wc-tax.php
+++ b/plugins/woocommerce/includes/class-wc-tax.php
@@ -6,6 +6,7 @@
*/
use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
+use Automattic\WooCommerce\Enums\TaxBasedOn;
use Automattic\WooCommerce\Utilities\NumberUtil;
defined( 'ABSPATH' ) || exit;
@@ -474,7 +475,7 @@ class WC_Tax {
if ( ! empty( $customer ) ) {
$location = $customer->get_taxable_address();
- } elseif ( wc_prices_include_tax() || DefaultCustomerAddress::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' ) || TaxBasedOn::BASE === get_option( 'woocommerce_tax_based_on' ) ) {
$location = array(
WC()->countries->get_base_country(),
WC()->countries->get_base_state(),
diff --git a/plugins/woocommerce/src/Enums/README.md b/plugins/woocommerce/src/Enums/README.md
index 9304b968a18..2cb5243abd6 100644
--- a/plugins/woocommerce/src/Enums/README.md
+++ b/plugins/woocommerce/src/Enums/README.md
@@ -15,6 +15,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.
+- [TaxBasedOn](./TaxBasedOn.php) - Enumerates the possible values of the `woocommerce_tax_based_on` option.
## Contributing
diff --git a/plugins/woocommerce/src/Enums/TaxBasedOn.php b/plugins/woocommerce/src/Enums/TaxBasedOn.php
new file mode 100644
index 00000000000..f4466840e7b
--- /dev/null
+++ b/plugins/woocommerce/src/Enums/TaxBasedOn.php
@@ -0,0 +1,34 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace Automattic\WooCommerce\Enums;
+
+/**
+ * Enum class for the possible values of the `woocommerce_tax_based_on` option,
+ * which determines which address is used to calculate tax.
+ *
+ * @since 10.8.0
+ */
+final class TaxBasedOn {
+ /**
+ * Tax is calculated based on the customer's shipping address.
+ *
+ * @var string
+ */
+ public const SHIPPING = 'shipping';
+
+ /**
+ * Tax is calculated based on the customer's billing address.
+ *
+ * @var string
+ */
+ public const BILLING = 'billing';
+
+ /**
+ * Tax is calculated based on the shop's base address.
+ *
+ * @var string
+ */
+ public const BASE = 'base';
+}