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?
- Rewrites with hierarchical taxonomies in permalink
- Rewrite rules for varying nested terms of custom taxonomy
- Copying taxonomy term to custom field
- Update table wp_term_taxonomy.count after INSERT INTO via SQL
- Get posts in certain Taxonomy terms for the current page url
- Exclude taxonomy term from all loops, but having it on widget
- Get all attachments by custom taxonomy – term
- Get terms that don’t belong to current post with a shortcode
- saving meta/custom field to tag
- Correctly order the hierarchy of custom taxonomy when displaying terms
- WC_Customer delete function returns error
- How best to store data (URLs and IDs) extracted from posts and pages using custom taxonomies
- Archive page for custom taxonomy grouped by month
- How to create a custom template for custom taxonomy wp-tag-cloud?
- Taxonomy page shows category in title
- Replace taxonomy term with an image in a custom loop
- Need to display custom taxonomy on single page – not working
- Show single Child Category on Custom Post
- Only display latest custom taxonomy post
- unable to save custom taxonomy terms in a custom-built metabox in wp-admin
- How to group non-hierarchical tags?
- How to combine taxonomies into URL?
- Add terms to a taxonomy archive from within the same taxonomy
- Show recent posts from a custom taxonomy in wordpress
- How do I show the parent term on a custom taxonomy template (not the ID)?
- Display taxonomies for custom post type
- ACF – Get unique values of array
- How to create archive pages for metadata query generated posts (so without taxonomy)?
- Making Woocommerce optimized for more than 500k products
- pagination for list category posts ( Custom post type )
- How to create a second set of tags that use the same slug or URL?
- Sort Taxonomy List by Custom Values
- How to filter a taxonomy meta field to the ‘single_term_title’ filter hook
- rewriting for custom taxonomy rewrite
- Get all taxonomy posts by id
- How do I create a term for every value of a post meta?
- Custom taxonomy archive empty
- Taxonomy Child Not Updating Unless I Click Update Twice
- How to show to show post list under the specific category name using jetengine query?
- How to enforce a requirement for custom taxonomy