W3S API Extension for Woocommerce
Enhances your store’s REST API by adding flexible endpoints.
Install in
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 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” — or non-Latin slugs such as “ανδρικά” — 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.
Plays Well With WooCommerce
Changes are saved through the WooCommerce product API, so product caches are refreshed, woocommerce_update_product runs, product.updated webhooks fire, and the store’s default category is applied if a product is left without one.
Built-In Validation & Security
Sanitization of all inputs (IDs and slugs) to guard against bad data; the batch payload is validated against a schema.
Permission checks mirror WooCommerce core: only users allowed to edit the product (Shop Manager, Admin) can modify its categories.
Clear, standardized error codes (w3s_api_extension_invalid_product and w3s_api_extension_invalid_product_category) for consistent API responses. Unknown category IDs and slugs both return 404.
W3S API Extension for WooCommerce installs alongside the core WooCommerce REST API, requires no additional configuration, and works out of the box.
WooCommerce Bookings: prices by date and forced dates (optional)
The Bookings endpoints need the commercial WooCommerce Bookings plugin (tested with versions 3.13 and 3.16). They are active only while WooCommerce Bookings is active; without it they are not registered, nothing is scheduled and the plugin works exactly as before.
- Read a bookable product: person types (in sort order, with their position, costs and limits), display cost, cost rules, availability, and the price periods and forced dates stored by this plugin.
- Price periods: store per-person-type prices for date ranges. A booking is priced with the period that covers its booked date; everything else in the WooCommerce Bookings calculation (base and block costs, cost rules, resources, add-ons) stays as it is. The person types’ own costs follow the period in effect today, updated once a day. Optionally removes date-range multiplier cost rules and keeps the “From” (display) price at the first person type’s price.
- Date overrides: force single dates open or closed, whatever the product’s default availability and other rules say. They are written as ordinary WooCommerce Bookings availability rules at the top of the product’s list; the product’s own rules are left untouched.
- Changes are saved through the WooCommerce Bookings product API, so person types, the product price and the WooCommerce Bookings availability caches are updated exactly as for an admin save.
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″]}’
WooCommerce Bookings (only when the WooCommerce Bookings plugin is active)
Namespace wc-w3s/v1. WooCommerce REST API keys work as for wc/v3 (HTTP Basic over HTTPS); reading needs the right to read the product, writing the right to edit it, as in WooCommerce core. Errors: 404 w3s_api_extension_invalid_product, 400 w3s_api_extension_not_bookable (not a bookable product), 400 rest_invalid_param naming the invalid parameter (e.g. periods[0][from]), 401/403 from the permission check.
-
Read a bookable product
- Type: HTTP request
- Endpoint: `/wp-json/wc-w3s/v1/bookings/products/{product_id}`
- Methods: GET
- Example:
curl https://example.com/wp-json/wc-w3s/v1/bookings/products/79 \
-u consumer_key:consumer_secret - Response: `id`, `name`, `status`, `person_types` (sorted by sort order; `position` is the index in that order), `display_cost`, `display_cost_sync`, `pricing_rules`, `availability` (`default` and `rules`), `price_periods` (costs keyed by person type ID) and `date_overrides` (date: `open` or `closed`).
-
Store price periods
- Type: HTTP request
- Endpoint: `/wp-json/wc-w3s/v1/bookings/products/{product_id}/price-periods`
- Methods: POST, PUT, PATCH
- Example:
curl -X POST https://example.com/wp-json/wc-w3s/v1/bookings/products/79/price-periods \
-u consumer_key:consumer_secret \
-H “Content-Type: application/json” \
-d ‘{“periods”: [{“key”: “1113”, “from”: “2025-01-01”, “to”: “2027-03-31”, “costs”: [135, 95, 0]}], “delete”: [“900”], “remove_multiplier_rules”: true, “update_display_cost”: true}’ - `periods`: inserted or replaced by `key` (any string chosen by the caller). `from` and `to` are inclusive `Y-m-d` dates. `costs` as a JSON array is applied by person type position (0 = first in sort order), as a JSON object by person type ID, e.g. `{“65021”: 135, “65022”: 95}`. Values are numbers of 0 or more; positions and IDs the product does not have are ignored; person types not mentioned keep their own cost in that period.
- `delete`: keys to remove; unknown keys are ignored. Periods that ended before today (site time zone) are dropped.
- `remove_multiplier_rules` (default false): removes the product’s date-range (`custom`) cost rules that multiply or divide and end today or later. Other cost rules are kept.
- `update_display_cost`: true sets the display (“From”) cost to the cost of the first person type in the period in effect today and keeps it so in the daily update; false stops that. When the parameter is not sent, the previous choice stays.
- When a stored period covers today, the person types’ own costs are set to its costs. Where periods overlap, the one that starts last applies.
- Response: the product as returned by GET, plus `removed_pricing_rules`.
-
Force dates open or closed
- Type: HTTP request
- Endpoint: `/wp-json/wc-w3s/v1/bookings/products/{product_id}/date-overrides`
- Methods: POST, PUT, PATCH
- Example:
curl -X POST https://example.com/wp-json/wc-w3s/v1/bookings/products/79/date-overrides \
-u consumer_key:consumer_secret \
-H “Content-Type: application/json” \
-d ‘{“close”: [“2026-12-01”, “2026-12-02”], “open”: [“2026-12-24”], “clear”: [“2026-11-30”]}’ - `close` / `open`: dates (`Y-m-d`) to force closed / open; `clear`: dates to stop forcing. A date in more than one list is a 400. Dates before today are ignored.
- The forced dates are written as `custom` availability rules at the top of the product’s rule list (consecutive dates with the same state as one rule), with a priority that wins over the product’s other rules, its resources’ rules and store-wide rules. Rules written earlier by this endpoint are replaced; all other rules stay untouched and in order.
- Response: the product as returned by GET.
Extra notes
- Strings that include only digits are parsed as IDs, everything else as a slug. Slugs may contain any characters except “/”; URL-encode them when needed (the batch endpoint takes them in the JSON body, so no encoding is required there).
- The batch endpoints also accept form-encoded `categories[]=…` parameters or a comma-separated string. An empty or missing list returns a standard 400 `rest_missing_callback_param`/`rest_invalid_param` error.
- Removing a product’s last category assigns the store’s default category (“Uncategorized”), exactly as WooCommerce does in the admin.
- Every response of the category endpoints is the product’s resulting list of category terms.
- Bookings: the price periods, the forced dates and the display-cost choice are kept in the product’s own meta (keys starting with `_w3s_api_extension_`). WooCommerce Bookings’ own settings are only changed through its product API.
- Bookings: the daily update runs shortly after midnight (site time) through Action Scheduler, or WP-Cron when Action Scheduler is not available. It is removed when this plugin or WooCommerce Bookings is deactivated.
- Bookings: a forced “open” date makes the whole day available. On products booked by the hour or minute this also opens hours that time-of-day rules would close.
Written by Joobi from the project's own listing. See the source page
1.2.0
- Fixed: the 1.1.0 package was published without the file
extensions/w3s-woo-api-category-base.phpand stopped with a fatal error when the plugin loaded. The file is part of the package again. - Added: WooCommerce Bookings module. Requires the commercial WooCommerce Bookings plugin (tested with 3.13 and 3.16) and is inactive without it. New endpoints under
wc-w3s/v1: read a bookable product, store price periods, force dates open or closed. - Added: bookings are priced by booked date with the stored price periods, through WooCommerce Bookings’ own cost calculation.
- Added: daily update of the person-type costs and the display cost to the period in effect (Action Scheduler, with WP-Cron as fallback).
- Added: after every change the product’s page is purged from WP Super Cache, WP Rocket, W3 Total Cache and LiteSpeed Cache when one of them is active; the action
w3s_api_extension_bookings_product_updatedfires for any other page cache. - Compatibility: tested with WooCommerce 11.3.
1.1.0
- Compatibility: tested with WordPress 7.1 and WooCommerce 11.0. Now requires WordPress 6.7+ and WooCommerce 9.0+.
- Changed: category updates go through the WooCommerce product CRUD (
set_category_ids()/save()). WooCommerce’s product object cache (on by default for new stores since WooCommerce 11.0) is invalidated, andwoocommerce_update_productandproduct.updatedwebhooks now fire. - Fixed: numeric category IDs that do not exist (or belong to another taxonomy) now return 404 instead of silently succeeding.
- Added: the single-category endpoints accept any slug, including non-Latin (e.g. Greek) slugs.
- Added: the batch
categoriesparameter is declared in the route schema; form-encoded and comma-separated values are accepted and invalid payloads return standard 400 errors. - Added: item schema for API discovery (OPTIONS requests).
- Changed: permission checks mirror WooCommerce core (
wc_rest_check_post_permissions), honouring thewoocommerce_rest_check_permissionsfilter. - Fixed: routes are no longer registered when WooCommerce is inactive (previously a fatal error on request).
- Removed: unnecessary rewrite-rule flush on activation/deactivation.
1.0.1
- Fixed: readme file modifications
1.0.0
- Initial release
Follow this listing's changes (Atom feed)