I eventually found a way using filters. I didn’t know there were filters for REST API responses…
Here is my solution :
add_filter( 'woocommerce_rest_prepare_product', 'custom_products_api_data', 90, 2 );
function custom_products_api_data( $response, $post ) {
// retrieve a custom field and add it to API response
$response->data['custom_taxonomy1'] = wp_get_post_terms( $post->ID, 'custom_taxonomy1', [] );
$response->data['custom_taxonomy2'] = wp_get_post_terms( $post->ID, 'custom_taxonomy2', [] );
return $response;
}
`
Source : https://francescocarlucci.com/woocommerce-api-add-custom-data-default-endpoints/
Related Posts:
- How to get WooCommerce Product Category Link by ID?
- WP REST API no longer supports filter param, so how do I get posts in a custom taxonomy?
- Create taxonomy with meta term using the WP Rest Api
- register_rest_field for custom taxonomy fields that are assosiated with custom post type
- Approach for saving a product attribute values with a custom UI in a woocommerce+dokan set up [closed]
- Add Category Name to REST API
- Display sub-taxonomies based on SELECTED parent-taxonomy
- Set download limit and expiry for WooCommerce downloadable products in specific categories
- Remove pagination from WooCommerce product categories on admin edit navigation menus
- Taxonomy , subtaxonomy,child taxonomy of a product woocommerce
- Woocommerce custom taxonomies page
- Outputting an array of term meta values in a custom WooCommerce tab?
- Programatically added attribute, set to ‘show on product page’ automatically. Woocommerce [closed]
- Get child product categories from parent product category in WooCommerce
- WP REST API – Limit the taxonomy search to the first letter
- Top level parent taxonomy ID
- Woocommerce product search result layout page
- Filter WooCommerce admin products list by a custom taxonomy
- Woocommerce: How to change the add to cart text in a certain category? [closed]
- Catchable fatal error on custom category post
- Get custom category image from menu
- Custom Taxonomy in REST API
- Hide product categories and taxonomy terms in menu if empty
- Display related products based on 2 specific product attributes values in WooCommerce
- How to target parent product category and its children using WooCommerce?
- Retrieving an intersection of two terms from two different custom taxonomies via API
- woocommerce custom product category template
- Getting WooCommerce product related child categories
- Hiding taxonomies with no children WP_Query & tax_query
- how does the wordpress rest API work
- WP REST API – get custom taxonomies based on terms & filter
- How to display ACF taxonomy checkbox links on WooCommerce product category archive
- Getting taxonomies associated with a specified post type
- Hide custom Woocommerce taxonomies when empty
- Add attribute taxonomy through code don’t appear in admin product page
- Terms added to custom taxonomy for custom post type only appear in Rest when added in code
- WordPress REST API – get custom taxonomy category posts
- Showing custom taxonomy in woocommerce signle product page
- Adding term to a custom taxonomy based on term from product category
- Warning: Undefined variable $post in C:\xampp\htdocs\… after PHP upgrade
- Admin only taxonomies?
- Fill New Taxonomies
- Infinite Scroll appending Next Product Category Term pages
- How to exclude woocommerece product category in search results?
- Cloning product not copying custom taxonomies
- Check if any available product has specific attribute
- How to get all the terms from a custom hierarchical taxonomy via REST api?
- WordPress search form and search result through ACF field in custom taxonomy
- how to filter the data’s comparison operators (>= &
- Get user created Woocommerce attributes ( taxonomies ) [closed]
- Custom order of taxonomy using wp_get_object_terms and woocommerce_term_meta
- How do you search for a post by custom taxonomy?
- Display woocommerce product_cat child terms with thumbnails
- Woocommerce – how to get and display selected variations on single product page
- How do I check if a post has a term with a particular ancestor/parent?
- Creating a custom archive page for WooCommerce products based on tags
- Hide empty categories on widget
- Change filter id into slug
- Set Variant options/attributes values on WooCommerce
- Equivalent setup_postdata for Taxonomy Term?
- Having issues with edit-tags.php not saving $_POST values for custom post_types including woocommerce product_cat
- add top and bottom content in edit page custom taxonomy woocommerce
- Using wp_query is it possible to orderby taxonomy?
- “tax_query” parameter not working with WP_Query
- How do I exclude a custom taxonomy from the post loop
- get_posts assigned to a specific custom taxonomy term, and not the term’s children
- How can I get only parent terms?
- How to modify a taxonomy that’s already registered
- Retrieve posts by term id custom query
- Change order of Custom Taxonomy List
- Get the the top-level parent of a custom taxonomy term
- get_the_term_list without links in 3.1
- Inserting terms in an Hierarchical Taxonomy
- get_terms – only top level
- Custom taxonomy terms not showing as list Gutenberg Editor
- Altering the appearance of custom taxonomy inputs
- How to only list the child terms of a taxonomy and not their parents?
- Get term SLUG by term ID
- Is ACF being a honey trap? [closed]
- Get term name from term ID?
- Check if Current Category has Children
- How to use taxonomies on attachments with the new Media Library?
- Hierarchical taxonomy UI
- WordPress taxonomy radio buttons
- How to prevent new terms being added to a custom taxonomy?
- Custom taxonomy, get_the_terms, listing in order of parent > child
- How to remove the tag cloud from custom taxonomy admin page?
- custom taxonomy and pages rewrite slug conflict gives 404
- Inserting a term into a custom taxonomy
- Count posts in custom taxonomy
- How to add images to taxonomies?
- Read-only taxonomy (user can assign term but can’t create or edit existing terms)
- Remove taxonomy base or term from url
- Can you add the visual editor to the description field for custom taxonomies?
- Adding Category/Tag/Taxonomy Support to Images/Media
- Add default WordPress tag meta box to User Profile
- Custom Taxonomy Endpoint Pagination using paginate_links()
- How do I get the top-level terms in a custom taxonomy?
- Check if a post has any term in this custom taxonomy?
- Custom post types filtered by taxonomy using REST API v2