Commit 228bb3c2c30 for woocommerce
commit 228bb3c2c30876910ee838f2ac8103b6c00baa16
Author: Tiago <77335756+tiago-123@users.noreply.github.com>
Date: Wed Mar 18 04:56:51 2026 -0300
Apply filter to variation option name in ProductItemTrait, allowing third-parties to optionally add relevant information. (#63673)
* Apply filter to variation option name in ProductItemTrait
Allow third-party plugins to optionally add relevant information to product attributes in the Store API Cart response.
* Apply filter to variation option name in ProductItemTrait (with the appropriate PHPDoc comment).
* Add changefile(s) from automation for the following project(s): woocommerce
* Apply filter to variation option name in ProductItemTrait (addressed linting errors)
* Fix parameter formatting in PHPDoc comments
* Update plugins/woocommerce/src/StoreApi/Utilities/ProductItemTrait.php
Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/63673-patch-1 b/plugins/woocommerce/changelog/63673-patch-1
new file mode 100644
index 00000000000..74c5794f5c0
--- /dev/null
+++ b/plugins/woocommerce/changelog/63673-patch-1
@@ -0,0 +1,4 @@
+Significance: patch
+Type: add
+
+Apply `woocommerce_variation_option_name` filter in ProductItemTrait, allowing third-parties to optionally add relevant information to variation option names.
\ No newline at end of file
diff --git a/plugins/woocommerce/src/StoreApi/Utilities/ProductItemTrait.php b/plugins/woocommerce/src/StoreApi/Utilities/ProductItemTrait.php
index 9c7e04f43b9..80aeeecf84b 100644
--- a/plugins/woocommerce/src/StoreApi/Utilities/ProductItemTrait.php
+++ b/plugins/woocommerce/src/StoreApi/Utilities/ProductItemTrait.php
@@ -50,7 +50,21 @@ trait ProductItemTrait {
// If this is a term slug, get the term's nice name.
$term = get_term_by( 'slug', $value, $taxonomy );
if ( ! is_wp_error( $term ) && $term && $term->name ) {
- $value = $term->name;
+
+ /**
+ * Filters the variation option name for taxonomy attributes.
+ *
+ * @since 10.7.0
+ *
+ * @internal Matches filter name in WooCommerce core.
+ *
+ * @param string $name The term name to display.
+ * @param \WP_Term $term Term object.
+ * @param string $taxonomy Taxonomy name.
+ * @param \WC_Product $product Product data.
+ * @return string
+ */
+ $value = apply_filters( 'woocommerce_variation_option_name', $term->name, $term, $taxonomy, $product );
}
$label = wc_attribute_label( $taxonomy );
} else {