• Resolved seb06

    (@seb06)


    Hello,

    I am using the woocommerce API to create a product, attach existing categories and tags to a newly created woocommerce product ! I can do all of this ! ok !

    EXPLANATION:

    I have created a custom taxonomy that I have attached to “Products”, the taxonomy appears properly into each product ! ok !

    MY ISSUE:

    I am not able to figure out how to attach an exixting term of my custom taxonomy to the woocommerce product when I create a woocommerce product with the remote woocommerce API (like for categories and tags)

    Custom taxonomies are not foreseen in the woocommerce documentation.

    I can attach manually my custom taxonomy term to a product in the WP Backend but not with the API for a remote creation of a product…

    I didn’t find anything on google…

    Could you please help me?

    Thanks a lot!

Viewing 8 replies - 1 through 8 (of 8 total)
  • madeincosmos

    (@madeincosmos)

    Automattic Happiness Engineer

    Hi @seb06,

    I see what you mean. WooCommerce API only currently supports custom metadata fields but doesn’t have an option to add custom taxonomies. If this is what you need, can you please add it as a suggestion on our ideas board?

    https://ideas.woocommerce.com/forums/133476-woocommerce?category_id=36092

    We’d like to see how many people would be interested in this.

    Alternatively you can create a mini plugin that will hook into woocommerce_rest_insert_product, look for the taxonomy information information in the request you send, and then save it on the product:

    https://docs.woocommerce.com/wc-apidocs/source-class-WC_REST_Posts_Controller.html#216

    Cheers!

    Thread Starter seb06

    (@seb06)

    Hello,

    Thanks for your answer,

    However, woocommerce_rest_insert_product doesn’t work, I do not know why but it never triggers

    woocommerce_new_product works

    But what I would like is what is done by the Brands plugin
    https://woocommerce.com/products/brands

    Brand is a custom taxonomy attached to woocommerce products.

    Adding the custom taxonomy to the woocommerce product with API will look like this:

    curl -X PUT https://example.com/wp-json/wc/v2/products/123 \
    -u consumer_key:consumer_secret \
    -H ‘Content-Type: application/json’ \
    -d ‘{“brands”: [48, 49]}’

    I need this, would be great if woocommerce integrate it…

    Best

    • This reply was modified 5 years, 9 months ago by seb06.
    • This reply was modified 5 years, 9 months ago by seb06.
    madeincosmos

    (@madeincosmos)

    Automattic Happiness Engineer

    Hi @seb06,

    WooCommerce Brands has an API integration already built in the plugin code, and should set product brand using the code you’ve linked to. If it’s not working for you, please submit a support ticket here:

    https://woocommerce.com/my-account/create-a-ticket/

    We can help you test the API and make sure it’s working correctly.

    Cheers!

    Thread Starter seb06

    (@seb06)

    Yes sure, I know that the Brands plugin has API integration built in… ??

    But should be present natively into woocommerce !!

    Best Regards

    Plugin Support RK a11n

    (@riaanknoetze)

    I can certainly see the merit of wanting that in the main WooCommerce REST API although I suspect there might be a misunderstanding on what the core WooCommerce plugin caters for: Facilitating eCommerce for all types of products across all types of stores.

    As I’m sure you can imagine, folks that sell books don’t need a “brand” as an example. This means that, for that example at least, building out a Brands feature along with an API is redudant/bloated. Instead, that sort of functionality is better reserved for a feature extension like https://woocommerce.com/products/brands/.

    Of course, we’re viewing this from a “support” perspective. If you’re still adamant this should be included in the core WooCommerce plugin and the ideas board suggestion above isn’t feasible, I’d recommend creating a pull request with the desired code changes on the WooCommerce Github repository at https://github.com/woocommerce/woocommerce.

    Thread Starter seb06

    (@seb06)

    Hello,

    I am not talking about a brand bu any custom taxonomy you would like…

    The reason why it could be useful to integrate it natively in woocommerce API, it is because it could be good to have others taxonomies than default woocommerce categories and tags for your products…

    As we can create custom taxonomies in WP and attach to woocommerce product, it should be interested to deal with that custom taxonomies with the API too…

    and it is not only building a custom taxonomy from API, but also attaching the custom taxonomy to a product, edit, delete, create that brand…

    Thanks for your help !
    Cheers

    Seb, I agree with you – I have customers with products that a simple category or tag just won’t do enough.
    You can easily create custom taxonomies for WC products just like you do for standard and custom posts.
    It’d be great to just use the ‘include in rest’, the ‘rest base’ and the controller where you create the new taxonomy.
    Seems like a glaring omission to me.

    I’m glad I’ve found this thread.
    I have a custom taxonomy too, for my products and I was trying to add terms using:

    wp_set_object_terms
    or
    wp_set_post_terms

    With no success.
    So is it impossible at this stage with these functions?

    Thanks,
    Andre

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to add the term of a custom taxonomy to a woocommerce product using woo API’ is closed to new replies.