wc_set_product_attributes: assign product attributes
Sets which attributes a product declares, and which of them drive its variations.
Arguments
| Argument | Required | Meaning |
|---|---|---|
product_id |
Yes | The product |
attributes |
Yes | The complete list of attributes for this product |
dry_run |
No | Report without writing |
Each entry in attributes takes:
| Key | Meaning |
|---|---|
name |
Required attribute name; global attributes use their pa_ taxonomy name |
options |
The values this product offers |
visible |
Show it in the product's information table |
variation |
Use it to build variations |
The response is the full product.
Permissions
Allow WooCommerce catalog writes open, plus catalog access and permission to edit the selected product. Global attributes also require their taxonomy assignment capability.
It replaces the whole set
This is the critical behaviour. The list you pass becomes the product's attributes — anything currently on the product and absent from your list is removed.
Adding one attribute therefore means sending all of them:
Read product 219's current attributes, then set them again with Material added. Show me the full list before writing.
Sending a single-entry list to "add Material" deletes Size and Colour. On a variable product, that severs every variation from the combination it represents, and the whole product stops being purchasable.
Read first. Always send the complete intended set.
visible and variation are independent
visiblecontrols whether customers see the attribute in the product's information table. Presentation only.variationcontrols whether the attribute can be used to build variations. Structural.
An attribute with variation off cannot appear in a variation's attributes map — or rather, it can, and the variation will simply never be selectable. This is the most common reason a correctly-created variation does not show up.
Turning variation off on an attribute an existing variation depends on breaks that variation the same way.
Validate every attribute
Every entry needs a nonempty name. Invalid entries are refused before approval. Use the complete pa_ taxonomy name for a registered global attribute, such as pa_size; its native attribute ID is preserved. Custom attributes use their display names.
options are the values for this product
They are a subset of what the attribute offers: the shop may define eight sizes while this product stocks three.
For global attributes, use the term slugs exactly as wc_get_attribute_terms reports them. Values must match an existing term slug or name. Unknown values are refused.
An empty options on an attribute flagged for variations gives a product with no combinations to build from.
The order of operations
wc_get_product— the current attributes, so you can preserve them.wc_get_product_attributesandwc_get_attribute_terms— the exact names and slugs.- This tool — the complete set, with
variationon where needed. wc_create_variation— one per combination.
Doing step 3 after step 4 is what breaks working products.
The preview
The preview contains the current product and the normalized attributes to save. Global values are resolved to existing terms before approval. Unknown terms are refused; create them separately through the term tools first.
On a live variable product
Changing attributes on a product that is already selling is high risk: it can strand variations, empty the selector and change the price range, immediately and publicly.
Do it on staging first, or during quiet hours with the previous attribute set written down.
After writing
- Compare the returned attributes against your intended list, entry by entry.
- List the variations and confirm none were stranded.
- Open the product page and select a combination end to end.
- Check the information table shows what you expect.
- Purge the cache, then the CDN.
Common problems
| Symptom | Cause |
|---|---|
| The write is refused | Catalog write gate closed |
pom_ai_mcp_wc_product_not_found |
Wrong ID |
pom_ai_mcp_wc_forbidden |
Missing shop capability |
| Attributes disappeared | The list replaces; they were omitted |
| An entry is refused | Missing name, unavailable global attribute or unknown term |
| Variations became unselectable | variation is off, or the options changed |
| The product cannot be added to a cart | Its variations no longer match any combination |
| The information table looks wrong | visible flags |
Related
wc_get_product— read the current set firstwc_get_attribute_terms— exact slugswc_create_variation— do this after