[WordPress] 外掛分享: W3S API Extension for Woocommerce

首頁外掛目錄 › W3S API Extension for Woocommerce
全新外掛
安裝啟用
尚無評分
290 天前
最後更新
問題解決
WordPress 6.0+ PHP 7.4+ v1.0.1 上架:2025-06-01

內容簡介

### 總結:
- 透過製作強大且具彈性的端點,增強您商店的 REST API。
- 敬請期待更多內容的推出!

### 問題與答案:
1. 如何在單一 HTTP 請求中添加單一類別?
- 答案:
- 類型:HTTP 請求
- 端點:`/wp-json/wc/v3/products/{product_id}/categories/{identifier}`
- 方法:POST、PUT、PATCH
- 範例:
- `curl -X PUT https://example.com/wp-json/wc/v3/products/125/categories/18 \ -u consumer_key:consumer_secret`
- `curl -X PUT https://example.com/wp-json/wc/v3/products/125/categories/my-category \ -u consumer_key:consumer_secret`

2. 如何移除單一類別?
- 答案:
- 類型:HTTP 請求
- 端點:`/wp-json/wc/v3/products/{product_id}/categories/{identifier}`
- 方法:DELETE
- 範例:
- `curl -X DELETE https://example.com/wp-json/wc/v3/products/125/categories/18 \ -u consumer_key:consumer_secret`
- `curl -X DELETE https://example.com/wp-json/wc/v3/products/125/categories/my-category \ -u consumer_key:consumer_secret`

3. 如何批量添加類別?
- 答案:
- 類型:HTTP 請求
- 端點:`/wp-json/wc/v3/products/{product_id}/categories`
- 方法:POST、PUT、PATCH
- 範例:
- `curl -X PUT https://example.com/wp-json/wc/v3/products/125/categories \ -u consumer_key:consumer_secret \ -H “Content-Type: application/json” \ -d ‘{“categories”: [1,”my-category”,3,”my-category-1”]}’`

4. 如何批量刪除類別?
- 答案:
- 類型:HTTP 請求
- 端點:`/wp-json/wc/v3/products/{product_id}/categories`
- 方法:DELETE
- 範例:
- `curl -X DELETE https://example.com/wp-json/wc/v3/products/125/categories \ -u consumer_key:consumer_secret \ -H “Content-Type: application/json” \ -d ‘{“categories”: [1,”my-category”,3,”my-category-1”]}’`

5. 單一類別端點允許什麼樣的類別標識符?
- 答案:不允許含有除拉丁字母及數字[a-z0-9]以外的字符。
- 請注意:僅包含數字的字串將被解析為 ID 而不是標題。

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「W3S API Extension for Woocommerce」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

Enhances your store’s REST API by adding powerful, flexible endpoints.
Stay tuned more are coming!
Add or Remove a Single Category
Easily append or remove one category at a time—by numeric ID or human-friendly slug—using simple POST/PUT/PATCH or DELETE requests to
/wp-json/wc/v3/products/{product_id}/categories/{identifier}
Batch Manage Multiple Categories
In a single call, add or remove multiple categories at once via JSON payloads to
/wp-json/wc/v3/products/{product_id}/categories
Supply an array of IDs or slugs under the “categories” key to update your product’s category list in bulk.
Automatic Slug Resolution
Pass slugs like “summer-collection” and the plugin will resolve them to the correct WooCommerce term IDs on the fly—no extra lookups required.
Non-Destructive Updates
Neither endpoint touches other product data. Categories are merged or pruned transparently without overwriting prices, stock, attributes, or any other fields.
Built-In Validation & Security
Sanitization of all inputs (IDs and slugs) to guard against bad data.
Permission checks ensure only users with the edit_products capability (Shop Manager, Admin) can modify categories.
Clear, standardized error codes (w3s_api_extension_invalid_product and w3s_api_extension_invalid_product_category) for consistent API responses.
W3S API Extension for WooCommerce installs alongside the core WooCommerce REST API, requires no additional configuration, and works out of the box.
Endpoints Documentation
Product Categories

Add a single category

Type: HTTP request
Endpoint: `/wp-json/wc/v3/products/{product_id}/categories/{identifier}`
Methods: POST, PUT, PATCH
Examples:
curl -X PUT https://example.com/wp-json/wc/v3/products/125/categories/18 \
-u consumer_key:consumer_secret
curl -X PUT https://example.com/wp-json/wc/v3/products/125/categories/my-category \
-u consumer_key:consumer_secret

Remove a single category

Type: HTTP request
Endpoint: `/wp-json/wc/v3/products/{product_id}/categories/{identifier}`
Methods: DELETE
Examples:
curl -X DELETE https://example.com/wp-json/wc/v3/products/125/categories/18 \
-u consumer_key:consumer_secret
curl -X DELETE https://example.com/wp-json/wc/v3/products/125/categories/my-category \
-u consumer_key:consumer_secret

Batch add categories

Type: HTTP request
Endpoint: `/wp-json/wc/v3/products/{product_id}/categories`
Methods: POST, PUT, PATCH
Example:
curl -X PUT https://example.com/wp-json/wc/v3/products/125/categories \
-u consumer_key:consumer_secret \
-H “Content-Type: application/json” \
-d ‘{“categories”: [1,”my-category”,3,”my-category-1″]}’

Batch delete categories

Type: HTTP request
Endpoint: `/wp-json/wc/v3/products/{product_id}/categories`
Methods: DELETE
Example:
curl -X DELETE https://example.com/wp-json/wc/v3/products/125/categories \
-u consumer_key:consumer_secret \
-H “Content-Type: application/json” \
-d ‘{“categories”: [1,”my-category”,3,”my-category-1″]}’

Extra notes

The single category endpoint doesn’t allow slug with characters anything other than latin & numbers [a-z0-9]
Strings that include only numbers will be parsed as IDs and not as Slugs

延伸相關外掛

文章
Filter
Apply Filters
Mastodon