Skip to content

[Backport to release/10.6] Add to Cart: improve validation of attributes with multi-word names#63647

Merged
kmanijak merged 2 commits intorelease/10.6from
cherry-pick-PR63640-to-release/10.6
Mar 12, 2026
Merged

[Backport to release/10.6] Add to Cart: improve validation of attributes with multi-word names#63647
kmanijak merged 2 commits intorelease/10.6from
cherry-pick-PR63640-to-release/10.6

Conversation

@woocommercebot
Copy link
Copy Markdown
Collaborator

This PR is a cherry-pick of #63640 to release/10.6.

Original PR Description

Submission Review Guidelines:

Changes proposed in this Pull Request:

Fixes attribute options being incorrectly disabled in the Add to Cart with Options block for variable products whose attribute slugs contain hyphens.

Root cause: The PHP context passes attribute names as slugs (e.g., attribute_pa_some-name), which normalizes to some-name. The Store API returns attribute labels with spaces (e.g., some name). The strict comparison "some-name" === "some name" failed, causing getVariationAttributeValue to return undefined and all options for that attribute to appear disabled.

Fix: Updated normalizeAttributeName() in attribute-matching.ts to also replace hyphens with spaces, and ensured all comparison points in the file use the normalized form consistently.

Closes #63635

(For Bug Fixes) Bug introduced in PR #62880

Screenshots or screen recordings:

Before After
image image image image

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Make sure you have variation product with attribute that's name has multiple words
  • important: slug should differ from name, e.g. name: "Numeric Size", slug: numeric-size
  1. Make sure you use Add to Cart with Options in your Single Product template
  2. Go to product frontend
  3. Expected: Attributes should be available to choose
  4. Confirm they're disabled on trunk

Testing that has already taken place:

Milestone

Note: Check the box above to have the milestone automatically assigned when merged.
Alternatively (e.g. for point releases), manually assign the appropriate milestone.

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

…63640)

* Improve attributes validation for two words cases

* Add changelog

* Cover one more case missing normalization

* Update chaneglog

* Refactor normalisation so it's more centralised

* Add tests

* Fix lint
@woocommercebot woocommercebot requested a review from kmanijak March 12, 2026 09:50
@github-actions github-actions bot added this to the 10.6.0 milestone Mar 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Testing Guidelines

Hi @kmanijak ,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Mar 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 12, 2026

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@github-actions
Copy link
Copy Markdown
Contributor

Size Change: +37 B (0%)

Total Size: 5.97 MB

compressed-size-action

Copy link
Copy Markdown
Contributor

@kmanijak kmanijak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and multi-word named attributes are enabled correctly and can be added to cart.

I only could experience the problem from this PR: #63535 that's fixed on trunk but not in 10.6.

Image

Product is still added to cart but with console error and downgraded UX but that's out of scope of this particular fix hence approving and merging.

FYI @SantosGuillamot

@kmanijak kmanijak merged commit 733fde6 into release/10.6 Mar 12, 2026
40 checks passed
@kmanijak kmanijak deleted the cherry-pick-PR63640-to-release/10.6 branch March 12, 2026 11:12
@github-actions github-actions bot added metric: feature freeze exception A tracking label for PRs that were merged after the feature freeze. needs: documentation The issue/PR requires documentation to be added. labels Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

metric: feature freeze exception A tracking label for PRs that were merged after the feature freeze. needs: documentation The issue/PR requires documentation to be added. plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants