• Resolved oneprg

    (@oneprg)


    Product have field “attributes”. This field have field “options” – array List of available term names of the attribute. How can I update this list?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there @oneprg ??

    Thank you for contacting Woo support!

    Product have field “attributes”. This field have field “options” – array List of available term names of the attribute. How can I update this list?

    I understand you’d like to manipulate the product attribute terms via the WooCommerce API.

    The product attribute terms API allows you to create, view, update, and delete individual, or a batch of, attribute terms.

    Feel free to check out the related API documentation, directly linked here, for further details on this.

    I hope this is helpful! Please let us know if you have any further questions or concerns.

    Thread Starter oneprg

    (@oneprg)

    Tthanks for the answer.
    I have read this documentation.
    I did not find a method there that allows you to update the list of product attributes. Note that I’m not talking about the general attributes section, I’m talking about specific product attributes.

    By analogy with variations in this method, you need to specify the id of the product whose attributes we want to change. But I can’t find such a method.

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @oneprg

    You can achieve this by updating the entire product using the “Update a Product” endpoint. In the request body, you would include the attributes field with the updated data.

    Here’s an example of how you can structure your request:

    PUT /wp-json/wc/v3/products/
    
    {
    "attributes": [
    {
    "id": 1,
    "name": "Color",
    "position": 0,
    "visible": true,
    "variation": true,
    "options": [
    "Black",
    "Green"
    ]
    }

    Please refer to the “Update a product” section of our API documentation for more details: WooCommerce REST API Documentation

    Please note that the attribute should already be assigned to the product before you can update its terms. If the attribute is not assigned to the product, you will need to use the “Create a Product” endpoint to assign it first.

    I hope this helps! If you have any other questions or need further clarification, please don’t hesitate to ask.

    Thread Starter oneprg

    (@oneprg)

    Hi, @shameemreza
    I have a product with empty attribute options:
    GET /wp-json/wc/v3/products/2639

    "attributes": [
        {
            "id": 1,
            "name": "ОБЪЕМ",
            "position": 2,
            "visible": true,
            "variation": true,
            "options": []
        }
    ]

    I want to add options:

    PUT /wp-json/wc/v3/products/2639

    "attributes": [
        {
            "id": 1,
            "name": "ОБЪЕМ",
            "position": 2,
            "visible": true,
            "variation": true,
            "options": [
                "340 мл",
                "739 мл"
                ]
        }
    ]

    The request does not return an error, but the options remain empty.

    If I look at attribute terms, i see this terms:

    GET /wp-json/wc/v3/products/attributes/1/terms

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @oneprg

    The attribute options in the product endpoint are meant to be used for custom product attributes. If you are using global attributes (which seems to be the case since you’re checking attribute terms), you should use the terms endpoint to add new options.

    Here’s how you can do it:

    1. First, you need to create a new term for your attribute.
    2. The response should give you an ID for the new term. You can then use this ID to link the term to your product.
    3. Repeat the process for the “739 мл” option.

    Please note that the “options” field in the product endpoint expects an array of strings. If you’re using global attributes, these strings should be the names of the terms, not the term IDs.

    If you continue to face issues, for assistance with the development, we recommend that you seek help from:

    If you are comfortable with coding yourself and have questions, I would also recommend that you consider:

    I hope that helps you to figure it out.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘API: Product – Attributes properties’ is closed to new replies.