Comments (4)
I don't think we necessarily need to duplicate functionality available in other WP APIs. Categories for example can be looked up via /wp-json/wp/v2/product_cat
. From that you can derive IDs from slugs—perhaps you can utilise this in your use case?
Example response
[
{
"id": 19,
"count": 5,
"description": "",
"link": "https://store.local/product-category/clothing/accessories/",
"name": "Accessories",
"slug": "accessories",
"taxonomy": "product_cat",
"parent": 16,
"meta": [],
"_links": {
"self": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat/19"
}
],
"collection": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat"
}
],
"about": [
{
"href": "https://store.local/wp-json/wp/v2/taxonomies/product_cat"
}
],
"up": [
{
"embeddable": true,
"href": "https://store.local/wp-json/wp/v2/product_cat/16"
}
],
"wp:post_type": [
{
"href": "https://store.local/wp-json/wp/v2/product?product_cat=19"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 16,
"count": 14,
"description": "",
"link": "https://store.local/product-category/clothing/",
"name": "Clothing",
"slug": "clothing",
"taxonomy": "product_cat",
"parent": 0,
"meta": [],
"_links": {
"self": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat/16"
}
],
"collection": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat"
}
],
"about": [
{
"href": "https://store.local/wp-json/wp/v2/taxonomies/product_cat"
}
],
"wp:post_type": [
{
"href": "https://store.local/wp-json/wp/v2/product?product_cat=16"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 21,
"count": 1,
"description": "",
"link": "https://store.local/product-category/decor/",
"name": "Decor",
"slug": "decor",
"taxonomy": "product_cat",
"parent": 0,
"meta": [],
"_links": {
"self": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat/21"
}
],
"collection": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat"
}
],
"about": [
{
"href": "https://store.local/wp-json/wp/v2/taxonomies/product_cat"
}
],
"wp:post_type": [
{
"href": "https://store.local/wp-json/wp/v2/product?product_cat=21"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 18,
"count": 3,
"description": "",
"link": "https://store.local/product-category/clothing/hoodies/",
"name": "Hoodies",
"slug": "hoodies",
"taxonomy": "product_cat",
"parent": 16,
"meta": [],
"_links": {
"self": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat/18"
}
],
"collection": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat"
}
],
"about": [
{
"href": "https://store.local/wp-json/wp/v2/taxonomies/product_cat"
}
],
"up": [
{
"embeddable": true,
"href": "https://store.local/wp-json/wp/v2/product_cat/16"
}
],
"wp:post_type": [
{
"href": "https://store.local/wp-json/wp/v2/product?product_cat=18"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 20,
"count": 0,
"description": "",
"link": "https://store.local/product-category/music/",
"name": "Music",
"slug": "music",
"taxonomy": "product_cat",
"parent": 0,
"meta": [],
"_links": {
"self": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat/20"
}
],
"collection": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat"
}
],
"about": [
{
"href": "https://store.local/wp-json/wp/v2/taxonomies/product_cat"
}
],
"wp:post_type": [
{
"href": "https://store.local/wp-json/wp/v2/product?product_cat=20"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 17,
"count": 5,
"description": "",
"link": "https://store.local/product-category/clothing/tshirts/",
"name": "Tshirts",
"slug": "tshirts",
"taxonomy": "product_cat",
"parent": 16,
"meta": [],
"_links": {
"self": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat/17"
}
],
"collection": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat"
}
],
"about": [
{
"href": "https://store.local/wp-json/wp/v2/taxonomies/product_cat"
}
],
"up": [
{
"embeddable": true,
"href": "https://store.local/wp-json/wp/v2/product_cat/16"
}
],
"wp:post_type": [
{
"href": "https://store.local/wp-json/wp/v2/product?product_cat=17"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 15,
"count": 0,
"description": "",
"link": "https://store.local/product-category/uncategorized/",
"name": "Uncategorized",
"slug": "uncategorized",
"taxonomy": "product_cat",
"parent": 0,
"meta": [],
"_links": {
"self": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat/15"
}
],
"collection": [
{
"href": "https://store.local/wp-json/wp/v2/product_cat"
}
],
"about": [
{
"href": "https://store.local/wp-json/wp/v2/taxonomies/product_cat"
}
],
"wp:post_type": [
{
"href": "https://store.local/wp-json/wp/v2/product?product_cat=15"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}
]
Reference: https://developer.wordpress.org/rest-api/reference/taxonomies/
from woocommerce.
I agree, duplicating functionality isn’t ideal, but unfortunately, the endpoint mentioned (/wp-json/wp/v2/product_cat
) isn’t publicly queryable like the others under /wp-json/wc/store
, which is causing some issues for my use case. Any suggestions on how to work around this?
edit: also see #42321
from woocommerce.
@355am I think you're mistaken there. The read only post type APIs are public. https://woocommerce.com/wp-json/wp/v2/product_cat
from woocommerce.
@mikejolley You are right! Interestingly, I tested the endpoint with several WooCommerce webshops and consistently received 404 "rest_no_route"
responses. Thank you for providing the link as evidence.
While it works, it would be nice to directly query based on the slug instead of having to make two requests. Is there any chance of introducing slug-based querying in the future?
from woocommerce.
Related Issues (20)
- Product Filters Redesign > Parent block: Add overlay navigation block HOT 1
- Product Filters Redesign: Allow Adding Individual Filters to the Product Filters Block
- Add support for API test to run against external test sites in ci-jobs HOT 2
- Programmatically install WC package on the externally hosted sites HOT 2
- WordPress 6.6 regression - settings button in New Product Editor Description section is not appearing for smaller mobile resolutions HOT 2
- Broken coming soon template in dataview HOT 2
- [ Product Editor ] Correctly display variation options as attributes for non variation supported product types
- "Add a note to your order" White Text Background If Dark Mode Inputs Is Enabled
- [Flaky] templates/template-part-customization.classic_theme_with_template_parts_support.spec.ts HOT 2
- [Flaky] templates/template-part-customization.classic_theme_with_template_parts_support.spec.ts
- [GlobalStep] Blank screen is displayed after navigating to "/wp-admin/admin.php?page=wc-admin&task=payments" url when "WooPayments" is not installed. HOT 1
- [Enhancement]: Support for query building in $wpdb->prepare statement HOT 1
- WPC Product Bundles messes up my datalayer/GTM tracking value and product quantity HOT 1
- [Enhancement]: Add readme for validators
- extensionCartUpdates not surfacing errors without extra error handling
- [Flaky] shopper/my-account-pay-order.spec.js
- Migrate the bundled version of the Interactivity API to the official WordPress package
- [Flaky] shopper/my-account-downloads.spec.js
- Proceed to checkout button changes size when clicked
- Cannot view further than 1 child category in admin panel HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from woocommerce.