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 |
The attribute; entries without it are skipped |
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 manage_woocommerce or edit_products.
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.
Entries missing name vanish silently
Any entry that is malformed, or that omits name, is dropped. No error, and the response reports the attributes that were saved — not the ones you sent.
So an assistant can send five attributes, have one silently dropped, and report success. Compare the response against your intended list every time.
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 that do not match an existing term are stored, and produce combinations that resolve to nothing.
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 dry run
Echoes back the attributes you supplied, unprocessed. It confirms what the tool received — useful for catching a malformed entry before it is silently dropped — but it does not show you what the product currently has.
That means it is not a before/after. Get the "before" yourself, from the product read.
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 |
| The response is missing an attribute you sent | That entry had no name |
| 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