Home Forums WoodMart support forum How to send "Color" for attribute swatches term via Woocommerce API

How to send "Color" for attribute swatches term via Woocommerce API

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #152200

    GDNETWORK
    Participant

    I’m using the Woocommerce API to create products for my website.

    How should I send the color hex code to the attribute term and turn on “Enable swatch”.

    Here’s a preview of what I’m trying to do through the API:
    Preview

    #152312

    Hello,

    Sorry I did not understand what you want to achieve. What do you mean by the color hex code?

    If you want to send or get the hex code of attribute then try the below code that might works in your case:

    $color = get_term_meta( $term->term_id, 'color', true );
    $image = get_term_meta( $term->term_id, 'image', true );

    Or if you just want to use the color swatches then let me know I will guide you.

    Best Regards.

    #656734

    Enzo
    Participant

    Hi, i want to GET product color hex or image link/id to create attributes using API.

    Your meta terms are not in the API. Please can you explain how to expose them ?

    • This reply was modified 2 months, 3 weeks ago by Enzo.
    #657002

    Hello,

    Unfortunately, by default, meta terms (such as hexadecimal color codes or image links/IDs) are not included in WooCommerce REST API responses.

    To make them available, you need to manually register these fields for the API. The fields we used are listed in this response: https://xtemos.com/forums/topic/how-to-send-color-for-attribute-swatches-term-via-woocommerce-api/#post-152312

    Best Regards,

    #658163

    Enzo
    Participant

    It works for color but not for image. I tried image id or image url but none of both works.

    #658298

    Hello,

    Please send a code that works for color but does not work for image.

    Best Regards,

Viewing 6 posts - 1 through 6 (of 6 total)