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
- Why is my working Custom Taxonomy not in get_taxonomies array?
- Creating custom Woocommerce attribute taxonomies from a plugin
- How to enable hierarchical permalinks for hierarchical taxonomies
- Use custom posts as taxonomy term meta replacement?
- Remove description in custom taxonomy edit screen
- Taxonomies not appearing in columns on dashboard
- Make Custom Taxonomy Category Use Parent Template
- How to get terms of a custom post type in a loop inside footer.php
- Refine user taxonomy query based on role
- Get ID and slug from taxonomy object
- List the number of posts for each custom taxonomy and specific custom field value
- Recreating the hierarchy of taxonomies for a dropdown form menu?
- showing custom taxonomies w/custom post type
- How to overwrite registered taxonomy url from vendor plugin in child theme
- Dynamic loading of Archive content based on custom taxonomy term name
- Checking return with WP Error
- Failure to add term meta
- Get the taxonomy of the post
- JWT on Woocommerce cannot work with “Customer” role user
- Custom taxonomy not showing terms in post area
- Add a term to list in block editor taxonomy sidebar
- How to get related taxonomies based on a category with mysql query?
- Reorder a page of posts of a certain taxonomy/value by a custom field
- Link a page from admin to a custom taxonomy
- set_object_terms for custom taxonomy in custom post type – not working
- Differentiate Parent & Child of Custom Taxonomy
- Listing all selected terms for custom taxonomies on a post
- Custom Taxonomy – Archive for the whole Custom Taxonomy (and not just single term)?
- Guest author – URL, base and custom taxonomy – working but unstable
- Hook to filter based on form value and insert term
- Change get_author_posts_url / Author URL via filter
- Prevent random entries in hierarchical false taxonomies
- Exporting CSV of users with custom user taxonomies out of WordPress
- Pagination links not working for custom taxonomy
- Filter posts and custom taxonomy using add_rewrite_rule
- Get taxonomy that is attached to post with all its parents
- Querying posts globally based on custom taxonomy with its own taxonomymeta table
- How to looping taxonomy terms?
- Sub-pages of Custom Taxonomies
- Make term slugs of custom taxonomy available in WP REST API for custom post type?
- How to delete unused terms?
- Optional taxonomy in cpt permalink
- Child terms with improper parent in the url should redirect to 404