# WooCommerce Documentation - Complete This file contains the complete content of all documentation files combined. ## Getting Started with WooCommerce APIs *Source: apis/README.md* # Getting Started with WooCommerce APIs WooCommerce provides a number of programmatic APIs to interact with WooCommerce store data. ## WC REST API The WC REST API is a powerful part of WooCommerce which lets you read and write various parts of WooCommerce data such as orders, products, coupons, customers, and shipping zones. It based on the [WordPress REST API](https://developer.wordpress.org/rest-api/). Explore the [WC REST API](./rest-api/) documentation. ## Store API The Store API provides public REST API endpoints for the development of customer-facing cart, checkout, and product functionality. In contrast to the WooCommerce REST API, the Store API is unauthenticated and does not provide access to sensitive store data or other customer information. Explore the [Store API](./store-api/README.md) documentation. ## Dual API (code + GraphQL, experimental) The dual API is an experimental, code-first API: you write plain PHP classes (the code API) and a build script generates a matching GraphQL endpoint from them. WooCommerce core ships its own dual API, and the underlying infrastructure can be reused by plugins to build their own. Explore the [Dual API](./dual-api/README.md) documentation. ## Other Resources Beyond the powerful REST APIs, WooCommerce offers a suite of PHP-based APIs designed for developers to deeply integrate and extend the core functionality of their store. These APIs allow for direct interaction with WooCommerce classes, enabling custom behaviors for settings, payment gateways, shipping methods, and more. ### Settings API The Settings API is used by extensions to display, save, and load settings. Explore the [Settings API](/docs/extensions/settings-and-config/settings-api) documentation. ### Payment Gateway API The Payment Gateway API is used by extensions to interact with the payment gateway. Explore the [Payment Gateway API](/docs/features/payments/payment-gateway-api/) documentation. ### Shipping Method API The Shipping Method API is used by extensions to extend shipping methods and add their own rates. Explore the [Shipping Method API](/docs/features/shipping/shipping-method-api/) documentation. ### Payment Token API The Payment Token API is used for storing and managing payment tokens for gateways. Explore the [Payment Token API](/docs/features/payments/payment-token-api/) documentation. ### WooCommerce Code Reference The WooCommerce Code Reference is a comprehensive documentation of the WooCommerce API. It is a great resource for developers to learn about the WooCommerce API and how to use it. The WooCommerce Code Reference is a comprehensive documentation of the internal WooCommerce Classes, API, and functions. It is a great resource for developers to learn about the WooCommerce functionality and how to extend it. Explore the [WooCommerce Code Reference](https://woocommerce.github.io/code-reference/) documentation. --- ## WooCommerce Dual API *Source: apis/dual-api/README.md* # WooCommerce Dual API The **dual API** is a code-first API architecture: you write plain PHP classes (the **code API**), and a build script generates a fully functional **GraphQL API** that mirrors them. The two are kept in sync from a single, manually maintained source (the code API) so there is one place to add behavior and two ways to consume it (in-process PHP calls and GraphQL-over-HTTP). WooCommerce core ships its own dual API, but the underlying infrastructure is reusable: a plugin can define its own code API and get a matching GraphQL endpoint with the same tooling. ## Status: experimental, and a proof of concept > **This feature is experimental.** Everything under the `Automattic\WooCommerce\Api` namespace can change in backwards-incompatible ways, or be removed, in any release. Do not use it in production extensions. There are two separate parts to understand: - **The infrastructure** (the build tooling, attributes, authorization model, engine-decoupling layer): Implementing a robust and stable infrastructure has been for now the main focus of the development efforts. - **WooCommerce core's own code API** (the `coupons` and `products` queries/mutations): This is a **proof of concept**. It exists to exercise the infrastructure and will likely change significantly or be replaced in the short term. Treat it as an example, not a contract. This dual API, both the infrastructure and the proof of concept code API, has been introduced as an experimental feature in WooCommerce 10.9. ## Requirements - **PHP 8.1+.** The code API uses enums, named arguments, and PHP 8 attributes. On PHP 8.0 or older the GraphQL endpoint is not registered. - **The `dual_code_graphql_api` feature flag.** It is hidden (not shown on the Features settings page). Enable it with: ```bash wp option update woocommerce_feature_dual_code_graphql_api_enabled yes ``` When the flag is off, no GraphQL route is registered. This gates **every** dual-API endpoint, the one in WooCommerce core **and** any registered by plugins. Code that touches the code API classes directly should guard on `FeaturesUtil::feature_is_enabled( 'dual_code_graphql_api' )`. The settings and filters are likewise site-wide and shared across all dual-API endpoints (see [Settings and caching](./caching-and-settings.md#scope-what-applies-where)). ## Which document do I need? | Your question | Start here | | --- | --- | | What is this and how does it fit together? | [Architecture](./architecture.md) | | How do I add to or change WooCommerce's code API? | [Extending the code API](./extending-the-code-api.md) | | How do I paginate a list query? | [Relay-style pagination](./pagination.md) | | How do I build my own dual API in a plugin? | [Creating a dual API in a plugin](./creating-a-dual-api-in-a-plugin.md) | | How does authentication and authorization work? | [Authentication and authorization](./authentication-and-authorization.md) | | How do I attach and query schema metadata? | [Metadata and discovery](./metadata.md) | | How do I configure the endpoint and caching? | [Settings and caching](./caching-and-settings.md) | | How do I regenerate the GraphQL code, and what is the staleness check? | [Building and staleness checks](./building-and-staleness.md) | | The infrastructure or the builder is missing something, how do I change it safely? | [Extending the infrastructure](./extending-the-infrastructure.md) | Reference material (lookup tables, exact signatures): - [Recognized directories](./reference/directories.md) - [Attributes](./reference/attributes.md) - [Recognized methods and parameters](./reference/recognized-methods-and-parameters.md) - [Infrastructure classes](./reference/infrastructure-classes.md) - [Exceptions](./reference/exceptions.md) ## Audience The primary audience for this documentation is **maintainers of WooCommerce's code API** and **developers building their own dual API in a plugin**. The secondary audience is **maintainers of the dual-API infrastructure** itself. Throughout these docs, rules introduced as "in a plugin" generally apply equally when extending WooCommerce core's own code API; where a rule is core-only or plugin-only, that is called out explicitly. ## A working example The [`woocommerce-simple-events`](https://github.com/woocommerce/woocommerce-simple-events) plugin is a runnable reference that exercises the infrastructure end to end: custom authentication, custom authorization attributes, granular field-level gates, pagination, scalars, and more. These docs link to it for complete, copy-pasteable examples. --- ## Dual API architecture *Source: apis/dual-api/architecture.md* # Dual API architecture This document explains how the pieces fit together. For how to actually write classes, see [Extending the code API](./extending-the-code-api.md). ## Two halves, one source The dual API has two halves: - **The code API**: plain PHP classes under `src/Api/`. They are GraphQL-agnostic: they import nothing from any GraphQL library and work as a standalone, in-process PHP API. This is the **authoritative, manually maintained source**. - **The autogenerated GraphQL layer**: code under `src/Internal/Api/Autogenerated/` produced by a build script from the code API. It is committed to source control but **never hand-edited**. It powers a GraphQL endpoint (by default `POST|GET /wp-json/wc/graphql`). The build script reads the code API and (re)generates the GraphQL layer. The relationship is one-directional: you change PHP classes, then regenerate. ```text src/Api/ ──(build:api)──▶ src/Internal/Api/Autogenerated/ ──▶ /wp-json/wc/graphql (you edit this) (generated, committed, never edited) (GraphQL endpoint) ``` Because the generated tree is committed to source code, regenerating it after a source change is mandatory; a [staleness check](./building-and-staleness.md) enforces this in GitHub's CI pipeline for pull requests. ## Code-first and the command pattern The code API is organized around the [**command pattern**](https://en.wikipedia.org/wiki/Command_pattern): each query or mutation is a class with a single `execute()` method (plus an optional `authorize()` method). Output types, input types, enums, interfaces, and scalars are likewise plain classes/enums. ```php #[Name( 'product' )] #[Description( 'Retrieve a single product by ID.' )] #[RequiredCapability( 'read_product' )] class GetProduct { #[ReturnType( Product::class )] public function execute( int $id ): ?object { // ... } } ``` The build script infers as much as it can from code structure and uses [**PHP 8 attributes**](https://www.php.net/manual/en/language.attributes.php) only where structure is not enough. ## Convention over configuration Two conventions drive most behavior: - **Directory placement determines role.** A class in `Queries/` becomes a GraphQL query; one in `Types/` becomes an output type; one in `Enums/` becomes an enum; and so on. Arbitrary nested subdirectories are allowed for organization (e.g. `Queries/Coupons/GetCoupon.php`) - nesting does not change the role. See [Recognized directories](./reference/directories.md). - **Names are derived, then overridable.** GraphQL type names default to the PHP class name; query/mutation names to its camelCase form; fields to property names as-is; enum values from PascalCase to `SCREAMING_SNAKE_CASE`. Any of these can be overridden with `#[Name( '...' )]`. Attributes fill the gaps that conventions cannot: descriptions, authorization, type shaping (arrays, connections, custom scalars), deprecation, and metadata. See the [Attributes reference](./reference/attributes.md). ## The GraphQL engine is an implementation detail The GraphQL endpoint is currently powered by the [webonyx/graphql-php](https://github.com/webonyx/graphql-php) package, vendored and re-namespaced to `Automattic\WooCommerce\Vendor\GraphQL\*` to avoid version conflicts with other plugins. This is deliberately hidden from code-API authors. The autogenerated code never references `Vendor\GraphQL\*` directly: it references only a thin, WooCommerce-owned **schema surface** under `Api\Infrastructure\Schema\*`. That surface is the single point of contact with the engine, so the engine could be replaced in the future without breaking already-committed generated code in plugins. As a code-API author you never see GraphQL types at all; as an infrastructure maintainer, see [Extending the infrastructure](./extending-the-infrastructure.md). ## Where things live | Path | Contents | Edit? | | --- | --- | --- | | `src/Api/` | The code API: attributes, queries, mutations, types, input types, enums, interfaces, scalars, pagination, utils | Yes, this is the source | | `src/Api/Infrastructure/` | Public, engine-decoupled runtime surface and convention classes (`Principal`, `ClassResolver`, `GraphQLControllerBase`, the `Schema\*` wrappers, ...) | Rarely; infrastructure only | | `src/Internal/Api/Autogenerated/` | Generated GraphQL resolvers and type definitions | No, regenerate instead | | `src/Internal/Api/` | Internal runtime not referenced by external code (`QueryCache`, `Settings`, endpoint registrar, query rules) | Rarely; core only | | `bin/api-builder/` | The build tooling (`ApiBuilder`, `build-api.php`, staleness checker, templates). Not shipped in release builds | Rarely; infrastructure only | The generated tree mirrors the role directories: `Autogenerated/GraphQLQueries/`, `GraphQLMutations/`, and `GraphQLTypes/{Output,Input,Enums,Interfaces,Scalars,Pagination}/`, plus a `RootQueryType`, `RootMutationType`, and `TypeRegistry`. ## Request lifecycle (summarized) When a GraphQL request hits the endpoint, the controller (a generated subclass of `GraphQLControllerBase`): 1. Resolves a **principal** for the request (who is calling) via the configured `PrincipalResolver`. 2. Parses and validates the query (depth and complexity limits; optional caching of the parsed AST). 3. Runs the resolvers, which look up the corresponding command class through the `ClassResolver`, check authorization, and call `execute()`. 4. Formats the result (or errors) and picks an HTTP status code (optionally via a plugin-supplied `HttpStatusResolver`). Each of these steps is a documented extension point; see [Authentication and authorization](./authentication-and-authorization.md), [Settings and caching](./caching-and-settings.md), and [Infrastructure classes](./reference/infrastructure-classes.md). ## Reusable by plugins Everything above applies to a plugin that wants its own dual API. A plugin defines its own `src/Api/` tree, runs the same builder against it, commits the generated output to its own repo, and registers a dedicated GraphQL endpoint. It reuses WooCommerce's infrastructure and can supply its own convention classes (authentication, class resolution, status codes) and attributes where it needs to diverge from the defaults. See [Creating a dual API in a plugin](./creating-a-dual-api-in-a-plugin.md). --- ## Authentication and authorization *Source: apis/dual-api/authentication-and-authorization.md* # Authentication and authorization Authentication and authorization in the dual API revolve around a [**security principal**](https://en.wikipedia.org/wiki/Principal_(computer_security)): a per-request object representing who is calling. Authentication produces the principal; authorization decides what that principal may do, expressed through **attributes**. ## The principal Each request resolves to exactly one principal, produced once by a `PrincipalResolver`. The default core resolver wraps the current WordPress user: ```php final class PrincipalResolver { public function resolve_principal(): Principal { return new Principal( wp_get_current_user() ); } } ``` The default `Principal` carries the `WP_User` and exposes: - `is_authenticated(): bool`: `true` when `user->ID > 0`. Anonymous requests are **not** signalled by `null`; they're a real principal whose user has ID 0. - `can_introspect(): bool`: defaults to true only when the user has the `manage_woocommerce` capability. - `can_use_debug_mode(): bool`: defaults to true only when the user has the `manage_options` capability. Plugins authenticating against something else (app token, signed webhook, ...) ship their own `PrincipalResolver` and principal class. The resolver's **return type declares the plugin's principal type**, which ApiBuilder uses to type-check `authorize()`/`$_principal` signatures at build time. A resolver may take an optional `\WP_REST_Request $request` parameter, or none. To reject bad credentials, throw `UnauthorizedException` or `InvalidTokenException` from the resolver. See [Creating a dual API in a plugin](./creating-a-dual-api-in-a-plugin.md) and [Infrastructure classes](./reference/infrastructure-classes.md). ## Authorization attributes Authorization is declarative. Core ships two attributes: - `#[PublicAccess]`: no authentication required (`authorize()` always returns `true`). - `#[RequiredCapability( 'capability-name' )]`: requires the principal to hold a WordPress capability. Repeatable; multiple capabilities are ANDed (so all the capabilities are required in the user for authorization to succeed). ```php #[RequiredCapability( 'read_private_shop_coupons' )] class ListCoupons { /* ... */ } ``` An attribute is recognized as an authorization attribute by **convention**: it declares a public `authorize()` method returning `bool`. The first non-underscore parameter receives the principal: ```php public function authorize( MyPrincipal $principal ): bool { /* ... */ } // or, for unconditional access: public function authorize(): bool { return true; } ``` Plugins define their own authorization attributes (e.g. `#[RequiresScope( 'events:read' )]`) the same way, see the [Attributes reference](./reference/attributes.md). This is the recommended approach; it keeps authorization separate from business logic. ### The `authorize()` method on commands For logic that doesn't fit an attribute, a query/mutation class can declare its own `authorize()` method. Compose it with the attribute decision via the `bool $_preauthorized` parameter (which will receive `true` if the attribute gates already grant): ```php public function authorize( int $id, bool $_preauthorized, MyPrincipal $_principal ): bool { return $_preauthorized || $_principal->owns( $id ); } ``` ## Granular (type- and field-level) authorization Authorization attributes apply at four levels: | Target | Effect | | --- | --- | | **Query / mutation** (class) | Gates the whole operation. | | **Output type** (class) | AND-composed into every field gate of that type (including via a trait the type uses). | | **Output field** (property) | Gates that field; re-evaluated per item when the field is a list. | | **Input field** (property) | Gates the field, but only when it was actually provided in the request. | `#[PublicAccess]` on a property is a no-op (it always grants) and produces a build warning. `authorize()` methods can opt into three more context parameters, supplied per call site, detected by name, in any order: - `array $_metadata`: `#[Metadata]` entries visible at the call site, in up to three slices: `['query']` (originating operation), `['type']` (enclosing type), `['field']` (the gated field). - `array $_args`: the GraphQL arguments at the call site. - `mixed $_parent`: the enclosing object being resolved (for an output-field gate, the parent object; lets you implement owner-or-scope checks). ```php #[Attribute( Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY )] final class OwnerOrScope { public function __construct( public readonly string $scope ) {} public function authorize( EventsPrincipal $principal, mixed $_parent ): bool { return $principal->has_scope( $this->scope ) || ( is_object( $_parent ) && $_parent->organizer_login === $principal->user_login ); } } ``` ### Deny shape and HTTP status When a gate denies: - **Operation-level** denies produce the bare authorization error. - **Field-level** denies attach `extensions.subject = { type, field, attribute }` alongside the preserved `extensions.code`. The error code and HTTP status depend on whether the principal is authenticated: - **Anonymous** principal (`is_authenticated()` returns `false`) → `UNAUTHORIZED` / **401** (authenticating might help). - **Authenticated** principal, or one that doesn't expose `is_authenticated()` → `FORBIDDEN` / **403** (authenticating won't help). Credential problems surfaced by the resolver use `UNAUTHORIZED` (401) or `INVALID_TOKEN` (401). See [Exceptions](./reference/exceptions.md). ## Introspection, debug mode, and metadata gating Three sensitive surfaces are gated independently, each by a combination of a principal method, a filter, and a fail-closed default: | Surface | Principal method | Filter | Default if method absent | | --- | --- | --- | --- | | Native introspection (`__schema`, `__type`) | `can_introspect()` | `woocommerce_graphql_can_introspect` | deny | | Debug mode (also requires `_debug=1`) | `can_use_debug_mode()` | `woocommerce_graphql_can_use_debug_mode` | deny | | `_apiMetadata` discovery | `can_query_metadata()`, else falls back to `can_introspect()` | `woocommerce_graphql_can_query_metadata` | deny | All three gates **fail closed**: - A `null`/unresolved principal denies. - The principal method's return is checked with `=== true` (a truthy non-bool denies). - A throw from the method or filter is caught and treated as a deny. - Filters must return strictly `true` to grant; loose values like `1` or `'yes'` deny. The filters receive `( bool $decision, ?object $principal, \WP_REST_Request $request )`. They are **not** invoked when principal resolution itself failed. They are also **site-wide**: a callback affects every dual-API endpoint on the site (core and plugins), so branch on the `$request` route if it should apply to only one; see [Scope: what applies where](./caching-and-settings.md#scope-what-applies-where). The core `Principal` declares `can_introspect()` (gated on `manage_woocommerce`), which also governs `_apiMetadata` since it has no `can_query_metadata()` - so admin access to both works out of the box, and other principals are denied unless they opt in. Example override: ```php add_filter( 'woocommerce_graphql_can_introspect', fn( bool $can, $principal, \WP_REST_Request $request ): bool => $can || 'true' === $request->get_param( 'x-allow-introspection' ), 10, 3 ); ``` ## Pre-authorization for code-API callers Code that calls the code API directly (not through GraphQL) can ask whether the attribute gates would grant access for a principal, without executing the command, via `ResolverHelpers::compute_preauthorized( string $command_fqcn, object $principal ): bool`. --- ## Building and staleness checks *Source: apis/dual-api/building-and-staleness.md* # Building and staleness checks The GraphQL layer is generated from the code API by a build script and **committed to source control**. This document covers the commands and the check that keeps the committed output in sync with its source. ## Regenerating From `plugins/woocommerce/`: ```bash # Regenerate core's GraphQL layer from src/Api/ pnpm --filter=@woocommerce/plugin-woocommerce build:api # Regenerate the test fixture's tree (the DummyApi used by the test suite) pnpm --filter=@woocommerce/plugin-woocommerce build:api:test # Check whether the committed output is stale (used by CI) pnpm --filter=@woocommerce/plugin-woocommerce build:api:check ``` `build:api` runs `php bin/api-builder/build-api.php`. It **wipes and regenerates** the output directory, formats the result with `phpcbf`, refreshes the Composer autoloader, and writes the staleness-tracking files. The build tooling under `bin/api-builder/` is excluded from release builds. After regenerating, commit the `src/Api/` change and the regenerated `src/Internal/Api/Autogenerated/` tree **together**. ## `build-api.php` flags `build-api.php` with no flags produces core's output. The four path/namespace flags are **all-or-nothing** - provide all four or none: | Flag | Meaning | | --- | --- | | `--api-dir=PATH` | Directory of code-API source classes to scan. | | `--autogen-dir=PATH` | Output directory (**wiped each run**). | | `--api-namespace=NS` | PSR-4 namespace mapping to `--api-dir`. | | `--autogen-namespace=NS` | PSR-4 namespace mapping to `--autogen-dir`. | | `--composer-working-dir=DIR` | Where to run `composer dump-autoload`. | | `--phpcbf-path=PATH` | Path to the `phpcbf` binary used for formatting. | | `--no-linter` | Skip the `phpcbf` formatting pass. | For fast local iteration, pass `--no-linter`: the `phpcbf` pass is the slowest step in the build, and it only affects whitespace in the generated PHP — the code is functionally identical with or without it. Run a full build (without the flag) before committing so the formatted output is what lands in source control. `ApiBuilder::run_for_plugin()` also honours `--no-linter` from `argv`, so the same shortcut works for plugin builds: `WC_PATH=… php bin/build-api.php --no-linter`. Plugins generally don't call the other flags directly; they use `ApiBuilder::run_for_plugin()` (see [Creating a dual API in a plugin](./creating-a-dual-api-in-a-plugin.md)). ## The staleness check `build:api:check` (`php bin/api-builder/check-api-staleness.php`) fails when the committed generated tree doesn't match the current source. The check is **content-based**, not timestamp-based: `build:api` writes a SHA-256 hash of every `.php` file under the source dir (each file hashed as `relative_path \0 contents \0`, files sorted by path) into `api_source_hash.txt` in the output directory. `StalenessChecker::is_stale()` recomputes that hash and compares. Because it ignores mtimes and filesystem iteration order, it behaves identically on fresh clones, in CI, and during active development. (`api_generation_date.txt` is also written, for human reference only.) ## CI enforcement The `.github/workflows/api-staleness.yml` workflow (**GraphQL API Staleness Check**) runs `build:api:check` on PRs and pushes that touch: - `plugins/woocommerce/src/Api/**` - `plugins/woocommerce/src/Internal/Api/Autogenerated/**` - `plugins/woocommerce/bin/api-builder/**` - the workflow file itself If the source was changed without regenerating, the job fails with `Generated GraphQL API code is out of date.` Regenerate, commit, and push to clear it. Plugins that maintain their own dual API should add an equivalent check to their own CI. --- ## Settings and caching *Source: apis/dual-api/caching-and-settings.md* # Settings and caching WooCommerce core's GraphQL endpoint is configured under **WooCommerce → Settings → Advanced → GraphQL**. The section appears only when the `dual_code_graphql_api` feature flag is on. These settings are **site-wide, not per-endpoint**: every setting below except **Endpoint URL** applies to *every* dual-API endpoint on the site, including those registered by plugins. See [Scope: what applies where](#scope-what-applies-where). ## Settings | Setting | Option name (`Main::` constant) | Type | Default | Effect | | --- | --- | --- | --- | --- | | Endpoint URL | `woocommerce_graphql_endpoint_url` (`OPTION_ENDPOINT_URL`) | text | `wc/graphql` | **Core's `/wc/graphql` only.** Path under `/wp-json/`. Must be at least two segments (`namespace/route`); validated and normalized on save. Plugins set their own route when they register an endpoint, so this setting does not affect them. | | Enable GET endpoint | `woocommerce_graphql_get_endpoint_enabled` (`OPTION_GET_ENDPOINT_ENABLED`) | checkbox | `yes` | When off, the endpoint accepts POST only; GET returns 404. Mutations are always rejected over GET. | | Maximum query depth | `woocommerce_graphql_max_query_depth` (`OPTION_MAX_QUERY_DEPTH`) | number | `15` | Rejects queries nested deeper than this during validation. Falls back to default when unset or non-positive. | | Maximum query complexity | `woocommerce_graphql_max_query_complexity` (`OPTION_MAX_QUERY_COMPLEXITY`) | number | `1000` | Rejects queries whose computed complexity score exceeds this. Connection fields multiply child cost by page size. | | Parsed query cache TTL | `woocommerce_graphql_query_cache_ttl` (`OPTION_QUERY_CACHE_TTL`) | number | `86400` | Seconds before cached parsed queries expire (object cache and APQ paths). | | Enable OPcache-based caching | `woocommerce_graphql_opcache_enabled` (`OPTION_OPCACHE_ENABLED`) | checkbox | `yes` | Cache parsed ASTs as PHP files served from OPcache shared memory. | | Enable ObjectCache-based caching | `woocommerce_graphql_object_cache_enabled` (`OPTION_OBJECT_CACHE_ENABLED`) | checkbox | `yes` | Cache parsed ASTs in the WP object cache. | | Enable APQ caching | `woocommerce_graphql_apq_enabled` (`OPTION_APQ_ENABLED`) | checkbox | `yes` | Support the Apollo Automatic Persisted Queries protocol (`persistedQuery` extension). When off, hash-only requests are rejected. | The depth and complexity metrics are observable on a request by appending `?_debug=1` (when the principal may use debug mode); the response carries `extensions.debug.depth` and `extensions.debug.complexity`. ## Scope: what applies where The dual API has one set of switches and filters shared by every endpoint on the site, there is no per-plugin configuration surface. Concretely: - **The `dual_code_graphql_api` feature flag gates every dual-API endpoint.** When it's off, neither core's `/wc/graphql` nor any plugin endpoint is registered (`Main::register_graphql_endpoint()` is a no-op). PHP 8.1+ is required the same way. - **Every setting except Endpoint URL applies to all endpoints.** The GET toggle, max depth, max complexity, the three caching toggles, and the cache TTL are read from the shared infrastructure, so a plugin endpoint honours them exactly as core's does (for example, plugin endpoints reject GET when the GET toggle is off). **Endpoint URL is the exception**: it only configures core's `/wc/graphql`; a plugin chooses its own route at registration. - **The filters below are global.** A callback added to any of them affects *every* dual-API endpoint on the site, core and plugins alike. Each filter receives the `\WP_REST_Request`, so a callback that should apply to only one endpoint must branch on the request's route itself. ## Query caching Parsing a GraphQL query into an AST is the expensive, repeatable step, so the framework caches parsed ASTs. On each request the resolution chain is: 1. **OPcache file backend**: when its toggle is on, the OPcache extension is loaded, and the cache directory is writable. Parsed ASTs are written as `return [...];` PHP files under `wp-content/uploads/wc-graphql-cache/v/`; OPcache serves them as compiled bytecode (no string parse, no `unserialize`, no remote cache call). 2. **WP object cache**: otherwise, when its toggle is on. 3. **No cache**: parse on every request. Notes: - The cache key/version is tied to the query string and the parser version, so there's no correctness TTL concern on the file backend; the configurable TTL applies to the object-cache and APQ paths. - OPcache writes are atomic (temp file + `rename()`), drop a deny-all `.htaccess`, and pre-warm the bytecode. Expired files are cleaned up via a scheduled `woocommerce_graphql_opcache_cleanup` action. - APQ always uses the object cache for hash-only lookups, regardless of the standard-query toggles, preserving persisted-query semantics. ## Relevant filters | Filter | Signature | Purpose | | --- | --- | --- | | `woocommerce_graphql_opcache_cache_dir` | `( string $dir )` | Override the OPcache file directory (default `{uploads}/wc-graphql-cache/v`). Empty strings and stream wrappers are rejected. | | `woocommerce_graphql_can_introspect` | `( bool, ?object $principal, \WP_REST_Request )` | Gate native introspection. See [Authentication and authorization](./authentication-and-authorization.md). | | `woocommerce_graphql_can_use_debug_mode` | `( bool, ?object $principal, \WP_REST_Request )` | Gate debug mode. | | `woocommerce_graphql_can_query_metadata` | `( bool, ?object $principal, \WP_REST_Request )` | Gate `_apiMetadata`. See [Metadata](./metadata.md). | ## Customizing the response HTTP status A plugin can override the HTTP status of any response (for example, always return 200) by shipping an `HttpStatusResolver` convention class. Core ships none, so its per-error-code mapping is the default. See [Creating a dual API in a plugin](./creating-a-dual-api-in-a-plugin.md) and [Infrastructure classes](./reference/infrastructure-classes.md). --- ## Creating a dual API in a plugin *Source: apis/dual-api/creating-a-dual-api-in-a-plugin.md* # Creating a dual API in a plugin A plugin can define its own code API and get a matching GraphQL endpoint using WooCommerce's infrastructure. The plugin writes its own classes under `src/Api/`, runs the same builder against them, commits the generated tree to its own repo, and registers a dedicated endpoint. > The full, runnable reference for everything here is the [`woocommerce-simple-events`](https://github.com/woocommerce/woocommerce-simple-events) plugin. The snippets below are condensed; see that repo for complete files. ## Prerequisites - WooCommerce installed with the `dual_code_graphql_api` feature flag enabled, on PHP 8.1+. - The plugin's own Composer autoloader (PSR-4) and a `vendor/autoload.php`. The endpoint is **dedicated**: each plugin registers its own REST route. You cannot federate into core's `/wc/graphql`. ## 1. Lay out the code API Use the same [directory conventions](./reference/directories.md) as core, under your plugin's namespace: ```text my-plugin/ ├── bin/build-api.php ├── src/Api/ │ ├── Queries/ Mutations/ Types/ InputTypes/ │ ├── Enums/ Interfaces/ Scalars/ │ ├── Attributes/ ← custom attributes (optional) │ └── Infrastructure/ ← custom convention classes (optional) └── src/Internal/Api/Autogenerated/ ← generated; committed ``` Writing the code-API classes is identical to core, see [Extending the code API](./extending-the-code-api.md). ## 2. Add the build script A plugin's `bin/build-api.php` is a thin wrapper around `ApiBuilder::run_for_plugin()`: ```php \Api`), output at `$plugin_root/src/Internal/Api/Autogenerated` (namespace `\Internal\Api\Autogenerated`). Run it with `WC_PATH= php bin/build-api.php` (or a `package.json` script), and commit the generated tree. See [Building and staleness checks](./building-and-staleness.md), and add an equivalent staleness check to your CI. > `ApiBuilder` lives under WooCommerce's `bin/api-builder/` and is registered via `autoload-dev`, so it is only resolvable from a dev-mode WooCommerce install. It is not shipped in release builds. ## 3. Register the endpoint In your plugin bootstrap, register the route through core's `Main`: ```php use Automattic\WooCommerce\Api\Infrastructure\Main as WooCommerceApiMain; add_action( 'plugins_loaded', static function () { if ( ! method_exists( WooCommerceApiMain::class, 'register_graphql_endpoint' ) ) { return; // WooCommerce too old, or feature/PHP unavailable } WooCommerceApiMain::register_graphql_endpoint( __DIR__, 'my-plugin', '/graphql' ); } ); ``` The first argument may be your plugin directory (the controller class is resolved by convention) or the fully-qualified controller class name. This is a no-op when the feature flag is off or PHP is < 8.1. Your endpoint goes through the same request pipeline as core's and inherits the core [GraphQL settings](./caching-and-settings.md). ## 4. Reuse or replace the convention classes ApiBuilder detects a small set of **convention classes** at `\Api\Infrastructure\*`. Ship one only when you need to diverge from the default; otherwise core's default applies. The same overriding mechanism is what core itself uses. | Class | Default | Ship your own to… | | --- | --- | --- | | `ClassResolver` | `wc_get_container()->get()` | Instantiate commands through your own DI container. | | `PrincipalResolver` | wraps `wp_get_current_user()` | Authenticate against something other than WP users. Its return type declares your principal type. | | `Principal` | wraps `WP_User` | Carry your own identity/permission data. Add `is_authenticated()`, and `can_introspect()`/`can_query_metadata()`/`can_use_debug_mode()` to opt into those surfaces. | | `HttpStatusResolver` | none (per-error-code map) | Override response HTTP status, e.g. always return 200. | See [Infrastructure classes](./reference/infrastructure-classes.md) for exact signatures. Custom authentication example (HTTP basic against a fixed credential, role in a header): ```php namespace Automattic\MyPlugin\Api\Infrastructure; use Automattic\WooCommerce\Api\InvalidTokenException; final class PrincipalResolver { public function resolve_principal( \WP_REST_Request $request ): EventsPrincipal { $user = $_SERVER['PHP_AUTH_USER'] ?? null; $pass = $_SERVER['PHP_AUTH_PW'] ?? null; if ( null === $user || null === $pass ) { return EventsPrincipal::anonymous(); } if ( 'password' !== $pass || ! isset( EventsPrincipal::SCOPES_BY_ROLE[ $user ] ) ) { throw new InvalidTokenException(); } return new EventsPrincipal( $user, $user, EventsPrincipal::SCOPES_BY_ROLE[ $user ] ); } } ``` ## 5. Define custom attributes and exceptions (optional) - **Attributes:** a class in your `Api/Attributes/` becomes an authorization attribute by declaring `authorize( $principal ): bool`, a metadata attribute by extending `Metadata`, and so on. See [Attributes reference](./reference/attributes.md). Authorization attributes can gate operations, types, fields, and arguments. - **Exceptions:** extend `ApiException` (or a subclass) to pin your own `(error code, HTTP status)`. See [Exceptions reference](./reference/exceptions.md). ## 6. Engine-decoupling guarantee Your committed generated tree references only WooCommerce's public `Api\Infrastructure\*` surface, never the underlying GraphQL engine (`Vendor\GraphQL\*`). If WooCommerce ever swaps engines, that surface absorbs the change and **your already-committed generated code keeps working**. The flip side: never write code (generated or hand-written) that imports from `Vendor\GraphQL\*` or from `Internal\Api\*`. See [Architecture](./architecture.md) and [Extending the infrastructure](./extending-the-infrastructure.md). --- ## Extending the code API *Source: apis/dual-api/extending-the-code-api.md* # Extending the code API This guide covers how to add to or change the code API (the PHP classes the GraphQL layer is generated from). It applies both to WooCommerce core's own code API and to the ones implemented by plugins (see [Creating a dual API in a plugin](./creating-a-dual-api-in-a-plugin.md) for the plugin-specific bootstrap). > Reminder: core's `coupons`/`products` API is a proof of concept and may change. Use it as a pattern, not a stable contract. ## The workflow 1. Add or edit classes under `src/Api/`. 2. Regenerate the GraphQL layer: `pnpm --filter=@woocommerce/plugin-woocommerce build:api`. 3. Run the tests and the [staleness check](./building-and-staleness.md). 4. Commit the source change **and** the regenerated `Autogenerated/` tree together. You never edit the generated tree by hand. If a generated file looks wrong, fix the source class or the underlying templates and regenerate. ## Queries and mutations A query or mutation is a class with one public `execute()` method. Place it under `Queries/` or `Mutations/` (nested subdirectories are fine). The GraphQL field name defaults to the camelCase form of the class name; override with `#[Name]`. ```php #[Name( 'coupon' )] #[Description( 'Retrieve a single coupon by ID or code.' )] #[RequiredCapability( 'read_private_shop_coupons' )] class GetCoupon { public function execute( #[Description( 'The ID of the coupon to retrieve.' )] ?int $id = null, #[Description( 'The coupon code to look up.' )] ?string $code = null, ): ?Coupon { // ... } } ``` - **Arguments** come from `execute()` parameters; their GraphQL types are inferred from the PHP type declarations. A non-nullable parameter (`int $id`) becomes a non-null argument (`Int!`); a nullable parameter (`?int $id`) becomes a nullable argument (`Int`). An argument is **optional** (the client may omit it) when it is nullable **or** has a default value; so `?int $id` is optional even without a default, and only a non-nullable parameter with no default is **required**. A default value is additionally exposed as the argument's GraphQL default. Add per-argument docs with `#[Description]` on the parameter. - **Return type** comes from the PHP return type. When `execute()` returns a GraphQL interface - which in the code API is implemented as a PHP trait (see [Enums, interfaces, scalars](#enums-interfaces-scalars) below), and a trait can't be used as a return type hint - declare it with `#[ReturnType( SomeInterface::class )]` and return `object`. - **Errors:** throw a plain `\InvalidArgumentException` for malformed input (will be mapped to `INVALID_ARGUMENT` / 400), or one of the [exception classes](./reference/exceptions.md) to pin a specific error code and HTTP status. Mutations are identical except for the directory. They typically take a single input-type argument and return an output type or a dedicated result type. ## Output types Classes under `Types/` become GraphQL output types. Public properties become fields, named as-is (snake_case is preserved). Type mapping is inferred from the PHP property type. ```php #[Description( 'Represents a WooCommerce discount coupon.' )] class Coupon { use ObjectWithId; // contributes the `id` field #[Description( 'The coupon code.' )] public string $code; #[Description( 'The type of discount.' )] public DiscountType $discount_type; // enum #[Description( 'The date the coupon was created.' )] #[ScalarType( DateTime::class )] public ?string $date_created; // custom scalar #[Description( 'Product IDs the coupon can be applied to.' )] #[ArrayOf( 'int' )] public array $product_ids; // list type } ``` Useful attributes on properties: - `#[ArrayOf( 'int' )]` / `#[ArrayOf( SomeType::class )]`: element type of an `array` property. - `#[ScalarType( DateTime::class )]`: render a property through a custom scalar. The property is typically a `string` holding the scalar's raw form (e.g. an ISO date), but it isn't required to be: any value the scalar's `serialize()` accepts works; the property's nullability still controls the field's nullability. - `#[ConnectionOf( SomeType::class )]` on a `Connection`-typed property: a nested paginated connection field (see [Relay-style pagination](./pagination.md)). - `#[Deprecated( 'reason' )]`: mark the field as deprecated (will be visible as such in [GraphQL introspection](https://graphql.org/learn/introspection/)). - `#[Ignore]`: exclude the property from the schema. - `#[Parameter( ... )]` / `#[ParameterDescription( ... )]`: give a field computed arguments (e.g. a `formatted` flag on a price field). See the [Attributes reference](./reference/attributes.md) for exact signatures. ## Input types Classes under `InputTypes/` become GraphQL input types. A field is optional when its type is nullable **or** it has a default value; a non-nullable field with no default is required. (The example below uses nullable-with-default for optional fields, which is the common shape.) Use the `TracksProvidedFields` trait to distinguish "field omitted" (leave unchanged) from "field explicitly set to null" (clear it) - essential for patch-style update mutations: ```php class CreateCouponInput { use TracksProvidedFields; public string $code; // required public ?string $description = null; // optional } ``` In the consuming `execute()`, call `$input->was_provided( 'description' )` to check whether the client actually sent the field. This works on any input type that uses the trait, whether it's an argument to a mutation (the common case, for patch-style updates) or to a query - the operation resolver populates the tracker when it builds the input object. The exception is an `#[Unroll]`ed input parameter: its fields are flattened into separate arguments and the object is rebuilt through a different path, so `was_provided()` isn't populated there. ## Enums, interfaces, scalars - **Enums** (`Enums/`) are backed PHP enums. Case names convert from PascalCase to `SCREAMING_SNAKE_CASE` (e.g. `FixedCart` → `FIXED_CART`); override with `#[Name]`. Add `#[Description]` to the enum and each case. A common pattern is an `Other` case plus a `raw_*` field on the type, so plugin-added values don't break the enum. - **Interfaces** (`Interfaces/`) are PHP **traits** marked with `#[Name]`/`#[Description]`. A type that `use`s the trait implements the interface. Traits can compose other traits (e.g. `Product` uses `ObjectWithId`). - **Scalars** (`Scalars/`) are classes with static `serialize( mixed $value ): string` (PHP → transport) and `parse( string $value ): mixed` (client → PHP, throwing `\InvalidArgumentException` on bad input). Apply one to a field with `#[ScalarType]`. ### Why interfaces are PHP traits GraphQL interfaces are modeled as PHP **traits** rather than PHP `interface`s for a concrete reason: in the code API a type's fields are its public **properties**, and a PHP interface can only declare methods, not properties. A trait, by contrast, can declare the shared properties *and* inject them into every type that `use`s it; so a single trait both defines the interface's field set and physically contributes those fields to each implementer. The builder treats a trait placed under `Interfaces/` as a GraphQL interface and registers every output type that uses it as an implementer. (This is also why a query/mutation returning an interface can't type-hint it directly - a trait isn't a usable return type - and instead uses `#[ReturnType]`; see [Queries and mutations](#queries-and-mutations).) A trait that lives **outside** `Interfaces/` is just an ordinary code-sharing mixin: the builder does not turn it into a GraphQL type. This matters for **input types**: an input type may `use` traits to share fields or behavior (for example `TracksProvidedFields`, or a shared base of common input fields), but doing so never produces an "input interface". GraphQL defines interfaces only for output object types (there is no input-interface concept in the GraphQL specification) so there is nothing for the builder to generate. Interface modeling applies to output types only. ## Pagination (connections) List queries handle [pagination](https://graphql.org/learn/pagination/) with [Relay-style cursor connections](https://relay.dev/graphql/connections.htm): return a `Connection` and declare the node type with `#[ConnectionOf( ::class )]`, taking a `PaginationParams` argument (which `#[Unroll]`s into `first` / `last` / `after` / `before`). ```php #[Name( 'coupons' )] #[RequiredCapability( 'read_private_shop_coupons' )] class ListCoupons { #[ConnectionOf( Coupon::class )] public function execute( PaginationParams $pagination, ?CouponStatus $status = null ): Connection { // build Edge[] with cursors, a PageInfo, and a total_count } } ``` This is a whole topic of its own: cursors, `PageInfo` semantics, the page-size cap, nested connections, and the two ways to build a `Connection`. See **[Relay-style pagination](./pagination.md)**. ## Infrastructure parameters `execute()` and `authorize()` can declare specially named, underscore-prefixed parameters that the framework injects. They are optional, detected by name, and may appear in any order; declare only the ones you need: - `?array $_query_info`: the selection tree of the current query, for resolve-time optimization (e.g. skipping expensive joins for unrequested fields). - ` $_principal`: the resolved principal for the request. - `bool $_preauthorized`: in `authorize()`, whether the attribute-based gates already grant access (lets you compose custom logic on top). - `array $_metadata`, `array $_args`, `mixed $_parent`: context for `authorize()` in granular (type/field) authorization. See [Recognized methods and parameters](./reference/recognized-methods-and-parameters.md) for the full contract, and [Authentication and authorization](./authentication-and-authorization.md) for how authorization is wired. ## After you change anything Regenerate and commit the generated tree. The CI [staleness check](./building-and-staleness.md) fails any PR whose `src/Api/` source doesn't match its committed `Autogenerated/` output. --- ## Extending the infrastructure *Source: apis/dual-api/extending-the-infrastructure.md* # Extending the infrastructure This document is for maintainers of the dual-API infrastructure itself (the build tooling and the engine-integration layer), not for code-API authors. It is intentionally a high-level map; **the code itself is the primary source of truth** for the details. Key entry points: - Build tooling: `plugins/woocommerce/bin/api-builder/` (`ApiBuilder.php`, templates under `code-templates/`, `StalenessChecker.php`). - Engine surface: `plugins/woocommerce/src/Api/Infrastructure/Schema/` and its `README.md`. - Runtime helpers: `plugins/woocommerce/src/Api/Infrastructure/` (`GraphQLControllerBase`, `ResolverHelpers`, `MetadataController`, `QueryInfoExtractor`). ## The engine-decoupling surface The GraphQL engine (currently `webonyx/graphql-php`, vendored as `Automattic\WooCommerce\Vendor\GraphQL\*`) is treated as a replaceable implementation detail. The contract that makes this possible: > **Generated code, and any public signature on an `Api\Infrastructure\*` class, may reference the `Schema\*` surface but never `Vendor\GraphQL\*` directly.** `src/Api/Infrastructure/Schema/` is the single point of contact with the engine. Generated resolvers, types, and root types import only from there. This matters because plugins commit their generated trees to their own repos: routing every engine reference through this surface means a future engine swap in WooCommerce doesn't break already-committed plugin code. Method *bodies* may touch vendor symbols: that's WooCommerce's concern when the engine changes, not the plugin's. The surface uses three patterns (see `Schema/README.md`): - **Subclass** (`Schema`, `ObjectType`, `InputObjectType`, `EnumType`, `InterfaceType`, `CustomScalarType`, `Error`): empty subclasses of the engine class today; a future migration translates the config in the constructor. - **Static facade** (`Type`): delegates `int()`, `string()`, `nonNull()`, `listOf()`, etc.; return types intentionally omitted so the concrete class can change. - **Class alias** (`ResolveInfo`, `AST\StringValueNode`): used where the engine constructs the instances; registered eagerly in `aliases.php` (wired via `composer.json`'s `autoload.files`). ### Adding a symbol to the surface 1. Add a subclass / facade method / alias in the matching style. 2. Update the template that needs it to import from `Api\Infrastructure\Schema\*`. 3. Regenerate core (`build:api`) and the fixture (`build:api:test`); confirm the `Autogenerated/` diff is imports-only. 4. Add a row to the table in `Schema/README.md`. **Versioning is implicit in the namespace.** If a change would break already-committed plugin code, add a sibling namespace (e.g. `Schema\V2`) and teach the templates to emit against it; keep the current surface until the last dependent plugin migrates. An engine-migration checklist lives in `Schema/README.md`. ## ApiBuilder (in brief) `ApiBuilder` scans the code-API directory, reflects over each class (placement, type declarations, attributes), and renders the matching template into the output tree. It also: - Detects the per-plugin convention classes (`ClassResolver`, `PrincipalResolver`/its principal type, `HttpStatusResolver`) and wires them into the generated controller subclass. - Harvests authorization and `#[Metadata]` attributes into the generated resolvers and the `_apiMetadata` data. - Emits per-field authorization gates and the input-side "only if provided" gates. - Warns at build time about unresolvable attribute references (e.g. a missing `use` import) and errors on duplicate metadata names. It is **not** unit-tested directly; it's validated end-to-end against a comprehensive dummy code-API fixture under `tests/php/src/Internal/Api/Fixtures/DummyApi/`, whose generated output is committed alongside it. When you change the builder or templates, update the dummy API if needed and regenerate both core and the fixture (`build:api` + `build:api:test`), then run the `wc-phpunit-graphql` test suite. Treat a non-imports-only diff in the generated trees as a signal to review. ## Runtime helpers - `GraphQLControllerBase`: abstract base for the generated controller. Owns the request lifecycle: principal resolution, validation (depth/complexity), execution, error formatting, and HTTP status selection (`pick_status()`, optionally via a plugin `HttpStatusResolver`). Its public `build_schema()` returns the `Schema\Schema` wrapper, never the engine type. - `ResolverHelpers`: static helpers the generated resolvers call: exception translation, pagination construction, authorization checks, and `compute_preauthorized()`. - `MetadataController`: contributes the hand-written `_apiMetadata` field and its supporting types (which don't fit the standard templates). - `QueryInfoExtractor`: turns the engine's `ResolveInfo` into the `_query_info` tree. ## What stays internal `QueryCache`, `Settings`, the endpoint registrar, and the query depth/complexity rules remain under `Internal\Api\*`. No external code references them; they're wired by `Main` through the DI container. Keep them there unless an external consumer genuinely needs them - at which point move only the public-facing surface, following the same engine-decoupling rule. --- ## Metadata and discovery *Source: apis/dual-api/metadata.md* # Metadata and discovery The dual API can attach machine-readable **metadata** to schema elements (types, fields, arguments, enum values) and expose it for discovery. The first built-in uses are marking elements as internal or experimental, but the mechanism is general: plugins ship their own categories without infrastructure changes. ## Attaching metadata The base `#[Metadata( name, value )]` attribute attaches one name/value entry. It is repeatable and targets classes, properties, parameters, and enum cases. Values are restricted to `bool|int|float|string|null`. ```php #[Metadata( 'owner', 'payments-team' )] #[Metadata( 'beta', true )] class SomeType { /* ... */ } ``` Core ships two convenience subclasses: - `#[Internal]` — `name = 'internal'`, `value = true`. For WooCommerce-core-only elements. - `#[Experimental]` — `name = 'experimental'`, `value = true`. Duplicate names on the same target are a build-time error (no silent merge or last-wins). Type-level metadata is **not** auto-propagated to fields; consumers apply the "subfields inherit" rule themselves if they want it. ## Description mirroring A metadata subclass can mirror its marking into the human-readable description, so it's visible in tools (like stock GraphiQL) that don't know about the discovery channel. Override `transform_description()`: - `#[Internal]` prefixes the description with `[Internal] ` and supplies a default body when none exists. - `#[Experimental]` does the same with `[Experimental] `. When several transforming attributes apply to one element, their transforms chain in PHP source order (last-in-source wraps outermost), and the text flows through the standard `__( ..., 'woocommerce' )` translation pipeline. The plain `#[Metadata]` base does not modify descriptions. To define your own description-mirroring category, subclass `Metadata` and override `transform_description()`; see the [Attributes reference](./reference/attributes.md). ## Discovery via GraphQL: `_apiMetadata` Every generated schema gains a root field: ```graphql _apiMetadata(name: String, type: String, field: String, attribute: String): [MetadataTarget!]! ``` Each `MetadataTarget` carries two parallel slices: the collected metadata `entries`, and an `authorization` slice describing the authorization gates on that target. Arguments narrow independently (combined with AND): `name` trims surviving rows to the matching metadata entry, and `attribute` trims the authorization slice to a specific attribute short name. ### Access is gated `_apiMetadata` is gated like introspection, see [Authentication and authorization](./authentication-and-authorization.md). The resolver consults `can_query_metadata()` on the principal if present, otherwise falls back to `can_introspect()`, otherwise denies; the `woocommerce_graphql_can_query_metadata` filter can override. This prevents anonymous callers from enumerating the schema's authorization gates. ### Opting a target out Apply `#[HiddenFromMetadataQuery]` to a class or property to omit it (and its descriptors) from `_apiMetadata`. This is recognized by a duck-typed `shows_in_metadata_query(): bool` returning `false`; a target's visibility is the AND of that method across all its attributes. It does **not** affect native introspection or the runtime authorization gates: an attribute hidden from discovery still runs its `authorize()`. ## Discovery via PHP: `SchemaHandle` For in-process inspection, `GraphQLControllerBase::get_schema()` returns an opaque `SchemaHandle` (`Automattic\WooCommerce\Api\Utils\SchemaHandle`) with: - `get_all_metadata(): array`: every metadata row in the schema. - `find_metadata( ?string $name, ?string $type, ?string $field ): array`: the same filter-narrows semantics as the GraphQL field. The handle never exposes the underlying engine type in its public signature, so PHP callers don't depend on the GraphQL engine. It's the natural home for future schema-inspection operations. --- ## Relay-style pagination *Source: apis/dual-api/pagination.md* # Relay-style pagination List queries in the dual API paginate with **cursor-based connections** following the [Relay Cursor Connections specification](https://relay.dev/graphql/connections.htm). You write a command that returns a `Connection`; the builder generates the matching GraphQL `Connection`, `Edge`, and shared `PageInfo` types. The building blocks live in `Automattic\WooCommerce\Api\Pagination` and are reused by core and plugins alike. ## The connection shape For a node type `Coupon`, a `#[ConnectionOf( Coupon::class )]` query produces this GraphQL shape: ```graphql type CouponConnection { edges: [CouponEdge!]! # each item paired with its cursor nodes: [Coupon!]! # the items alone, a convenience shortcut page_info: PageInfo! total_count: Int! # total matches before the page window } type CouponEdge { cursor: String! node: Coupon! } type PageInfo { has_next_page: Boolean! has_previous_page: Boolean! start_cursor: String end_cursor: String } ``` `edges` and `nodes` carry the same items; `edges` adds the per-item `cursor`, while `nodes` is there for clients that just want the data. `PageInfo` is a single shared type across every connection. ## Writing a paginated query Place the query under `Queries/`, return a `Connection`, and annotate `execute()` with `#[ConnectionOf( ::class )]`. Take an argument of type `PaginationParams` - this type carries `#[Unroll]`, so its properties expand into individual GraphQL arguments rather than a nested input object: ```php #[Name( 'coupons' )] #[Description( 'List coupons with cursor-based pagination.' )] #[RequiredCapability( 'read_private_shop_coupons' )] class ListCoupons { #[ConnectionOf( Coupon::class )] public function execute( PaginationParams $pagination, ?CouponStatus $status = null ): Connection { // 1. query your data store, fetching one extra row to detect a next page // 2. build an Edge per item (cursor + node) // 3. populate a PageInfo and total_count // 4. return the Connection } } ``` The resulting field accepts the four standard arguments plus any others you declare (like `status` above): ```graphql coupons(first: Int, last: Int, after: String, before: String, status: CouponStatus) { ... } ``` ## The pagination arguments `PaginationParams` defines the forward/backward window: | Argument | Meaning | | --- | --- | | `first` | Return the first N items (forward pagination). | | `after` | Return items after this cursor. | | `last` | Return the last N items (backward pagination). | | `before` | Return items before this cursor. | Bounds are enforced: `first`/`last` must be between `0` and `PaginationParams::MAX_PAGE_SIZE`; a negative or over-cap value throws `INVALID_ARGUMENT` (HTTP 400). When neither `first` nor `last` is given, `PaginationParams::get_default_page_size()` applies. The same bounds are enforced on nested connection fields via `PaginationParams::validate_args()`, so a deeply nested `first: 1000` can't slip past the cap. These maximum and default page sizes are currently hardcoded to 100, but may become configurable in future versions of WooCommerce. ## Cursors Cursors are **opaque strings** to the client, never construct or parse them on the client side. Beyond that opacity, the engine mandates nothing about their format: any stable, encodable key works. The current core proof-of-concept happens to encode the node's numeric id as base64 (`base64_encode( (string) $id )`) and decode it with `IdCursorFilter::decode_id_cursor()`, which validates the input and throws `INVALID_ARGUMENT` (400) on a malformed cursor rather than silently returning unfiltered results. That scheme is a choice of the PoC code, not a requirement; your own connections are free to use a different encoding - just keep cursors opaque and validate them on decode. `IdCursorFilter` (in the `Api\Pagination` namespace) is a helper the PoC uses to window WordPress post queries on the `ID` column, via a lazy `posts_where` filter and two query vars: - `IdCursorFilter::AFTER_ID` (`wc_api_after_id`) → `AND ID > X` - `IdCursorFilter::BEFORE_ID` (`wc_api_before_id`) → `AND ID < X` Set whichever you need on your `WP_Query` args and call `IdCursorFilter::ensure_registered()` once before running the query. None of this is mandated by the engine: a plugin paginating its own post-backed data may find it useful to reuse `IdCursorFilter` (or follow the same `ID`-cursor pattern), but it's specific to `WP_Query` sources, and a connection over any other data store won't touch it. ## PageInfo semantics - `start_cursor` / `end_cursor` are the cursors of the first and last edges in the returned page (or `null` for an empty page). - `has_next_page` / `has_previous_page` follow the Relay rules. In **forward** pagination (`first`), `has_next_page` is true when more items exist after the window - the common "fetch N+1 and check" trick. In **backward** pagination (`last`), the roles mirror. The framework computes these for you when it slices; if you pre-slice, you set them yourself. ## Building the Connection: two paths `Connection` supports both a performant pre-paginated path and a slice-it-for-me path, and it guards against being sliced twice (so it's safe whether or not the generated resolver also calls `slice()`): - **`Connection::pre_sliced( array $edges, PageInfo $page_info, int $total_count )`**: use when your data store already applied the limits (the recommended path for real databases: push `first`/`after` into the SQL query). The returned connection is marked sliced, so the framework leaves it untouched. - **`$connection->slice( array $args )`**: build a `Connection` over a larger (or full) result set and let it apply the Relay algorithm: narrow by `after`, then `before`, then take `first` or `last`. It recomputes `PageInfo` and returns a new, sliced connection. Convenient for in-memory or small result sets. ## Nested connections A `Connection`-typed **property** on an output type, annotated with `#[ConnectionOf]`, becomes a paginated field on that type; for example `Product.reviews`: ```php #[Description( 'Customer reviews for this product.' )] #[ConnectionOf( ProductReview::class )] public Connection $reviews; ``` The generated resolver slices the property per the field's own pagination arguments, enforcing the same `MAX_PAGE_SIZE` cap as top-level queries. ## Complexity Connection fields contribute to a query's computed complexity: a connection's cost multiplies its children's cost by the requested page size. This is what the **Maximum query complexity** limit guards against, see [Settings and caching](./caching-and-settings.md). ## Reusing the building blocks `Connection`, `Edge`, `PageInfo`, and `PaginationParams` are part of the public `Api\Pagination` surface, so a plugin can return them directly without redefining its own. The [`woocommerce-simple-events`](https://github.com/woocommerce/woocommerce-simple-events) plugin's `eventsConnection` query is a minimal, in-memory working example (it builds edges over the full set and calls `slice()`); core's `ListCoupons` shows the `WP_Query` + `IdCursorFilter` database path. --- ## Reference: attributes *Source: apis/dual-api/reference/attributes.md* # Reference: attributes PHP 8 attributes supply the metadata the builder can't infer from code structure. All built-in attributes live in `Automattic\WooCommerce\Api\Attributes`. Plugins define their own under their `Api\Attributes\` namespace, following the [conventions](#conventions-for-custom-attributes) below; those conventions also apply when adding attributes to core. ## Naming and description | Attribute | Constructor | Targets | Purpose | | --- | --- | --- | --- | | `Name` | `( string $name )` | all | Override the derived GraphQL name of a type, field, query/mutation, or enum value. | | `Description` | `( string $description )` | all | Human-readable description, surfaced in the schema. | | `ParameterDescription` | `( string $name, string $description )` | all, repeatable | Describe a single argument by name (e.g. a computed field's `#[Parameter]`). | ## Type shaping | Attribute | Constructor | Targets | Purpose | | --- | --- | --- | --- | | `ArrayOf` | `( string $type )` | all | Element type of an `array` property/return: a scalar name (`'int'`, `'string'`, `'float'`, `'bool'`) or a class name. | | `ScalarType` | `( string $type )` | all | Render a property through a custom scalar class (e.g. `DateTime::class`). | | `ConnectionOf` | `( string $type )` | all | Mark a `Connection` return or property as a connection of the given node type; generates `Connection`/`Edge`. | | `ReturnType` | `( string $type )` | method | Declare the GraphQL return type when `execute()` returns an interface (PHP can't type-hint a trait). | | `Parameter` | see below | all, repeatable | Declare an explicit argument. Used to give an output field computed arguments, or to shape/`unroll` a query argument. | | `Unroll` | `()` | class, parameter | Expand a class's public properties into individual flat arguments instead of one input object. | `Parameter` full signature: ```php public function __construct( public readonly string $name = '', public readonly string $type = '', public readonly bool $nullable = false, public readonly bool $array = false, public readonly mixed $default = null, public readonly string $description = '', bool $has_default = false, public readonly bool $unroll = false, ) ``` ## Lifecycle | Attribute | Constructor | Targets | Purpose | | --- | --- | --- | --- | | `Deprecated` | `( string $reason )` | all | Mark a field or enum value deprecated (shown in introspection). | | `Ignore` | `()` | all | Exclude the class or property from the schema entirely. | ## Authorization | Attribute | Constructor | Targets | Purpose | | --- | --- | --- | --- | | `PublicAccess` | `()` | class, property | No authentication required. `authorize()` returns `true`. A no-op (and build warning) on a property. | | `RequiredCapability` | `( string $capability )` | class, property, repeatable | Require a WordPress capability; `authorize( Principal $principal )` checks `user_can()`. Multiple are ANDed. | Both can gate queries/mutations (class), output/input types (class), and output/input fields (property). A class-level gate AND-composes into every field gate of the type. See [Authentication and authorization](../authentication-and-authorization.md). ## Metadata | Attribute | Constructor | Targets | Purpose | | --- | --- | --- | --- | | `Metadata` | `( string $name, bool\|int\|float\|string\|null $value )` | class, property, parameter, enum case, repeatable | Attach one name/value entry. Base class for custom categories. | | `Internal` | `()` | class, property, enum case | `Metadata( 'internal', true )` + `[Internal] ` description prefix. | | `Experimental` | `()` | class, property, enum case | `Metadata( 'experimental', true )` + `[Experimental] ` description prefix. | | `HiddenFromMetadataQuery` | `()` | class, property, parameter, enum case | Omit the target from `_apiMetadata` discovery (`shows_in_metadata_query()` returns `false`). Does not affect native introspection or runtime gates. | `Metadata` methods: `get_name()`, `get_value()`, and the overridable `transform_description( string $description ): string` (no-op in the base). Duplicate names on one target are a build error. See [Metadata and discovery](../metadata.md). ## Conventions for custom attributes The builder recognizes custom attributes by **duck-typed conventions**, not by a base class or interface (except metadata). Declare the PHP `#[Attribute(...)]` targets you want to support. - **Authorization attribute**: declares a public `authorize(): bool` method. Its first non-underscore parameter receives the principal; the parameter type should be the registered principal type. It may also declare the opt-in context parameters `array $_metadata`, `array $_args`, `mixed $_parent` (see [Recognized methods and parameters](./recognized-methods-and-parameters.md)). To gate fields/arguments as well as operations, include `Attribute::TARGET_PROPERTY` in the `#[Attribute(...)]` declaration. - **Metadata attribute**: extends `Metadata` and calls `parent::__construct( $name, $value )`. Discoverable through `_apiMetadata`. - **Description-mirroring attribute**: a `Metadata` subclass that overrides `transform_description()`. Transforms chain in source order. - **Metadata-query opt-out**: declares `shows_in_metadata_query(): bool` returning `false` (what `#[HiddenFromMetadataQuery]` does). If you reference an attribute without importing it, PHP resolves it to a non-existent class in the current namespace and silently ignores it; the builder emits a warning naming the FQCN it tried to load, so add the missing `use`. --- ## Reference: recognized directories *Source: apis/dual-api/reference/directories.md* # Reference: recognized directories The builder determines a class' role from the directory it lives in, relative to the code-API root (`src/Api/` for core, `/src/Api/` for a plugin). Arbitrary nested subdirectories are allowed for organization and do **not** change the role; e.g. `Queries/Coupons/GetCoupon.php` and `Queries/GetCoupon.php` are both queries. | Directory | Role | What it holds | | --- | --- | --- | | `Queries/` | GraphQL query | Command classes with an `execute()` method. Name defaults to camelCase of the class name. | | `Mutations/` | GraphQL mutation | Command classes with an `execute()` method. Rejected over GET. | | `Types/` | Output type | Plain classes whose public properties become fields. | | `InputTypes/` | Input type | Plain classes used as `execute()` arguments; a field is optional when its type is nullable or it has a default. | | `Enums/` | Enum type | Backed PHP enums. Case names become `SCREAMING_SNAKE_CASE`. | | `Interfaces/` | Interface | PHP **traits** marked `#[Name]`/`#[Description]`; types `use` them to implement. | | `Scalars/` | Custom scalar | Classes with static `serialize()` / `parse()`. Applied to fields via `#[ScalarType]`. | | `Pagination/` | Pagination support | `Connection`, `Edge`, `PageInfo`, `PaginationParams`, cursor helpers (provided by core; reused, not redefined). | | `Attributes/` | Attribute definitions | Custom PHP 8 attributes (authorization, metadata, …). See [Attributes](./attributes.md). | | `Infrastructure/` | Convention classes | Optional per-plugin `ClassResolver`, `PrincipalResolver`, principal class, `HttpStatusResolver`. See [Infrastructure classes](./infrastructure-classes.md). | | `Utils/` | Helpers | Mappers, repositories, and other plain helpers. Not exposed in the schema. | Notes: - Classes the builder shouldn't expose can be excluded with `#[Ignore]` regardless of placement (e.g. a helper that happens to live under a scanned directory). - The generated output mirrors these roles under `Internal/Api/Autogenerated/` (`GraphQLQueries/`, `GraphQLMutations/`, `GraphQLTypes/{Output,Input,Enums,Interfaces,Scalars,Pagination}/`), but you never edit that tree; see [Building and staleness checks](../building-and-staleness.md). - These conventions are identical for core and for plugins. --- ## Reference: exceptions *Source: apis/dual-api/reference/exceptions.md* # Reference: exceptions Throwing an exception from `execute()` or `authorize()` is how the code API surfaces errors. The framework translates each into a GraphQL error with a machine-readable `extensions.code` and a matching HTTP status. All built-in exceptions live in `Automattic\WooCommerce\Api`. ## The base: `ApiException` ```php public function __construct( string $message, private readonly string $error_code = 'INTERNAL_ERROR', private readonly array $extensions = array(), int $status_code = 500, ?\Throwable $previous = null, ) ``` It extends `\RuntimeException` and exposes `getErrorCode()`, `getExtensions()`, and `getStatusCode()`. The controller merges your `extensions` with `{ code: }` (the code can't be overridden by an extensions entry), and uses `status_code` as the HTTP status. ## Built-in subclasses Each fixes a `(code, status)` pair; all share the signature `( string $message = , array $extensions = [], ?\Throwable $previous = null )`. | Class | `extensions.code` | HTTP | Use when | | --- | --- | --- | --- | | `UnauthorizedException` | `UNAUTHORIZED` | 401 | Authentication is required but missing; or a generic auth denial where re-authenticating might help. | | `InvalidTokenException` | `INVALID_TOKEN` | 401 | Credentials were supplied but rejected (bad/expired token, malformed header). | | `ForbiddenException` | `FORBIDDEN` | 403 | Authenticated, but lacks permission ("I know who you are, but you can't do this") | | `NotFoundException` | `NOT_FOUND` | 404 | The resource doesn't exist. (When existence is sensitive, prefer `UnauthorizedException` to avoid leaking it.) | | `ValidationException` | `VALIDATION_ERROR` | 422 | Input is well-formed but fails a business rule. | ## Other translated throwables | Thrown | Becomes | | --- | --- | | `\InvalidArgumentException` | `INVALID_ARGUMENT` / 400 - use for malformed/structural input (wrong type, contradictory args). | | any other `\Throwable` | `INTERNAL_ERROR` / 500 - message masked; the original is attached as `previous` and shown only in debug mode. | The framework also maps engine-level issues itself (e.g. an out-of-range `Int` output → `BAD_USER_INPUT` / 400; depth/complexity violations → 400). ## Authorization-failure status When an authorization gate denies (rather than throwing), the framework picks the status from the principal: **401 `UNAUTHORIZED`** for anonymous principals (`is_authenticated()` is `false`), **403 `FORBIDDEN`** for authenticated ones or principals that don't expose `is_authenticated()`. See [Authentication and authorization](../authentication-and-authorization.md). ## Creating a custom exception (in a plugin or core) Extend `ApiException` (or a subclass when its behavior fits) and pin your own code and status: ```php namespace Automattic\MyPlugin\Api; use Automattic\WooCommerce\Api\ApiException; class QuotaExceededException extends ApiException { public function __construct( string $message = 'Quota exceeded.', array $extensions = array(), ?\Throwable $previous = null ) { parent::__construct( $message, 'QUOTA_EXCEEDED', $extensions, 429, $previous ); } } ``` Throw it from a command; the `code` and `status_code` surface automatically, and any `extensions` you pass appear alongside `code` in the response. Use a sensible standard HTTP status for your domain. --- ## Reference: infrastructure classes *Source: apis/dual-api/reference/infrastructure-classes.md* # Reference: infrastructure classes These classes live in `Automattic\WooCommerce\Api\Infrastructure` (and `Api\Utils`). Some are **convention classes** that ApiBuilder detects per plugin; the rest are runtime helpers. Plugin override rules apply equally when adjusting core's own behavior. ## Convention classes ApiBuilder looks for these at `\Infrastructure\*` and wires whatever it finds into the generated controller. Ship one only to diverge from the default; otherwise the default applies. The signature must match exactly. ### `ClassResolver` ```php public static function resolve_class( string $class_name ): object ``` Instantiates command and infrastructure classes. **Default:** `wc_get_container()->get( $class_name )`. Ship your own to route through a different DI container. When no resolver is present at all, generated resolvers fall back to `new $class_name()`. ### `PrincipalResolver` ```php public function resolve_principal(): Principal // or public function resolve_principal( \WP_REST_Request $request ): Principal ``` Resolves the per-request principal once. **Default:** returns `new Principal( wp_get_current_user() )` (no `$request` parameter). The **return type declares the plugin's principal type**, which the builder uses to type-check `authorize()`/`$_principal` against. Throw `UnauthorizedException`/`InvalidTokenException` to reject credentials. Anonymous requests are a resolved principal (not `null`). ### `Principal` The default principal wraps a `WP_User`: ```php public function __construct( public readonly \WP_User $user ) public function is_authenticated(): bool // user->ID > 0 public function can_introspect(): bool // user_can( $user, 'manage_woocommerce' ) public function can_use_debug_mode(): bool // user_can( $user, 'manage_options' ) ``` A custom principal can be any class. Recognized (all optional, duck-typed) methods: | Method | If declared | If absent | | --- | --- | --- | | `is_authenticated(): bool` | distinguishes 401 vs 403 on denial; used by your own code | denials default to 403 (`FORBIDDEN`) | | `can_introspect(): bool` | gates native introspection (and `_apiMetadata`, as fallback) | introspection denied | | `can_use_debug_mode(): bool` | gates debug mode (with `_debug=1`) | debug mode denied | | `can_query_metadata(): bool` | gates `_apiMetadata` specifically | falls back to `can_introspect()`, else deny | Core's `Principal` deliberately omits `can_query_metadata()`, so `_apiMetadata` follows `can_introspect()`. ### `HttpStatusResolver` ```php public function resolve_status( int $default_status, array $output, \WP_REST_Request $request ): int ``` Optional. Override the framework-computed HTTP status for any response (e.g. always 200), or return `$default_status` to defer. Called for both success and error responses. **Must not throw**: any throw is converted to a fixed 500 `INTERNAL_ERROR`. **Default:** core ships none, so its per-error-code mapping applies. See [Settings and caching](../caching-and-settings.md). ## Runtime helpers You generally don't call these directly (generated code does), but they're public for advanced use. ### `GraphQLControllerBase` Abstract base for the generated controller; owns the request lifecycle. Notable public members: - `get_schema(): SchemaHandle`: schema handle for metadata inspection. - `build_schema(): Schema\Schema`: returns the engine-decoupled wrapper, never the engine type. - Static config accessors `get_endpoint_url()`, `get_max_query_depth()`, `get_max_query_complexity()`. ### `ResolverHelpers` Static helpers used by generated resolvers: exception translation, pagination construction, authorization checks, and the public `compute_preauthorized( string $command_fqcn, object $principal ): bool`. ### `Main` Bootstrap and registration: - `is_enabled(): bool`: checks PHP 8.1+ and the `dual_code_graphql_api` flag. - `register_graphql_endpoint( string $plugin_dir_or_controller_class, string $route_namespace, string $route, array $methods = ['GET','POST'] ): void`: register a plugin endpoint. No-op when the feature is off. - `instantiate_graphql_controller( string $controller_class_name ): ?GraphQLControllerBase`. ### `MetadataController`, `QueryInfoExtractor` Hand-written runtime pieces: the `_apiMetadata` field/types, and the `ResolveInfo` → `_query_info` extraction. See [Extending the infrastructure](../extending-the-infrastructure.md). ## `SchemaHandle` (`Api\Utils`) Opaque, engine-independent handle returned by `get_schema()`: ```php public function get_all_metadata(): array public function find_metadata( ?string $name = null, ?string $type = null, ?string $field = null ): array ``` ## Utility classes Plain helpers (mappers, repositories) live under `Api/Utils/` and are not exposed in the schema, e.g. `Utils\Products\ProductRepository` (`find( int $id ): ?\WC_Product`, `save( \WC_Product $product ): void`). Inject them into commands via the `ClassResolver`/DI container. Plugins place their own helpers under their `Api/Utils/`. --- ## Reference: recognized methods and parameters *Source: apis/dual-api/reference/recognized-methods-and-parameters.md* # Reference: recognized methods and parameters The builder recognizes certain method names on command and attribute classes, and certain specially named parameters that it injects at runtime. These conventions are identical for core and plugins. ## Methods on command classes (queries/mutations) | Method | Signature | Notes | | --- | --- | --- | | `execute` | `execute( ...args ): ` | Required. Parameters become GraphQL arguments; the return type becomes the GraphQL return type (use `#[ReturnType]` for interface returns). | | `authorize` | `authorize( ...args ): bool` | Optional. Custom authorization for the operation; return `false` to deny. Compose with attributes via `$_preauthorized`. | ## Methods on attribute classes | Method | Signature | Makes the attribute… | | --- | --- | --- | | `authorize` | `authorize( $principal, ... ): bool` | an authorization attribute. | | `get_name` / `get_value` | `get_name(): string` / `get_value(): bool\|int\|float\|string\|null` | (on `Metadata` subclasses) expose the metadata entry. | | `transform_description` | `transform_description( string $description ): string` | a description-mirroring metadata attribute. | | `shows_in_metadata_query` | `shows_in_metadata_query(): bool` | able to opt its target out of `_apiMetadata` (when it returns `false`). | ## Methods on custom scalar classes | Method | Signature | Purpose | | --- | --- | --- | | `serialize` | `static serialize( mixed $value ): string` | PHP value → transport string. | | `parse` | `static parse( string $value ): mixed` | Client string → PHP value; throw `\InvalidArgumentException` on bad input. | ## Recognized parameters These are optional, underscore-prefixed parameters detected **by name**. They may appear in any order; declare only the ones you use. The underscore prefix also keeps them out of the GraphQL argument list. (`provided_fields` on input types uses the same underscore-invisibility idea for an internal property.) | Parameter | Type | Available on | Value | | --- | --- | --- | --- | | `$_principal` | the registered principal type | `execute()`, `authorize()` | The resolved principal for the request. | | `$_preauthorized` | `bool` | `authorize()` (command) | Whether the attribute-based gates already grant access — compose your custom check on top. | | `$_query_info` | `?array` | `execute()` | The selection tree of the current query, for resolve-time optimization. Provided via `QueryInfoExtractor`. | | `$_metadata` | `array` | `authorize()` (attribute) | `#[Metadata]` entries at the call site, in slices `['query']`, `['type']`, `['field']` (each `array`). At the operation level only `['query']` is populated. | | `$_args` | `array` | `authorize()` (attribute) | The GraphQL arguments at the call site. | | `$_parent` | `mixed` | `authorize()` (attribute) | The enclosing object being resolved, for output-field gates (enables owner-or-scope checks). | For how these combine in granular authorization, see [Authentication and authorization](../authentication-and-authorization.md). ## Public PHP-side helpers | Call | Purpose | | --- | --- | | `ResolverHelpers::compute_preauthorized( string $command_fqcn, object $principal ): bool` | Ask whether attribute gates would grant access, without executing the command. | | `GraphQLControllerBase::get_schema(): SchemaHandle` | Obtain the schema handle for PHP-side metadata inspection. | | `SchemaHandle::get_all_metadata()` / `find_metadata( ?name, ?type, ?field )` | Read collected metadata. See [Metadata and discovery](../metadata.md). | --- ## Authentication *Source: apis/rest-api/authentication.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Authentication WooCommerce includes two ways to authenticate with the WP REST API. It is also possible to authenticate using any [WP REST API authentication](http://v3.wp-api.org/guide/authentication/) plugin or method. ## REST API keys Pre-generated keys can be used to authenticate use of the REST API endpoints. New keys can be generated either through the WordPress admin interface or they can be auto-generated through an endpoint. ### Generating API keys in the WordPress admin interface To create or manage keys for a specific WordPress user, go to WooCommerce > Settings > Advanced > REST API. *Note: Keys/Apps was found at WooCommerce > Settings > API > Key/Apps prior to WooCommerce 3.4.* ![WooCommerce REST API keys settings](v3/images/woocommerce-api-keys-settings.png) Click the "Add Key" button. In the next screen, add a description and select the WordPress user you would like to generate the key for. Use of the REST API with the generated keys will conform to that user's WordPress roles and capabilities. Choose the level of access for this REST API key, which can be _Read_ access, _Write_ access or _Read/Write_ access. Then click the "Generate API Key" button and WooCommerce will generate REST API keys for the selected user. ![Creating a new REST API key](v3/images/woocommerce-creating-api-keys.png) Now that keys have been generated, you should see two new keys, a QRCode, and a Revoke API Key button. These two keys are your Consumer Key and Consumer Secret. ![Generated REST API key](v3/images/woocommerce-api-key-generated.png) If the WordPress user associated with an API key is deleted, the API key will cease to function. API keys are not transferred to other users. ### Auto generating API keys using our Application Authentication Endpoint This endpoint can be used by any APP to *allow users to generate API keys* for your APP. This makes integration with WooCommerce API easier because the user only needs to grant access to your APP via a URL. After being redirected back to your APP, the API keys will be sent back in a separate POST request. The following image illustrates how this works: ![Authentication Endpoint flow](v3/images/woocommerce-auth-endpoint-flow.png) :::warning This endpoint works exclusively for users to generate API keys and facilitate integration between the WooCommerce REST API and an application. In no way is this endpoint intended to be used as login method for customers. ::: #### URL parameters | Parameter | Type | Description | |----------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `app_name` | string | Your APP name `MANDATORY` | | `scope` | string | Level of access. Available: `read`, `write` and `read_write` `MANDATORY` | | `user_id` | string | User ID in your APP. For your internal reference, used when the user is redirected back to your APP. NOT THE USER ID IN WOOCOMMERCE `MANDATORY` | | `return_url` | string | URL the user will be redirected to after authentication `MANDATORY` | | `callback_url` | string | URL that will receive the generated API key. Note: this URL should be over **HTTPS** `MANDATORY` | #### Creating an authentication endpoint URL You must use the `/wc-auth/v1/authorize` endpoint and pass the above parameters as a query string. > Example of how to build an authentication URL: ```shell # Bash example STORE_URL='http://example.com' ENDPOINT='/wc-auth/v1/authorize' PARAMS="app_name=My App Name&scope=read_write&user_id=123&return_url=http://app.com/return-page&callback_url=https://app.com/callback-endpoint" QUERY_STRING="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$PARAMS")" QUERY_STRING=$(echo $QUERY_STRING | sed -e "s/%20/\+/g" -e "s/%3D/\=/g" -e "s/%26/\&/g") echo "$STORE_URL$ENDPOINT?$QUERY_STRING" ``` ```javascript const querystring = require('querystring'); const store_url = 'http://example.com'; const endpoint = '/wc-auth/v1/authorize'; const params = { app_name: 'My App Name', scope: 'read_write', user_id: 123, return_url: 'http://app.com/return-page', callback_url: 'https://app.com/callback-endpoint' }; const query_string = querystring.stringify(params).replace(/%20/g, '+'); console.log(store_url + endpoint + '?' + query_string); ``` ```php 'My App Name', 'scope' => 'write', 'user_id' => 123, 'return_url' => 'http://app.com', 'callback_url' => 'https://app.com' ]; $query_string = http_build_query( $params ); echo $store_url . $endpoint . '?' . $query_string; ?> ``` ```python from urllib.parse import urlencode store_url = 'http://example.com' endpoint = '/wc-auth/v1/authorize' params = { "app_name": "My App Name", "scope": "read_write", "user_id": 123, "return_url": "http://app.com/return-page", "callback_url": "https://app.com/callback-endpoint" } query_string = urlencode(params) print("%s%s?%s" % (store_url, endpoint, query_string)) ``` ```ruby require "uri" store_url = 'http://example.com' endpoint = '/wc-auth/v1/authorize' params = { app_name: "My App Name", scope: "read_write", user_id: 123, return_url: "http://app.com/return-page", callback_url: "https://app.com/callback-endpoint" } query_string = URI.encode_www_form(params) puts "#{store_url}#{endpoint}?#{query_string}" ``` > Example of JSON posted with the API Keys ``` { "key_id": 1, "user_id": 123, "consumer_key": "ck_xxxxxxxxxxxxxxxx", "consumer_secret": "cs_xxxxxxxxxxxxxxxx", "key_permissions": "read_write" } ``` Example of the screen that the user will see: ![Authentication Endpoint example](v3/images/woocommerce-auth-endpoint-example.png) #### Notes - While redirecting the user using `return_url`, you are also sent `success` and `user_id` parameters as query strings. - `success` sends `0` if the user denied, or `1` if authenticated successfully. - Use `user_id` to identify the user when redirected back to the (`return_url`) and also remember to save the API Keys when your `callback_url` is posted to after auth. - The auth endpoint will send the API Keys in JSON format to the `callback_url`, so it's important to remember that some languages such as PHP will not display it inside the `$_POST` global variable, in PHP you can access it using `$HTTP_RAW_POST_DATA` (for old PHP versions) or `file_get_contents('php://input');`. - The URL generated must have all query string values encoded. ## Authentication over HTTPS You may use [HTTP Basic Auth](http://en.wikipedia.org/wiki/Basic_access_authentication) by providing the REST API Consumer Key as the username and the REST API Consumer Secret as the password. > HTTP Basic Auth example ```shell curl https://www.example.com/wp-json/wc/v3/orders \ -u consumer_key:consumer_secret ``` ```javascript const WooCommerceRestApi = require("@woocommerce/woocommerce-rest-api").default; // import WooCommerceRestApi from "@woocommerce/woocommerce-rest-api"; // Supports ESM const WooCommerce = new WooCommerceRestApi({ url: 'https://example.com', consumerKey: 'consumer_key', consumerSecret: 'consumer_secret', version: 'wc/v3' }); ``` ```php true, 'version' => 'wc/v3' ] ); ?> ``` ```python from woocommerce import API wcapi = API( url="https://example.com", consumer_key="consumer_key", consumer_secret="consumer_secret", wp_api=True, version="wc/v3" ) ``` ```ruby require "woocommerce_api" woocommerce = WooCommerce::API.new( "https://example.com", "consumer_key", "consumer_secret", { wp_json: true, version: "wc/v3" } ) ``` Occasionally some servers may not parse the Authorization header correctly (if you see a "Consumer key is missing" error when authenticating over SSL, you have a server issue). In this case, you may provide the consumer key/secret as query string parameters instead. > Example for servers that not properly parse the Authorization header: ```shell curl https://www.example.com/wp-json/wc/v3/orders?consumer_key=123&consumer_secret=abc ``` ```javascript const WooCommerceRestApi = require("@woocommerce/woocommerce-rest-api").default; // import WooCommerceRestApi from "@woocommerce/woocommerce-rest-api"; // Supports ESM const WooCommerce = new WooCommerceRestApi({ url: 'https://example.com', consumerKey: 'consumer_key', consumerSecret: 'consumer_secret', version: 'wc/v3', queryStringAuth: true // Force Basic Authentication as query string true and using under HTTPS }); ``` ```php true, 'version' => 'wc/v3', 'query_string_auth' => true // Force Basic Authentication as query string true and using under HTTPS ] ); ?> ``` ```python from woocommerce import API wcapi = API( url="https://example.com", consumer_key="consumer_key", consumer_secret="consumer_secret", wp_api=True, version="wc/v3", query_string_auth=True # Force Basic Authentication as query string true and using under HTTPS ) ``` ```ruby require "woocommerce_api" woocommerce = WooCommerce::API.new( "https://example.com", "consumer_key", "consumer_secret", { wp_json: true, version: "wc/v3", query_string_auth: true # Force Basic Authentication as query string true and using under HTTPS } ) ``` ## Authentication over HTTP You must use [OAuth 1.0a "one-legged" authentication](http://tools.ietf.org/html/rfc5849) to ensure REST API credentials cannot be intercepted by an attacker. Typically you will use any standard OAuth 1.0a library in the language of your choice to handle the authentication, or generate the necessary parameters by following the following instructions. ### Creating a signature #### Collect the request method and URL First you need to determine the HTTP method you will be using for the request, and the URL of the request. The **HTTP method** will be `GET` in our case. The **Request URL** will be the endpoint you are posting to, e.g. `http://www.example.com/wp-json/wc/v3/orders`. #### Collect parameters Collect and normalize your parameters. This includes all `oauth_*` parameters except for the `oauth_signature` itself. These values need to be encoded into a single string which will be used later on. The process to build the string is very specific: 1. [Percent encode](https://dev.twitter.com/oauth/overview/percent-encoding-parameters) every key and value that will be signed. 2. Sort the list of parameters alphabetically by encoded key. 3. For each key/value pair: - Append the encoded key to the output string. - Append the `=` character to the output string. - Append the encoded value to the output string. - If there are more key/value pairs remaining, append a `&` character to the output string. When percent encoding in PHP for example, you would use `rawurlencode()`. When sorting parameters in PHP for example, you would use `uksort( $params, 'strcmp' )`. > Parameters example: ``` oauth_consumer_key=abc123&oauth_signature_method=HMAC-SHA1 ``` #### Create the signature base string The above values collected so far must be joined to make a single string, from which the signature will be generated. This is called the signature base string in the OAuth specification. To encode the HTTP method, request URL, and parameter string into a single string: 1. Set the output string equal to the uppercase **HTTP Method**. 2. Append the `&` character to the output string. 3. [Percent encode](https://dev.twitter.com/oauth/overview/percent-encoding-parameters) the URL and append it to the output string. 4. Append the `&` character to the output string. 5. [Percent encode](https://dev.twitter.com/oauth/overview/percent-encoding-parameters) the parameter string and append it to the output string. > Example signature base string: ``` GET&http%3A%2F%2Fwww.example.com%2Fwp-json%2Fwc%2Fv3%2Forders&oauth_consumer_key%3Dabc123%26oauth_signature_method%3DHMAC-SHA1 ``` #### Generate the signature Generate the signature using the *signature base string* and your consumer secret key with a `&` character with the HMAC-SHA1 hashing algorithm. In PHP you can use the [hash_hmac](http://php.net/manual/en/function.hash-hmac.php) function. HMAC-SHA1 or HMAC-SHA256 are the only accepted hash algorithms. If you are having trouble generating a correct signature, you'll want to review the string you are signing for encoding errors. The [authentication source](https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-rest-authentication.php#L185) can also be helpful in understanding how to properly generate the signature. ### OAuth tips * The OAuth parameters may be added as query string parameters or included in the Authorization header. * Note there is no reliable cross-platform way to get the raw request headers in WordPress, so query string should be more reliable in some cases. * The required parameters are: `oauth_consumer_key`, `oauth_timestamp`, `oauth_nonce`, `oauth_signature`, and `oauth_signature_method`. `oauth_version` is not required and should be omitted. * The OAuth nonce can be any randomly generated 32 character (recommended) string that is unique to the consumer key. * The OAuth timestamp should be the unix timestamp at the time of the request. The REST API will deny any requests that include a timestamp outside of a 15 minute window to prevent replay attacks. * You must use the store URL provided by the index when forming the base string used for the signature, as this is what the server will use. (e.g. if the store URL includes a `www` sub-domain, you should use it for requests) * Note that the request body is *not* signed as per the OAuth spec. * If including parameters in your request, it saves a lot of trouble if you can order your items alphabetically. * Authorization header is supported starting WooCommerce 3.0. --- ## WooCommerce REST API *Source: apis/rest-api/index.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # WooCommerce REST API WooCommerce (WC) 2.6+ is fully integrated with the WordPress [REST](http://en.wikipedia.org/wiki/Representational_State_Transfer) API. This allows WC data to be created, read, updated, and deleted using requests in JSON format and using WordPress REST API Authentication methods and standard HTTP verbs which are understood by most HTTP clients. The current WP REST API integration version is `v3` which takes a first-order position in endpoints. ## Requirements To use the REST API you must be using: - WooCommerce 3.5+ - WordPress 4.4+ - Pretty permalinks in **Settings > Permalinks** (default permalinks will not work) You may access the API over either HTTP or HTTPS, but *HTTPS is recommended where possible*. :::note You are **not** required to install the [WP REST API (WP API)](https://wordpress.org/plugins/rest-api/) plugin. ::: If you use ModSecurity and see `501 Method Not Implemented` errors, see [this issue](https://github.com/woocommerce/woocommerce/issues/9838) for details. ## Libraries and tools ### Official libraries - [JavaScript](https://www.npmjs.com/package/@woocommerce/woocommerce-rest-api) Library - [PHP](https://packagist.org/packages/automattic/woocommerce) Library - [Python](https://pypi.python.org/pypi/WooCommerce) Library - [Ruby](https://rubygems.org/gems/woocommerce_api) Library ```javascript // Install: // npm install --save @woocommerce/woocommerce-rest-api // Setup: const WooCommerceRestApi = require("@woocommerce/woocommerce-rest-api").default; // import WooCommerceRestApi from "@woocommerce/woocommerce-rest-api"; // Supports ESM const WooCommerce = new WooCommerceRestApi({ url: 'http://example.com', // Your store URL consumerKey: 'consumer_key', // Your consumer key consumerSecret: 'consumer_secret', // Your consumer secret version: 'wc/v3' // WooCommerce WP REST API version }); ``` ```php true, // Enable the WP REST API integration 'version' => 'wc/v3' // WooCommerce WP REST API version ] ); ?> ``` ```python # Install: # pip install woocommerce # Setup: from woocommerce import API wcapi = API( url="http://example.com", # Your store URL consumer_key="consumer_key", # Your consumer key consumer_secret="consumer_secret", # Your consumer secret wp_api=True, # Enable the WP REST API integration version="wc/v3" # WooCommerce WP REST API version ) ``` ```ruby # Install: # gem install woocommerce_api # Setup: require "woocommerce_api" woocommerce = WooCommerce::API.new( "https://example.com", # Your store URL "consumer_key", # Your consumer key "consumer_secret", # Your consumer secret { wp_api: true, # Enable the WP REST API integration version: "wc/v3" # WooCommerce WP REST API version } ) ``` ### Third party libraries - [Java](https://github.com/icoderman/wc-api-java) Library - [.NET](https://github.com/XiaoFaye/WooCommerce.NET) Library - [Android](https://github.com/gilokimu/WooDroid) Library :::note We don't offer support for third party libraries. If you have questions about how to use any of these libraries, contact the respective authors. ::: ### Tools - [Insomnia](https://insomnia.rest) - Cross-platform GraphQL and REST client, available for Mac, Windows, and Linux. - [Postman](https://www.getpostman.com/) - Cross-platform REST client, available for Mac, Windows, and Linux. - [RequestBin](https://requestbin.com) - Allows you test webhooks. - [Hookbin](https://hookbin.com/) - Another tool to test webhooks. ## Generate keys To start using REST API, you first need to generate API keys. 1. Go to **WooCommerce > Settings > Advanced** 2. Go to the **REST API** tab and click **Add key** 3. Give the key a description for your own reference, choose a user with access to orders etc, and give the key **read/write** permissions 4. Click **Generate API key** 5. Your keys will be shown - do not close this tab yet, the secret will be hidden if you try to view the key again ![Generated API Keys](https://developer.woocommerce.com/wp-content/uploads/2023/12/keys.png) ## Make a basic request The request URL we'll test is `wp-json/wc/v3/orders`. On localhost the full URL may look something like this: `https://localhost:8888/wp-json/wc/v3/orders`. Modify this to use your own site URL. In Postman, you need to set the fields for request type, request URL, and the settings on the authorization tab. For Authorization, choose **basic auth** and enter your **consumer key** and **consumer secret** keys from WooCommerce into the username and password fields. Once done, hit send and you'll see the JSON response from the API if all worked well: ![Postman example](https://developer.woocommerce.com/wp-content/uploads/2023/12/postman.png) Insomnia is almost identical to Postman; fill in the same fields and again use basic auth: ![Insomnia example](https://developer.woocommerce.com/wp-content/uploads/2023/12/insomnia.png) ## Request/Response format The default response format is JSON. Requests with a message-body use plain JSON to set or update resource attributes. Successful requests will return a `200 OK` HTTP status. Some general information about responses: - Dates are returned in ISO8601 format: `YYYY-MM-DDTHH:MM:SS` - Resource IDs are returned as integers - Any decimal monetary amount, such as prices or totals, will be returned as strings with two decimal places - Other amounts, such as item counts, are returned as integers - Blank fields are generally included as `null` or empty string instead of being omitted ### JSONP support The WP REST API supports JSONP by default. JSONP responses use the `application/javascript` content-type. You can specify the callback using the `?_jsonp` parameter for `GET` requests to have the response wrapped in a JSON function: ```http GET /wp-json/wc/v3?_jsonp=callback ``` ## Parameters Almost all endpoints accept optional parameters which can be passed as a HTTP query string parameter, e.g. `GET /orders?status=completed`. All parameters are documented along each endpoint. ## Pagination Requests that return multiple items will be paginated to 10 items by default. This default can be changed by the site administrator by changing the `posts_per_page` option. Alternatively the items per page can be specified with the `?per_page` parameter: ```http GET /orders?per_page=15 ``` You can specify further pages with the `?page` parameter: ```http GET /orders?page=2 ``` You may also specify the offset from the first resource using the `?offset` parameter: ```http GET /orders?offset=5 ``` Page number is 1-based and omitting the `?page` parameter will return the first page. The total number of resources and pages are always included in the `X-WP-Total` and `X-WP-TotalPages` HTTP headers. ### Link header Pagination info is included in the [Link Header](http://tools.ietf.org/html/rfc5988). It's recommended that you follow these values instead of building your own URLs where possible. ``` Link: ; rel="next", ; rel="last" ``` | Value | Description | |---------|----------------------------------------------------------| | `next` | Shows the URL of the immediate next page of results. | | `last` | Shows the URL of the last page of results. | | `first` | Shows the URL of the first page of results. | | `prev` | Shows the URL of the immediate previous page of results. | ## Errors Occasionally you might encounter errors when accessing the REST API. There are four possible types: | Error Code | Error Type | |-----------------------------|-------------------------------------------------------------| | `400 Bad Request` | Invalid request, e.g. using an unsupported HTTP method | | `401 Unauthorized` | Authentication or permission error, e.g. incorrect API keys | | `404 Not Found` | Requests to resources that don't exist or are missing | | `500 Internal Server Error` | Server error | Errors return both an appropriate HTTP status code and response object which contains a `code`, `message` and `data` attribute: ```json { "code": "woocommerce_rest_term_invalid", "message": "Resource doesn't exist.", "data": { "status": 404 } } ``` ## Common connection issues ### Connection issues with localhost and self-signed SSL certificates If you're having problems connecting to the REST API on your localhost and seeing SSL errors, you need to disable SSL verification. In Postman you can find this in the settings: ![Postman settings](https://developer.woocommerce.com/wp-content/uploads/2023/12/postman-ssl.png) Insomnia also has this setting in the preferences area: ![Insomnia settings](https://developer.woocommerce.com/wp-content/uploads/2023/12/insomnia-ssl.png) ### 401 Unauthorized Your API keys or signature is wrong. Ensure that: - The user you generated API keys for actually has access to those resources - The username when authenticating is your consumer key - The password when authenticating is your consumer secret - Make a new set of keys to be sure If your server utilizes FastCGI, check that your [authorization headers are properly read](https://web.archive.org/web/20230330133128/https://support.metalocator.com/en/articles/1654091-wp-json-basic-auth-with-fastcgi). ### Consumer key is missing Occasionally servers may not parse the Authorization header correctly (if you see a "Consumer key is missing" error when authenticating over SSL, you have a server issue). In this case, you may provide the consumer key/secret as query string parameters instead: ```text https://local.wordpress.dev/wp-json/wc/v2/orders?consumer_key=XXXX&consumer_secret=XXXX ``` ### Server does not support POST/DELETE/PUT Ideally, your server should be configured to accept these types of API request, but if not you can use the [`_method` property](https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_method-or-x-http-method-override-header). ## API version history | API Version | WC Version | WP Version | |-------------|----------------|--------------| | `v3` | 3.5.x or later | 4.4 or later | | `v2` | 3.0.x or later | 4.4 or later | | `v1` | 2.6.x or later | 4.4 or later | ## Learn more Learn more about the REST API checking the [official WordPress REST API documentation](https://developer.wordpress.org/rest-api/). --- ## Coupons *Source: apis/rest-api/v1/coupons.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Coupons The coupons API allows you to create, view, update, and delete individual, or a batch, of coupon codes. ## Coupon properties | Attribute | Type | Description | |-------------------------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the object. `READ-ONLY` | | `code` | string | Coupon code. `MANDATORY` | | `date_created` | date-time | The date the coupon was created, in the site's timezone. `READ-ONLY` | | `date_modified` | date-time | The date the coupon was last modified, in the site's timezone. `READ-ONLY` | | `description` | string | Coupon description. | | `discount_type` | string | Determines the type of discount that will be applied. Options: `fixed_cart`, `percent`, `fixed_product` and `percent_product`. Default: `fixed_cart`. | | `amount` | string | The amount of discount. | | `expiry_date` | string | UTC DateTime when the coupon expires. | | `usage_count` | integer | Number of times the coupon has been used already. `READ-ONLY` | | `individual_use` | boolean | Whether coupon can only be used individually. | | `product_ids` | array | List of product ID's the coupon can be used on. | | `exclude_product_ids` | array | List of product ID's the coupon cannot be used on. | | `usage_limit` | integer | How many times the coupon can be used. | | `usage_limit_per_user` | integer | How many times the coupon can be used per customer. | | `limit_usage_to_x_items` | integer | Max number of items in the cart the coupon can be applied to. | | `free_shipping` | boolean | Define if can be applied for free shipping. | | `product_categories` | array | List of category ID's the coupon applies to. | | `excluded_product_categories` | array | List of category ID's the coupon does not apply to. | | `exclude_sale_items` | boolean | Define if should not apply when have sale items. | | `minimum_amount` | string | Minimum order amount that needs to be in the cart before coupon applies. | | `maximum_amount` | string | Maximum order amount allowed when using the coupon. | | `email_restrictions` | array | List of email addresses that can use this coupon. | | `used_by` | array | List of user IDs who have used the coupon. `READ-ONLY` | ## Create a coupon This API helps you to create a new coupon. ```http POST /wp-json/wc/v1/coupons ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/coupons \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "code": "10off", "discount_type": "percent", "amount": 10, "individual_use": true, "exclude_sale_items": true, "minimum_amount": "100.00" }' ``` ```javascript const data = { code: "10off", discount_type: "percent", amount: 10, individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" }; WooCommerce.post("coupons", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php '10off', 'discount_type' => 'percent', 'amount' => 10, 'individual_use' => true, 'exclude_sale_items' => true, 'minimum_amount' => '100.00' ]; print_r($woocommerce->post('coupons', $data)); ?> ``` ```python data = { "code": "10off", "discount_type": "percent", "amount": 10, "individual_use": True, "exclude_sale_items": True, "minimum_amount": "100.00" } print(wcapi.post("coupons", data).json()) ``` ```ruby data = { code: "10off", discount_type: "percent", amount: 10, individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" } woocommerce.post("coupons", data).parsed_response ``` ```json { "id": 113, "code": "10off", "date_created": "2016-04-28T21:55:54", "date_modified": "2016-04-28T21:55:54", "discount_type": "percent", "description": "", "amount": "10.00", "expiry_date": null, "usage_count": 0, "individual_use": true, "product_ids": [], "exclude_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": 0, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/coupons/113" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/coupons" } ] } } ``` ## Retrieve a coupon This API lets you retrieve and view a specific coupon by ID. ```http GET /wp-json/wc/v1/coupons/ ``` ```shell curl https://example.com/wp-json/wc/v1/coupons/113 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("coupons/113") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('coupons/113')); ?> ``` ```python print(wcapi.get("coupons/113").json()) ``` ```ruby woocommerce.get("coupons/113").parsed_response ``` ```json { "id": 113, "code": "10off", "date_created": "2016-04-28T21:55:54", "date_modified": "2016-04-28T21:55:54", "discount_type": "percent", "description": "", "amount": "10.00", "expiry_date": null, "usage_count": 0, "individual_use": true, "product_ids": [], "exclude_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": 0, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/coupons/113" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/coupons" } ] } } ``` ## List all coupons This API helps you to list all the coupons that have been created. ```http GET /wp-json/wc/v1/coupons ``` ```shell curl https://example.com/wp-json/wc/v1/coupons \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("coupons") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('coupons')); ?> ``` ```python print(wcapi.get("coupons").json()) ``` ```ruby woocommerce.get("coupons").parsed_response ``` ```json [ { "id": 114, "code": "free-shipping", "date_created": "2016-04-28T21:58:25", "date_modified": "2016-04-28T21:58:25", "discount_type": "fixed_cart", "description": "", "amount": "0.00", "expiry_date": null, "usage_count": 0, "individual_use": true, "product_ids": [], "exclude_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": 0, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "50.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/coupons/114" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/coupons" } ] } }, { "id": 113, "code": "10off", "date_created": "2016-04-28T21:55:54", "date_modified": "2016-04-28T21:55:54", "discount_type": "percent", "description": "", "amount": "10.00", "expiry_date": null, "usage_count": 0, "individual_use": true, "product_ids": [], "exclude_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": 0, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/coupons/113" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/coupons" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |-----------------|---------|---------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | string | Ensure result set excludes specific ids. | | `include` | string | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `date`, Options: `date`, `id`, `include`, `title` and `slug`. | | `code` | string | Limit result set to resources with a specific code. | ## Update a coupon This API lets you make changes to a coupon. ```http PUT /wp-json/wc/v1/coupons/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v1/coupons/113 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "amount": 5 }' ``` ```javascript const data = { amount: 5 }; WooCommerce.put("coupons/113", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 5 ]; print_r($woocommerce->put('coupons/113', $data)); ?> ``` ```python data = { "amount": 5 } print(wcapi.put("coupons/113", data).json()) ``` ```ruby data = { amount: 5 } woocommerce.put("coupons/113", data).parsed_response ``` ```json { "id": 113, "code": "10off", "date_created": "2016-04-28T21:55:54", "date_modified": "2016-04-28T22:00:49", "discount_type": "percent", "description": "", "amount": "5.00", "expiry_date": null, "usage_count": 0, "individual_use": true, "product_ids": [], "exclude_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": 0, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/coupons/113" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/coupons" } ] } } ``` ## Delete a coupon This API helps you delete a coupon. ```http DELETE /wp-json/wc/v1/coupons/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/coupons/113?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("coupons/113", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('coupons/113', ['force' => true])); ?> ``` ```python print(wcapi.delete("coupons/113", params={"force": True}).json()) ``` ```ruby woocommerce.delete("coupons/113", force: true).parsed_response ``` ```json { "id": 113, "code": "10off", "date_created": "2016-04-28T21:55:54", "date_modified": "2016-04-28T22:00:49", "discount_type": "percent", "description": "", "amount": "5.00", "expiry_date": null, "usage_count": 0, "individual_use": true, "product_ids": [], "exclude_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": 0, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/coupons/113" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/coupons" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|--------------------------------------------------------------------------| | `force` | string | Use `true` whether to permanently delete the coupon, Default is `false`. | ## Batch update coupons This API helps you to batch create, update and delete multiple coupons. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v1/coupons/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/coupons/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "code": "20off", "discount_type": "percent", "amount": 20, "individual_use": true, "exclude_sale_items": true, "minimum_amount": "100.00" }, { "code": "30off", "discount_type": "percent", "amount": 30, "individual_use": true, "exclude_sale_items": true, "minimum_amount": "100.00" } ], "update": [ { "id": 113, "minimum_amount": "50.00" } ], "delete": [ 137 ] }' ``` ```javascript const data = { create: [ { code: "20off", discount_type: "percent", amount: 20, individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" }, { code: "30off", discount_type: "percent", amount: 30, individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" } ], update: [ { id: 113, minimum_amount: "50.00" } ], delete: [ 137 ] }; WooCommerce.post("coupons/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'code' => '20off', 'discount_type' => 'percent', 'amount' => 20, 'individual_use' => true, 'exclude_sale_items' => true, 'minimum_amount' => '100.00' ], [ 'code' => '30off', 'discount_type' => 'percent', 'amount' => 30, 'individual_use' => true, 'exclude_sale_items' => true, 'minimum_amount' => '100.00' ] ], 'update' => [ [ 'id' => 113, 'minimum_amount' => '50.00' ] ], 'delete' => [ 137 ] ]; print_r($woocommerce->post('coupons/batch', $data)); ?> ``` ```python data = { "create": [ { "code": "20off", "discount_type": "percent", "amount": 20, "individual_use": True, "exclude_sale_items": True, "minimum_amount": "100.00" }, { "code": "30off", "discount_type": "percent", "amount": 30, "individual_use": True, "exclude_sale_items": True, "minimum_amount": "100.00" } ], "update": [ { "id": 113, "minimum_amount": "50.00" } ], "delete": [ 137 ] } print(wcapi.post("coupons/batch", data).json()) ``` ```ruby data = { create: [ { code: "20off", discount_type: "percent", amount: 20, individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" }, { code: "30off", discount_type: "percent", amount: 30, individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" } ], update: [ { id: 113, minimum_amount: "50.00" } ], delete: [ 137 ] } woocommerce.post("coupons/batch", data).parsed_response ``` ```json { "create": [ { "id": 138, "code": "20off", "date_created": "2016-05-17T20:52:21", "date_modified": "2016-05-17T20:52:21", "discount_type": "percent", "description": "", "amount": "20.00", "expiry_date": null, "usage_count": 0, "individual_use": true, "product_ids": [], "exclude_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": 0, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/coupons/138" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/coupons" } ] } }, { "id": 139, "code": "30off", "date_created": "2016-05-17T20:52:22", "date_modified": "2016-05-17T20:52:22", "discount_type": "percent", "description": "", "amount": "30.00", "expiry_date": null, "usage_count": 0, "individual_use": true, "product_ids": [], "exclude_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": 0, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/coupons/139" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/coupons" } ] } } ], "update": [ { "id": 113, "code": "10off", "date_created": "2016-04-28T21:55:54", "date_modified": "2016-05-17T20:52:23", "discount_type": "percent", "description": "", "amount": "5.00", "expiry_date": null, "usage_count": 0, "individual_use": true, "product_ids": [], "exclude_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": 0, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "50.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/coupons/113" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/coupons" } ] } } ], "delete": [ { "id": 137, "code": "50off", "date_created": "2016-05-17T20:49:12", "date_modified": "2016-05-17T20:50:30", "discount_type": "fixed_cart", "description": "", "amount": "50.00", "expiry_date": null, "usage_count": 0, "individual_use": false, "product_ids": [], "exclude_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": 0, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": false, "minimum_amount": "0.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/coupons/137" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/coupons" } ] } } ] } ``` --- ## Customers *Source: apis/rest-api/v1/customers.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Customers The customer API allows you to create, view, update, and delete individual, or a batch, of customers. ## Customer properties | Attribute | Type | Description | |-----------------|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | date-time | The date the customer was created, in the site's timezone. `READ-ONLY` | | `date_modified` | date-time | The date the customer was last modified, in the site's timezone. `READ-ONLY` | | `email` | string | The email address for the customer. `MANDATORY` | | `first_name` | string | Customer first name. | | `last_name` | string | Customer last name. | | `username` | string | Customer login name. Can be generated automatically from the customer's email address if the option `woocommerce_registration_generate_username` is equal to `yes` `CANNOT BE CHANGED` `MAYBE MANDATORY` | | `password` | string | Customer password. Can be generated automatically with [`wp_generate_password()`](http://codex.wordpress.org/Function_Reference/wp_generate_password) if the "Automatically generate customer password" option is enabled, check the index meta for `generate_password` `WRITE-ONLY` `MAYBE MANDATORY` | | `last_order` | array | Last order data. See [Customer Last Order properties](#customer-last-order-properties). `READ-ONLY` | | `orders_count` | integer | Quantity of orders made by the customer. `READ-ONLY` | | `total_spent` | string | Total amount spent. `READ-ONLY` | | `avatar_url` | string | Avatar URL. | | `billing` | array | List of billing address data. See [Billing Address properties](#billing-address-properties). | | `shipping` | array | List of shipping address data. See [Shipping Address properties](#shipping-address-properties). | ### Customer last order properties | Attribute | Type | Description | |-----------|-----------|------------------------------------------------------------------------------------| | `id` | integer | Last order ID. `READ-ONLY` | | `date` | date-time | UTC DateTime of the customer last order. `READ-ONLY` | ### Billing address properties | Attribute | Type | Description | |--------------|--------|------------------------------------------------------| | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1. | | `address_2` | string | Address line 2. | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | ISO code of the country. | | `email` | string | Email address. | | `phone` | string | Phone number. | ### Shipping address properties | Attribute | Type | Description | |--------------|--------|------------------------------------------------------| | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1. | | `address_2` | string | Address line 2. | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | ISO code of the country. | ## Create a customer This API helps you to create a new customer. ```http POST /wp-json/wc/v1/customers ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/customers \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } }' ``` ```javascript const data = { email: "john.doe@example.com", first_name: "John", last_name: "Doe", username: "john.doe", billing: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" } }; WooCommerce.post("customers", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'john.doe@example.com', 'first_name' => 'John', 'last_name' => 'Doe', 'username' => 'john.doe', 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ] ]; print_r($woocommerce->post('customers', $data)); ?> ``` ```python data = { "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } } print(wcapi.post("customers", data).json()) ``` ```ruby data = { email: "john.doe@example.com", first_name: "John", last_name: "Doe", username: "john.doe", billing: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" } } woocommerce.post("customers", data).parsed_response ``` ```json { "id": 2, "date_created": "2016-05-03T17:58:35", "date_modified": "2016-05-11T21:34:43", "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe", "last_order": { "id": 118, "date": "2016-05-03T18:10:43" }, "orders_count": 3, "total_spent": "28.00", "avatar_url": "https://secure.gravatar.com/avatar/?s=96", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/customers/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/customers" } ] } } ``` ## Retrieve a customer This API lets you retrieve and view a specific customer by ID. ```http GET /wp-json/wc/v1/customers/ ``` ```shell curl https://example.com/wp-json/wc/v1/customers/2 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("customers/2") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('customers/2')); ?> ``` ```python print(wcapi.get("customers/2").json()) ``` ```ruby woocommerce.get("customers/2").parsed_response ``` ```json { "id": 2, "date_created": "2016-05-03T17:58:35", "date_modified": "2016-05-11T21:34:43", "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe", "last_order": { "id": 118, "date": "2016-05-03T18:10:43" }, "orders_count": 3, "total_spent": "28.00", "avatar_url": "https://secure.gravatar.com/avatar/?s=96", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/customers/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/customers" } ] } } ``` ## List all customers This API helps you to view all the customers. ```http GET /wp-json/wc/v1/customers ``` ```shell curl https://example.com/wp-json/wc/v1/customers \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("customers") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('customers')); ?> ``` ```python print(wcapi.get("customers").json()) ``` ```ruby woocommerce.get("customers").parsed_response ``` ```json [ { "id": 5, "date_created": "2016-05-11T21:39:01", "date_modified": "2016-05-11T21:40:02", "email": "joao.silva@example.com", "first_name": "João", "last_name": "Silva", "username": "joao.silva", "last_order": { "id": null, "date": null }, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/?s=96", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/customers/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/customers" } ] } }, { "id": 2, "date_created": "2016-05-03T17:58:35", "date_modified": "2016-05-11T21:34:43", "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe", "last_order": { "id": 118, "date": "2016-05-03T18:10:43" }, "orders_count": 3, "total_spent": "28.00", "avatar_url": "https://secure.gravatar.com/avatar/?s=96", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/customers/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/customers" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `search` | string | Limit results to those matching a string. | | `exclude` | string | Ensure result set excludes specific ids. | | `include` | string | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`, Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `name`. Options: `id`, `include`, `name` and `registered_date`. | | `email` | string | Limit result set to resources with a specific email. | | `role` | string | Limit result set to resources with a specific role. Default: `customer`. Options (some plugins can add more user roles): `all`, `administrator`, `editor`, `author`, `contributor`, `subscriber`, `customer` and `shop_manager` | ## Update a customer This API lets you make changes to a customer. ```http PUT /wp-json/wc/v1/customers/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v1/customers/2 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "first_name": "James", "billing": { "first_name": "James" }, "shipping": { "first_name": "James" } }' ``` ```javascript const data = { first_name: "James", billing: { first_name: "James" }, shipping: { first_name: "James" } }; WooCommerce.put("customers/2", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'James', 'billing' => [ 'first_name' => 'James' ], 'shipping' => [ 'first_name' => 'James' ] ]; print_r($woocommerce->put('customers/2', $data)); ?> ``` ```python data = { "first_name": "James", "billing": { "first_name": "James" }, "shipping": { "first_name": "James" } } print(wcapi.put("customers/2", data).json()) ``` ```ruby data = { first_name: "James", billing: { first_name: "James" }, shipping: { first_name: "James" } } woocommerce.put("customers/2", data).parsed_response ``` ```json { "id": 2, "date_created": "2016-05-03T17:58:35", "date_modified": "2016-05-11T21:43:45", "email": "john.doe@example.com", "first_name": "James", "last_name": "Doe", "username": "john.doe", "last_order": { "id": 118, "date": "2016-05-03T18:10:43" }, "orders_count": 3, "total_spent": "28.00", "avatar_url": "https://secure.gravatar.com/avatar/?s=96", "billing": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/customers/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/customers" } ] } } ``` ## Delete a customer This API helps you delete a customer. ```http DELETE /wp-json/wc/v1/customers/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/customers/2?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("customers/2", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('customers/2', ['force' => true])); ?> ``` ```python print(wcapi.delete("customers/2", params={"force": True}).json()) ``` ```ruby woocommerce.delete("customers/2", force: true).parsed_response ``` ```json { "id": 2, "date_created": "2016-05-03T17:58:35", "date_modified": "2016-05-11T21:43:45", "email": "john.doe@example.com", "first_name": "James", "last_name": "Doe", "username": "john.doe", "last_order": { "id": 118, "date": "2016-05-03T18:10:43" }, "orders_count": 3, "total_spent": "28.00", "avatar_url": "https://secure.gravatar.com/avatar/?s=96", "billing": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/customers/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/customers" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update customers This API helps you to batch create, update and delete multiple customers. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v1/customers/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/customers/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "email": "john.doe2@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe2", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } }, { "email": "joao.silva2@example.com", "first_name": "João", "last_name": "Silva", "username": "joao.silva2", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" } } ], "update": [ { "id": 5, "billing": { "phone": "(11) 1111-1111" } } ], "delete": [ 2 ] }' ``` ```javascript const data = { create: [ { email: "john.doe2@example.com", first_name: "John", last_name: "Doe", username: "john.doe2", billing: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" } }, { email: "joao.silva2@example.com", first_name: "João", last_name: "Silva", username: "joao.silva2", billing: { first_name: "João", last_name: "Silva", company: "", address_1: "Av. Brasil, 432", address_2: "", city: "Rio de Janeiro", state: "RJ", postcode: "12345-000", country: "BR", email: "joao.silva@example.com", phone: "(55) 5555-5555" }, shipping: { first_name: "João", last_name: "Silva", company: "", address_1: "Av. Brasil, 432", address_2: "", city: "Rio de Janeiro", state: "RJ", postcode: "12345-000", country: "BR" } } ], update: [ { id: 5, billing: { phone: "(11) 1111-1111" } } ], delete: [ 2 ] }; WooCommerce.post("customers/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'email' => 'john.doe2@example.com', 'first_name' => 'John', 'last_name' => 'Doe', 'username' => 'john.doe2', 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ] ], [ 'email' => 'joao.silva2@example.com', 'first_name' => 'João', 'last_name' => 'Silva', 'username' => 'joao.silva2', 'billing' => [ 'first_name' => 'João', 'last_name' => 'Silva', 'company' => '', 'address_1' => 'Av. Brasil, 432', 'address_2' => '', 'city' => 'Rio de Janeiro', 'state' => 'RJ', 'postcode' => '12345-000', 'country' => 'BR', 'email' => 'joao.silva@example.com', 'phone' => '(55) 5555-5555' ], 'shipping' => [ 'first_name' => 'João', 'last_name' => 'Silva', 'company' => '', 'address_1' => 'Av. Brasil, 432', 'address_2' => '', 'city' => 'Rio de Janeiro', 'state' => 'RJ', 'postcode' => '12345-000', 'country' => 'BR' ] ] ], 'update' => [ [ 'id' => 5, 'billing' => [ 'phone' => '(11) 1111-1111' ] ] ], 'delete' => [ 2 ] ]; print_r($woocommerce->post('customers/batch', $data)); ?> ``` ```python data = { "create": [ { "email": "john.doe2@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe2", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } }, { "email": "joao.silva2@example.com", "first_name": "João", "last_name": "Silva", "username": "joao.silva2", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" } } ], "update": [ { "id": 5, "billing": { "phone": "(11) 1111-1111" } } ], "delete": [ 2 ] } print(wcapi.post("customers/batch", data).json()) ``` ```ruby data = { create: [ { email: "john.doe2@example.com", first_name: "John", last_name: "Doe", username: "john.doe2", billing: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" } }, { email: "joao.silva2@example.com", first_name: "João", last_name: "Silva", username: "joao.silva2", billing: { first_name: "João", last_name: "Silva", company: "", address_1: "Av. Brasil, 432", address_2: "", city: "Rio de Janeiro", state: "RJ", postcode: "12345-000", country: "BR", email: "joao.silva@example.com", phone: "(55) 5555-5555" }, shipping: { first_name: "João", last_name: "Silva", company: "", address_1: "Av. Brasil, 432", address_2: "", city: "Rio de Janeiro", state: "RJ", postcode: "12345-000", country: "BR" } } ], update: [ { id: 5, billing: { phone: "(11) 1111-1111" } } ], delete: [ 2 ] } woocommerce.post("customers/batch", data).parsed_response ``` ```json { "create": [ { "id": 6, "date_created": "2016-05-11T22:06:32", "date_modified": "2016-05-11T22:07:31", "email": "john.doe2@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe2", "last_order": { "id": null, "date": null }, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/?s=96", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/customers/6" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/customers" } ] } }, { "id": 7, "date_created": "2016-05-11T22:07:33", "date_modified": "2016-05-11T22:07:37", "email": "joao.silva2@example.com", "first_name": "João", "last_name": "Silva", "username": "joao.silva2", "last_order": { "id": null, "date": null }, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/?s=96", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/customers/7" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/customers" } ] } } ], "update": [ { "id": 5, "date_created": "2016-05-11T21:39:01", "date_modified": "2016-05-11T22:04:36", "email": "joao.silva@example.com", "first_name": "João", "last_name": "Silva", "username": "joao.silva", "last_order": { "id": null, "date": null }, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/?s=96", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(11) 1111-1111" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/customers/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/customers" } ] } } ], "delete": [ { "id": 2, "date_created": "2016-05-03T17:58:35", "date_modified": "2016-05-11T21:43:45", "email": "john.doe@example.com", "first_name": "James", "last_name": "Doe", "username": "john.doe", "last_order": { "id": 118, "date": "2016-05-03T18:10:43" }, "orders_count": 3, "total_spent": "28.00", "avatar_url": "https://secure.gravatar.com/avatar/?s=96", "billing": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/customers/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/customers" } ] } } ] } ``` ## Retrieve customer downloads This API lets you retrieve customer downloads permissions. ```http GET /wp-json/wc/v1/customers//downloads ``` ```shell curl https://example.com/wp-json/wc/v1/customers/2/downloads \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("customers/2/downloads") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('customers/2/downloads')); ?> ``` ```python print(wcapi.get("customers/2/downloads").json()) ``` ```ruby woocommerce.get("customers/2/downloads").parsed_response ``` ```json [ { "download_url": "https://example.com/?download_file=96&order=wc_order_571a7260c0da5&email=john.dow@xanmple.com&key=1789931e0c14ad9909a50c826f10c169", "download_id": "1789931e0c14ad9909a50c826f10c169", "product_id": 96, "download_name": "Woo Album #4 – Testing", "order_id": 105, "order_key": "wc_order_571a7260c0da5", "downloads_remaining": "unlimited", "access_expires": "never", "file": { "name": "Testing", "file": "http://example.com/wp-content/uploads/2013/06/cd_5_angle.jpg" }, "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v1/customers/1/downloads" } ], "product": [ { "href": "https://example.com/wp-json/wc/v1/products/96" } ], "order": [ { "href": "https://example.com/wp-json/wc/v1/orders/105" } ] } } ] ``` ### Customer downloads properties | Attribute | Type | Description | |-----------------------|---------|------------------------------------------------------------------------------------------------------------------| | `download_url` | string | Download file URL. `READ-ONLY` | | `download_id` | string | Download ID (MD5). `READ-ONLY` | | `product_id` | integer | Downloadable product ID. `READ-ONLY` | | `download_name` | string | Downloadable file name. `READ-ONLY` | | `order_id` | integer | Order ID. `READ-ONLY` | | `order_key` | string | Order key. `READ-ONLY` | | `downloads_remaining` | string | Amount of downloads remaining. `READ-ONLY` | | `access_expires` | string | The date when the download access expires, in the site's timezone. `READ-ONLY` | | `file` | array | File details with `name` (file name) and `file` (file URL) attributes. `READ-ONLY` | --- ## REST API v1 *Source: apis/rest-api/v1/index.mdx* import DocCardList from '@theme/DocCardList'; Legacy version of the WooCommerce REST API. Use `/wp-json/wc/v1/` endpoints. Consider migrating to v3 for new integrations. --- ## Order notes *Source: apis/rest-api/v1/order-notes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Order notes The order notes API allows you to create, view, and delete individual order notes. Order notes are added by administrators and programmatically to store data about an order, or order events. ## Order note properties | Attribute | Type | Description | |-----------------|-----------|---------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | date-time | The date the order note was created, in the site's timezone. `READ-ONLY` | | `note` | string | Order note. `REQUIRED` | | `customer_note` | boolean | Shows/define if the note is only for reference or for the customer (the user will be notified). Default is `false`. | ## Create an order note This API helps you to create a new note for an order. ```http POST /wp-json/wc/v1/orders//notes ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/orders/645/notes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "note": "Order ok!!!" }' ``` ```javascript const data = { note: "Order ok!!!" }; WooCommerce.post("orders/645/notes", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Order ok!!!' ]; print_r($woocommerce->post('orders/645/notes', $data)); ?> ``` ```python data = { "note": "Order ok!!!" } print(wcapi.post("orders/645/notes", data).json()) ``` ```ruby data = { note: "Order ok!!!" } woocommerce.post("orders/645/notes", data).parsed_response ``` ```json { "id": 51, "date_created": "2016-05-13T20:51:55", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/118/notes/51" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders/118/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/orders/118" } ] } } ``` ## Retrieve an order note This API lets you retrieve and view a specific note from an order. ```http GET /wp-json/wc/v1/orders//notes/ ``` ```shell curl https://example.com/wp-json/wc/v1/orders/645/notes/51 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders/645/notes/51") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders/645/notes/51')); ?> ``` ```python print(wcapi.get("orders/645/notes/51").json()) ``` ```ruby woocommerce.get("orders/645/notes/51").parsed_response ``` ```json { "id": 51, "date_created": "2016-05-13T20:51:55", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/118/notes/51" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders/118/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/orders/118" } ] } } ``` ## List all order notes This API helps you to view all the notes from an order. ```http GET /wp-json/wc/v1/orders//notes ``` ```shell curl https://example.com/wp-json/wc/v1/orders/645/notes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders/645/notes") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders/645/notes')); ?> ``` ```python print(wcapi.get("orders/645/notes").json()) ``` ```ruby woocommerce.get("orders/645/notes").parsed_response ``` ```json [ { "id": 51, "date_created": "2016-05-13T20:51:55", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/118/notes/51" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders/118/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/orders/118" } ] } }, { "id": 46, "date_created": "2016-05-03T18:10:43", "note": "Order status changed from Pending Payment to Processing.", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/118/notes/46" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders/118/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/orders/118" } ] } } ] ``` ## Delete an order note This API helps you delete an order note. ```http DELETE /wp-json/wc/v1/orders//notes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/orders/645/notes/51?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("orders/645/notes/51", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('orders/645/notes/51', ['force' => true])); ?> ``` ```python print(wcapi.delete("orders/645/notes/51", params={"force": True}).json()) ``` ```ruby woocommerce.delete("orders/645/notes/51", force: true).parsed_response ``` ```json { "id": 51, "date_created": "2016-05-13T20:51:55", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/118/notes/51" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders/118/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/orders/118" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | --- ## Refunds *Source: apis/rest-api/v1/order-refunds.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Refunds The refunds API allows you to create, view, and delete individual refunds. ## Refund properties | Attribute | Type | Description | |----------------|-----------|----------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | date-time | The date the order refund was created, in the site's timezone. `READ-ONLY` | | `amount` | string | Refund amount. `REQUIRED` | | `reason` | string | Reason for refund. | | `line_items` | array | Line items data. See [Refunds Line Items properties](#refund-line-item-properties). | ### Refund line item properties | Attribute | Type | Description | |----------------|---------|------------------------------------------------------------------------------------------------| | `id` | integer | Item ID. `READ-ONLY` | | `name` | string | Product name. `READ-ONLY` | | `sku` | string | Product SKU. `READ-ONLY` | | `product_id` | integer | Product ID. | | `variation_id` | integer | Variation ID, if applicable. | | `quantity` | integer | Quantity ordered. | | `tax_class` | string | Tax class of product. `READ-ONLY` | | `price` | string | Product price. `READ-ONLY` | | `subtotal` | string | Line subtotal (before discounts). | | `subtotal_tax` | string | Line subtotal tax (before discounts). | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). | | `taxes` | array | Line total tax with `id`, `total` and `subtotal`. `READ-ONLY` | | `meta` | array | Line item meta data with `key`, `label` and `value`. `READ-ONLY` | ## Create a refund This API helps you to create a new refund for an order. ```http POST /wp-json/wc/v1/orders//refunds ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/orders/116/refunds \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "amount": "10" }' ``` ```javascript const data = { amount: "10" }; WooCommerce.post("orders/116/refunds", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php '10' ]; print_r($woocommerce->post('orders/116/refunds', $data)); ?> ``` ```python data = { "amount": "10" } print(wcapi.post("orders/116/refunds", data).json()) ``` ```ruby data = { amount: "10" } woocommerce.post("orders/116/refunds", data).parsed_response ``` ```json { "id": 150, "date_created": "2016-05-30T17:28:05", "amount": "10.00", "reason": "", "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/116/refunds/150" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders/116/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/orders/116" } ] } } ``` ## Retrieve a refund This API lets you retrieve and view a specific refund from an order. ```http GET /wp-json/wc/v1/orders//refunds/ ``` ```shell curl https://example.com/wp-json/wc/v1/orders/116/refunds/150 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders/116/refunds/150") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders/116/refunds/150')); ?> ``` ```python print(wcapi.get("orders/116/refunds/150").json()) ``` ```ruby woocommerce.get("orders/116/refunds/150").parsed_response ``` ```json { "id": 150, "date_created": "2016-05-30T17:28:05", "amount": "10.00", "reason": "", "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/116/refunds/150" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders/116/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/orders/116" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------| | `dp` | string | Number of decimal points to use in each resource. | ## List all refunds This API helps you to view all the refunds from an order. ```http GET /wp-json/wc/v1/orders//refunds ``` ```shell curl https://example.com/wp-json/wc/v1/orders/116/refunds \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders/116/refunds") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders/116/refunds')); ?> ``` ```python print(wcapi.get("orders/116/refunds").json()) ``` ```ruby woocommerce.get("orders/116/refunds").parsed_response ``` ```json [ { "id": 151, "date_created": "2016-05-30T17:31:48", "amount": "2.00", "reason": "", "line_items": [ { "id": 11, "name": "Woo Single #2", "sku": "12345", "product_id": 99, "variation_id": 0, "quantity": -1, "tax_class": "", "price": "-2.00", "subtotal": "-2.00", "subtotal_tax": "0.00", "total": "-2.00", "total_tax": "0.00", "taxes": [], "meta": [] } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/116/refunds/151" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders/116/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/orders/116" } ] } }, { "id": 150, "date_created": "2016-05-30T17:28:05", "amount": "10.00", "reason": "", "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/116/refunds/150" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders/116/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/orders/116" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |-----------------|---------|---------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | string | Ensure result set excludes specific ids. | | `include` | string | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `date`, Options: `date`, `id`, `include`, `title` and `slug`. | | `dp` | string | Number of decimal points to use in each resource. | ## Delete a refund This API helps you delete an order refund. ```http DELETE /wp-json/wc/v1/orders//refunds/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/orders/116/refunds/150?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("orders/116/refunds/150", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('orders/116/refunds/150', ['force' => true])); ?> ``` ```python print(wcapi.delete("orders/116/refunds/150", params={"force": True}).json()) ``` ```ruby woocommerce.delete("orders/116/refunds/150", force: true).parsed_response ``` ```json { "id": 150, "date_created": "2016-05-30T17:28:05", "amount": "10.00", "reason": "", "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/116/refunds/150" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders/116/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/orders/116" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | --- ## Orders *Source: apis/rest-api/v1/orders.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Orders The orders API allows you to create, view, update, and delete individual, or a batch, of orders. ## Order properties | Attribute | Type | Description | |------------------------|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `parent_id` | integer | Parent order ID. | | `status` | string | Order status. Default is `pending`. Options (plugins may include new status): `pending`, `processing`, `on-hold`, `completed`, `cancelled`, `refunded` and `failed`. | | `order_key` | string | Order key. `READ-ONLY` | | `number` | string | Order number. `READ-ONLY` | | `currency` | string | Currency the order was created with, in ISO format, e.g `USD`. Default is the current store currency. | | `version` | string | Version of WooCommerce when the order was made. `READ-ONLY` | | `prices_include_tax` | boolean | Shows if the prices included tax during checkout. `READ-ONLY` | | `date_created` | date-time | The date the order was created, in the site's timezone. `READ-ONLY` | | `date_modified` | date-time | The date the order was last modified, in the site's timezone. `READ-ONLY` | | `customer_id` | integer | User ID who owns the order. Use `0` for guests. Default is `0`. | | `discount_total` | string | Total discount amount for the order. `READ-ONLY` | | `discount_tax` | string | Total discount tax amount for the order. `READ-ONLY` | | `shipping_total` | string | Total shipping amount for the order. `READ-ONLY` | | `shipping_tax` | string | Total shipping tax amount for the order. `READ-ONLY` | | `cart_tax` | string | Sum of line item taxes only. `READ-ONLY` | | `total` | string | Grand total. `READ-ONLY` | | `total_tax` | string | Sum of all taxes. `READ-ONLY` | | `billing` | object | Billing address. See [Customer Billing Address properties](#billing-address-properties). | | `shipping` | object | Shipping address. See [Customer Shipping Address properties](#shipping-address-properties). | | `payment_method` | string | Payment method ID. | | `payment_method_title` | string | Payment method title. | | `set_paid` | boolean | Define if the order is paid. It will set the status to processing and reduce stock items. Default is `false`. `WRITE-ONLY` | | `transaction_id` | string | Unique transaction ID. In write-mode only is available if `set_paid` is `true`. | | `customer_ip_address` | string | Customer's IP address. `READ-ONLY` | | `customer_user_agent` | string | User agent of the customer. `READ-ONLY` | | `created_via` | string | Shows where the order was created. `READ-ONLY` | | `customer_note` | string | Note left by customer during checkout. | | `date_completed` | date-time | The date the order was completed, in the site's timezone. `READ-ONLY` | | `date_paid` | date-time | The date the order has been paid, in the site's timezone. `READ-ONLY` | | `cart_hash` | string | MD5 hash of cart items to ensure orders are not modified. `READ-ONLY` | | `line_items` | array | Line items data. See [Line Items properties](#line-item-properties). | | `tax_lines` | array | Tax lines data. See [Tax Lines properties](#tax-line-properties). `READ-ONLY` | | `shipping_lines` | array | Shipping lines data. See [Shipping Lines properties](#shipping-line-properties). | | `fee_lines` | array | Fee lines data. See [Fee Lines Properties](#fee-line-properties). | | `coupon_lines` | array | Coupons line data. See [Coupon Lines properties](#coupon-line-properties). | | `refunds` | array | List of refunds. See [Refund line properties](#refund-line-properties). `READ-ONLY` | ### Billing address properties | Attribute | Type | Description | | ------------ | ------ | ---------------------------------------------------- | | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1. | | `address_2` | string | Address line 2. | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | ISO code of the country. | | `email` | string | Email address. | | `phone` | string | Phone number. | ### Shipping address properties | Attribute | Type | Description | | ------------ | ------ | ---------------------------------------------------- | | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1. | | `address_2` | string | Address line 2. | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | ISO code of the country. | ### Line item properties | Attribute | Type | Description | |----------------|---------|------------------------------------------------------------------------------------------------| | `id` | integer | Item ID. `READ-ONLY` | | `name` | string | Product name. `READ-ONLY` | | `sku` | string | Product SKU. `READ-ONLY` | | `product_id` | integer | Product ID. | | `variation_id` | integer | Variation ID, if applicable. | | `quantity` | integer | Quantity ordered. | | `tax_class` | string | Tax class of product. `READ-ONLY` | | `price` | string | Product price. `READ-ONLY` | | `subtotal` | string | Line subtotal (before discounts). | | `subtotal_tax` | string | Line subtotal tax (before discounts). | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). | | `taxes` | array | Line taxes with `id`, `total` and `subtotal`. `READ-ONLY` | | `meta` | array | Line item meta data with `key`, `label` and `value`. `READ-ONLY` | ### Tax line properties | Attribute | Type | Description | |----------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Item ID. `READ-ONLY` | | `rate_code` | string | Tax rate code. `READ-ONLY` | | `rate_id` | string | Tax rate ID. `READ-ONLY` | | `label` | string | Tax rate label. `READ-ONLY` | | `compound` | boolean | Show if is a compound tax rate. Compound tax rates are applied on top of other tax rates. `READ-ONLY` | | `tax_total` | string | Tax total (not including shipping taxes). `READ-ONLY` | | `shipping_tax_total` | string | Shipping tax total. `READ-ONLY` | ### Shipping line properties | Attribute | Type | Description | |----------------|---------|-----------------------------------------------------------------------------| | `id` | integer | Item ID. `READ-ONLY` | | `method_title` | string | Shipping method name. | | `method_id` | string | Shipping method ID. `REQUIRED` | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). `READ-ONLY` | | `taxes` | array | Line taxes with `id` and `total`. `READ-ONLY` | ### Fee line properties | Attribute | Type | Description | |--------------|---------|-----------------------------------------------------------------------------------------| | `id` | integer | Item ID. `READ-ONLY` | | `name` | string | Fee name. `REQUIRED` | | `tax_class` | string | Tax class. `REQUIRED IF THE FEE IS TAXABLE` | | `tax_status` | string | Tax status of fee. Set to `taxable` if need apply taxes. | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). | | `taxes` | array | Line taxes with `id`, `total` and `subtotal`. `READ-ONLY` | ### Coupon line properties | Attribute | Type | Description | |----------------|---------|---------------------------------------------------------------| | `id` | integer | Item ID. `READ-ONLY` | | `code` | string | Coupon code. `REQUIRED` | | `discount` | string | Discount total. `REQUIRED` | | `discount_tax` | string | Discount total tax. `READ-ONLY` | ### Refund line properties | Attribute | Type | Description | |-----------|---------|----------------------------------------------------------| | `id` | integer | Refund ID. `READ-ONLY` | | `reason` | string | Refund reason. `READ-ONLY` | | `total` | string | Refund total. `READ-ONLY` | ## Create an order This API helps you to create a new order. ```http POST /wp-json/wc/v1/orders ``` > Example of create a paid order: ```shell curl -X POST https://example.com/wp-json/wc/v1/orders \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": true, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 93, "quantity": 2 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "10.00" } ] }' ``` ```javascript const data = { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", set_paid: true, billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 93, quantity: 2 }, { product_id: 22, variation_id: 23, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "10.00" } ] }; WooCommerce.post("orders", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'bacs', 'payment_method_title' => 'Direct Bank Transfer', 'set_paid' => true, 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ], 'line_items' => [ [ 'product_id' => 93, 'quantity' => 2 ], [ 'product_id' => 22, 'variation_id' => 23, 'quantity' => 1 ] ], 'shipping_lines' => [ [ 'method_id' => 'flat_rate', 'method_title' => 'Flat Rate', 'total' => '10.00' ] ] ]; print_r($woocommerce->post('orders', $data)); ?> ``` ```python data = { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": True, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 93, "quantity": 2 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "10.00" } ] } print(wcapi.post("orders", data).json()) ``` ```ruby data = { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", set_paid: true, billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 93, quantity: 2 }, { product_id: 22, variation_id: 23, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "10.00" } ] } woocommerce.post("orders", data).parsed_response ``` ```json { "id": 154, "parent_id": 0, "status": "processing", "order_key": "wc_order_574cc02467274", "number": "154", "currency": "USD", "version": "2.6.0", "prices_include_tax": false, "date_created": "2016-05-30T22:35:16", "date_modified": "2016-05-30T22:35:16", "customer_id": 0, "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.95", "total": "37.95", "total_tax": "1.95", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "bacs", "transaction_id": "", "customer_ip_address": "127.0.0.1", "customer_user_agent": "curl/7.47.0", "created_via": "rest-api", "customer_note": "", "date_completed": "2016-05-30T19:35:16", "date_paid": "2016-05-30 19:35:25", "cart_hash": "", "line_items": [ { "id": 18, "name": "Woo Single #1", "sku": "", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "price": "3.00", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": 0.45, "subtotal": 0.45 } ], "meta": [] }, { "id": 19, "name": "Ship Your Idea", "sku": "", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "price": "20.00", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": 1.5, "subtotal": 1.5 } ], "meta": [ { "key": "pa_color", "label": "Color", "value": "Black" } ] } ], "tax_lines": [ { "id": 21, "rate_code": "US-CA-STATE TAX", "rate_id": "75", "label": "State Tax", "compound": false, "tax_total": "1.95", "shipping_tax_total": "0.00" } ], "shipping_lines": [ { "id": 20, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/154" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders" } ] } } ``` ## Retrieve an order This API lets you retrieve and view a specific order. ```http GET /wp-json/wc/v1/orders/ ``` ```shell curl https://example.com/wp-json/wc/v1/orders/154 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders/154") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders/154')); ?> ``` ```python print(wcapi.get("orders/154").json()) ``` ```ruby woocommerce.get("orders/154").parsed_response ``` ```json { "id": 154, "parent_id": 0, "status": "processing", "order_key": "wc_order_574cc02467274", "number": "154", "currency": "USD", "version": "2.6.0", "prices_include_tax": false, "date_created": "2016-05-30T22:35:16", "date_modified": "2016-05-30T22:35:16", "customer_id": 0, "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.95", "total": "37.95", "total_tax": "1.95", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "bacs", "transaction_id": "", "customer_ip_address": "127.0.0.1", "customer_user_agent": "curl/7.47.0", "created_via": "rest-api", "customer_note": "", "date_completed": "2016-05-30T19:35:16", "date_paid": "2016-05-30 19:35:25", "cart_hash": "", "line_items": [ { "id": 18, "name": "Woo Single #1", "sku": "", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "price": "3.00", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": 0.45, "subtotal": 0.45 } ], "meta": [] }, { "id": 19, "name": "Ship Your Idea", "sku": "", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "price": "20.00", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": 1.5, "subtotal": 1.5 } ], "meta": [ { "key": "pa_color", "label": "Color", "value": "Black" } ] } ], "tax_lines": [ { "id": 21, "rate_code": "US-CA-STATE TAX", "rate_id": "75", "label": "State Tax", "compound": false, "tax_total": "1.95", "shipping_tax_total": "0.00" } ], "shipping_lines": [ { "id": 20, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/154" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------| | `dp` | string | Number of decimal points to use in each resource. | ## List all orders This API helps you to view all the orders. ```http GET /wp-json/wc/v1/orders ``` ```shell curl https://example.com/wp-json/wc/v1/orders \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders')); ?> ``` ```python print(wcapi.get("orders").json()) ``` ```ruby woocommerce.get("orders").parsed_response ``` ```json [ { "id": 154, "parent_id": 0, "status": "processing", "order_key": "wc_order_574cc02467274", "number": "154", "currency": "USD", "version": "2.6.0", "prices_include_tax": false, "date_created": "2016-05-30T22:35:16", "date_modified": "2016-05-30T22:35:16", "customer_id": 0, "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.95", "total": "37.95", "total_tax": "1.95", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "bacs", "transaction_id": "", "customer_ip_address": "127.0.0.1", "customer_user_agent": "curl/7.47.0", "created_via": "rest-api", "customer_note": "", "date_completed": "2016-05-30T19:35:16", "date_paid": "2016-05-30 19:35:25", "cart_hash": "", "line_items": [ { "id": 18, "name": "Woo Single #1", "sku": "", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "price": "3.00", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": 0.45, "subtotal": 0.45 } ], "meta": [] }, { "id": 19, "name": "Ship Your Idea", "sku": "", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "price": "20.00", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": 1.5, "subtotal": 1.5 } ], "meta": [ { "key": "pa_color", "label": "Color", "value": "Black" } ] } ], "tax_lines": [ { "id": 21, "rate_code": "US-CA-STATE TAX", "rate_id": "75", "label": "State Tax", "compound": false, "tax_total": "1.95", "shipping_tax_total": "0.00" } ], "shipping_lines": [ { "id": 20, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/154" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders" } ] } }, { "id": 116, "parent_id": 0, "status": "processing", "order_key": "wc_order_5728e6e53d2a4", "number": "116", "currency": "USD", "version": "2.6.0", "prices_include_tax": false, "date_created": "2016-05-03T17:59:00", "date_modified": "2016-05-30T22:37:31", "customer_id": 1, "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "0.00", "total": "14.00", "total_tax": "0.00", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@claudiosmweb.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "customer_ip_address": "127.0.0.1", "customer_user_agent": "curl/7.47.0", "created_via": "", "customer_note": "", "date_completed": "2016-05-30T19:35:16", "date_paid": "2016-05-03 14:59:12", "cart_hash": "", "line_items": [ { "id": 6, "name": "Woo Single #2", "sku": "12345", "product_id": 99, "variation_id": 0, "quantity": 2, "tax_class": "", "price": "2.00", "subtotal": "4.00", "subtotal_tax": "0.00", "total": "4.00", "total_tax": "0.00", "taxes": [], "meta": [] } ], "tax_lines": [], "shipping_lines": [ { "id": 7, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/116" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders" } ], "customer": [ { "href": "https://example.com/wp-json/wc/v1/customers/1" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |-----------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | string | Ensure result set excludes specific ids. | | `include` | string | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `date`, Options: `date`, `id`, `include`, `title` and `slug`. | | `status` | string | Limit result set to orders assigned a specific status. Default is `any`. Options (plugins may add new status): `any`, `pending`, `processing`, `on-hold`, `completed`, `cancelled`, `refunded` and `failed`. | | `customer` | string | Limit result set to orders assigned a specific customer. | | `product` | string | Limit result set to orders assigned a specific product. | | `dp` | string | Number of decimal points to use in each resource. | ## Update an Order This API lets you make changes to an order. ### HTTP Request ```http PUT /wp-json/wc/v1/orders/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v1/orders/154 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "status": "completed" }' ``` ```javascript const data = { status: "completed" }; WooCommerce.put("orders/154", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'completed' ]; print_r($woocommerce->put('orders/154', $data)); ?> ``` ```python data = { "status": "completed" } print(wcapi.put("orders/154", data).json()) ``` ```ruby data = { status: "completed" } woocommerce.put("orders/154", data).parsed_response ``` ```json { "id": 154, "parent_id": 0, "status": "completed", "order_key": "wc_order_574cc02467274", "number": "154", "currency": "USD", "version": "2.6.0", "prices_include_tax": false, "date_created": "2016-05-30T22:35:16", "date_modified": "2016-05-30T22:46:16", "customer_id": 0, "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.95", "total": "37.95", "total_tax": "1.95", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "bacs", "transaction_id": "", "customer_ip_address": "127.0.0.1", "customer_user_agent": "curl/7.47.0", "created_via": "rest-api", "customer_note": "", "date_completed": "2016-05-30T19:47:46", "date_paid": "2016-05-30 19:35:25", "cart_hash": "", "line_items": [ { "id": 18, "name": "Woo Single #1", "sku": "", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "price": "3.00", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": 0.45, "subtotal": 0.45 } ], "meta": [] }, { "id": 19, "name": "Ship Your Idea", "sku": "", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "price": "20.00", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": 1.5, "subtotal": 1.5 } ], "meta": [ { "key": "pa_color", "label": "Color", "value": "Black" } ] } ], "tax_lines": [ { "id": 21, "rate_code": "US-CA-STATE TAX", "rate_id": "75", "label": "State Tax", "compound": false, "tax_total": "1.95", "shipping_tax_total": "0.00" } ], "shipping_lines": [ { "id": 20, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/154" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders" } ] } } ``` ## Delete an order This API helps you delete an order. ```http DELETE /wp-json/wc/v1/orders/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/orders/154?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("orders/154", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('orders/154', ['force' => true])); ?> ``` ```python print(wcapi.delete("orders/154", params={"force": True}).json()) ``` ```ruby woocommerce.delete("orders/154", force: true).parsed_response ``` ```json { "id": 154, "parent_id": 0, "status": "completed", "order_key": "wc_order_574cc02467274", "number": "154", "currency": "USD", "version": "2.6.0", "prices_include_tax": false, "date_created": "2016-05-30T22:35:16", "date_modified": "2016-05-30T22:46:16", "customer_id": 0, "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.95", "total": "37.95", "total_tax": "1.95", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "bacs", "transaction_id": "", "customer_ip_address": "127.0.0.1", "customer_user_agent": "curl/7.47.0", "created_via": "rest-api", "customer_note": "", "date_completed": "2016-05-30T19:47:46", "date_paid": "2016-05-30 19:35:25", "cart_hash": "", "line_items": [ { "id": 18, "name": "Woo Single #1", "sku": "", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "price": "3.00", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": 0.45, "subtotal": 0.45 } ], "meta": [] }, { "id": 19, "name": "Ship Your Idea", "sku": "", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "price": "20.00", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": 1.5, "subtotal": 1.5 } ], "meta": [ { "key": "pa_color", "label": "Color", "value": "Black" } ] } ], "tax_lines": [ { "id": 21, "rate_code": "US-CA-STATE TAX", "rate_id": "75", "label": "State Tax", "compound": false, "tax_total": "1.95", "shipping_tax_total": "0.00" } ], "shipping_lines": [ { "id": 20, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/154" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|-------------------------------------------------------------------------| | `force` | boolean | Use `true` to permanently delete the order. Default is `false`. | ## Batch update orders This API helps you to batch create, update and delete multiple orders. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v1/orders/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/orders/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 79, "quantity": 1 }, { "product_id": 93, "quantity": 1 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "30.00" } ] }, { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": true, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 22, "variation_id": 23, "quantity": 1 }, { "product_id": 22, "variation_id": 24, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "20.00" } ] } ], "update": [ { "id": 154, "shipping_methods": "Local Delivery" } ], "delete": [ 154 ] }' ``` ```javascript const data = { create: [ { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 79, quantity: 1 }, { product_id: 93, quantity: 1 }, { product_id: 22, variation_id: 23, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "30.00" } ] }, { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", set_paid: true, billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 22, variation_id: 23, quantity: 1 }, { product_id: 22, variation_id: 24, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "20.00" } ] } ], update: [ { id: 154, shipping_methods: "Local Delivery" } ], delete: [ 154 ] }; WooCommerce.post("orders/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'payment_method' => 'bacs', 'payment_method_title' => 'Direct Bank Transfer', 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ], 'line_items' => [ [ 'product_id' => 79, 'quantity' => 1 ], [ 'product_id' => 93, 'quantity' => 1 ], [ 'product_id' => 22, 'variation_id' => 23, 'quantity' => 1 ] ], 'shipping_lines' => [ [ 'method_id' => 'flat_rate', 'method_title' => 'Flat Rate', 'total' => '30.00' ] ] ], [ 'payment_method' => 'bacs', 'payment_method_title' => 'Direct Bank Transfer', 'set_paid' => true, 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ], 'line_items' => [ [ 'product_id' => 22, 'variation_id' => 23, 'quantity' => 1 ], [ 'product_id' => 22, 'variation_id' => 24, 'quantity' => 1 ] ], 'shipping_lines' => [ [ 'method_id' => 'flat_rate', 'method_title' => 'Flat Rate', 'total' => '20.00' ] ] ] ], 'update' => [ [ 'id' => 154, 'shipping_methods' => 'Local Delivery' ] ], 'delete' => [ 154 ] ]; print_r($woocommerce->post('orders/batch', $data)); ?> ``` ```python data = { "create": [ { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 79, "quantity": 1 }, { "product_id": 93, "quantity": 1 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "30.00" } ] }, { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": True, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 22, "variation_id": 23, "quantity": 1 }, { "product_id": 22, "variation_id": 24, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "20.00" } ] } ], "update": [ { "id": 154, "shipping_methods": "Local Delivery" } ], "delete": [ 154 ] } print(wcapi.post("orders/batch", data).json()) ``` ```ruby data = { create: [ { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 79, quantity: 1 }, { product_id: 93, quantity: 1 }, { product_id: 22, variation_id: 23, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "30.00" } ] }, { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", set_paid: true, billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 22, variation_id: 23, quantity: 1 }, { product_id: 22, variation_id: 24, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "20.00" } ] } ], update: [ { id: 154, shipping_methods: "Local Delivery" } ], delete: [ 154 ] } woocommerce.post("orders/batch", data).parsed_response ``` ```json { "create": [ { "id": 155, "parent_id": 0, "status": "pending", "order_key": "wc_order_574cc9541cea3", "number": "155", "currency": "USD", "version": "2.6.0", "prices_include_tax": false, "date_created": "2016-05-30T23:14:28", "date_modified": "2016-05-30T23:14:28", "customer_id": 0, "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "30.00", "shipping_tax": "0.00", "cart_tax": "2.85", "total": "70.85", "total_tax": "2.85", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "bacs", "transaction_id": "", "customer_ip_address": "127.0.0.1", "customer_user_agent": "curl/7.47.0", "created_via": "rest-api", "customer_note": "", "date_completed": "2016-05-30T20:14:28", "date_paid": "", "cart_hash": "", "line_items": [ { "id": 22, "name": "Woo Logo", "sku": "", "product_id": 79, "variation_id": 0, "quantity": 1, "tax_class": "", "price": "15.00", "subtotal": "15.00", "subtotal_tax": "1.13", "total": "15.00", "total_tax": "1.13", "taxes": [ { "id": 75, "total": 1.125, "subtotal": 1.125 } ], "meta": [] }, { "id": 23, "name": "Woo Single #1", "sku": "", "product_id": 93, "variation_id": 0, "quantity": 1, "tax_class": "", "price": "3.00", "subtotal": "3.00", "subtotal_tax": "0.23", "total": "3.00", "total_tax": "0.23", "taxes": [ { "id": 75, "total": 0.225, "subtotal": 0.225 } ], "meta": [] }, { "id": 24, "name": "Ship Your Idea", "sku": "", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "price": "20.00", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": 1.5, "subtotal": 1.5 } ], "meta": [ { "key": "pa_color", "label": "Color", "value": "Black" } ] } ], "tax_lines": [ { "id": 26, "rate_code": "US-CA-STATE TAX", "rate_id": "75", "label": "State Tax", "compound": false, "tax_total": "2.85", "shipping_tax_total": "0.00" } ], "shipping_lines": [ { "id": 25, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "30.00", "total_tax": "0.00", "taxes": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/155" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders" } ] } }, { "id": 156, "parent_id": 0, "status": "processing", "order_key": "wc_order_574cc95465214", "number": "156", "currency": "USD", "version": "2.6.0", "prices_include_tax": false, "date_created": "2016-05-30T23:14:28", "date_modified": "2016-05-30T23:14:28", "customer_id": 0, "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "20.00", "shipping_tax": "0.00", "cart_tax": "3.00", "total": "63.00", "total_tax": "3.00", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "bacs", "transaction_id": "", "customer_ip_address": "127.0.0.1", "customer_user_agent": "curl/7.47.0", "created_via": "rest-api", "customer_note": "", "date_completed": "2016-05-30T20:14:28", "date_paid": "2016-05-30 20:14:37", "cart_hash": "", "line_items": [ { "id": 27, "name": "Ship Your Idea", "sku": "", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "price": "20.00", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": 1.5, "subtotal": 1.5 } ], "meta": [ { "key": "pa_color", "label": "Color", "value": "Black" } ] }, { "id": 28, "name": "Ship Your Idea", "sku": "", "product_id": 22, "variation_id": 24, "quantity": 1, "tax_class": "", "price": "20.00", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": 1.5, "subtotal": 1.5 } ], "meta": [ { "key": "pa_color", "label": "Color", "value": "Green" } ] } ], "tax_lines": [ { "id": 30, "rate_code": "US-CA-STATE TAX", "rate_id": "75", "label": "State Tax", "compound": false, "tax_total": "3.00", "shipping_tax_total": "0.00" } ], "shipping_lines": [ { "id": 29, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "20.00", "total_tax": "0.00", "taxes": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/156" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders" } ] } } ], "update": [ { "id": 154, "parent_id": 0, "status": "completed", "order_key": "wc_order_574cc02467274", "number": "154", "currency": "USD", "version": "2.6.0", "prices_include_tax": false, "date_created": "2016-05-30T22:35:16", "date_modified": "2016-05-30T22:55:19", "customer_id": 0, "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.95", "total": "37.95", "total_tax": "1.95", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "bacs", "transaction_id": "", "customer_ip_address": "127.0.0.1", "customer_user_agent": "curl/7.47.0", "created_via": "rest-api", "customer_note": "", "date_completed": "2016-05-30T19:47:46", "date_paid": "2016-05-30 19:35:25", "cart_hash": "", "line_items": [ { "id": 18, "name": "Woo Single #1", "sku": "", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "price": "3.00", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": 0.45, "subtotal": 0.45 } ], "meta": [] }, { "id": 19, "name": "Ship Your Idea", "sku": "", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "price": "20.00", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": 1.5, "subtotal": 1.5 } ], "meta": [ { "key": "pa_color", "label": "Color", "value": "Black" } ] } ], "tax_lines": [ { "id": 21, "rate_code": "US-CA-STATE TAX", "rate_id": "75", "label": "State Tax", "compound": false, "tax_total": "1.95", "shipping_tax_total": "0.00" } ], "shipping_lines": [ { "id": 20, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/154" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders" } ] } } ], "delete": [ { "id": 154, "parent_id": 0, "status": "completed", "order_key": "wc_order_574cc02467274", "number": "154", "currency": "USD", "version": "2.6.0", "prices_include_tax": false, "date_created": "2016-05-30T22:35:16", "date_modified": "2016-05-30T22:55:19", "customer_id": 0, "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.95", "total": "37.95", "total_tax": "1.95", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "bacs", "transaction_id": "", "customer_ip_address": "127.0.0.1", "customer_user_agent": "curl/7.47.0", "created_via": "rest-api", "customer_note": "", "date_completed": "2016-05-30T19:47:46", "date_paid": "2016-05-30 19:35:25", "cart_hash": "", "line_items": [ { "id": 18, "name": "Woo Single #1", "sku": "", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "price": "3.00", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": 0.45, "subtotal": 0.45 } ], "meta": [] }, { "id": 19, "name": "Ship Your Idea", "sku": "", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "price": "20.00", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": 1.5, "subtotal": 1.5 } ], "meta": [ { "key": "pa_color", "label": "Color", "value": "Black" } ] } ], "tax_lines": [ { "id": 21, "rate_code": "US-CA-STATE TAX", "rate_id": "75", "label": "State Tax", "compound": false, "tax_total": "1.95", "shipping_tax_total": "0.00" } ], "shipping_lines": [ { "id": 20, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/orders/154" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/orders" } ] } } ] } ``` --- ## Product attribute terms *Source: apis/rest-api/v1/product-attribute-terms.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product attribute terms The product attribute terms API allows you to create, view, update, and delete individual, or a batch, of attribute terms. ## Attribute term properties | Attribute | Type | Description | |---------------|---------|------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Term name. `REQUIRED` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `description` | string | HTML description of the resource. | | `menu_order` | integer | Menu order, used to custom sort the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ## Create an attribute term This API helps you to create a new product attribute term. ```http POST /wp-json/wc/v1/products/attributes//terms ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/products/attributes/2/terms \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "XXS" }' ``` ```javascript const data = { name: "XXS" }; WooCommerce.post("products/attributes/2/terms", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'XXS' ]; print_r($woocommerce->post('products/attributes/2/terms', $data)); ?> ``` ```python data = { "name": "XXS" } print(wcapi.post("products/attributes/2/terms", data).json()) ``` ```ruby data = { name: "XXS" } woocommerce.post("products/attributes/2/terms", data).parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } } ``` ## Retrieve an attribute term This API lets you retrieve a product attribute term by ID. ```http GET /wp-json/wc/v1/products/attributes//terms/ ``` ```shell curl https://example.com/wp-json/wc/v1/products/attributes/2/terms/23 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/attributes/2/terms/23") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/attributes/2/terms/23')); ?> ``` ```python print(wcapi.get("products/attributes/2/terms/23").json()) ``` ```ruby woocommerce.get("products/attributes/2/terms/23").parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } } ``` ## List all attribute terms This API lets you retrieve all terms from a product attribute. ```http GET /wp-json/wc/v1/products/attributes//terms ``` ```shell curl https://example.com/wp-json/wc/v1/products/attributes/2/terms \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/attributes/2/terms") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/attributes/2/terms')); ?> ``` ```python print(wcapi.get("products/attributes/2/terms").json()) ``` ```ruby woocommerce.get("products/attributes/2/terms").parsed_response ``` ```json [ { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } }, { "id": 22, "name": "XS", "slug": "xs", "description": "", "menu_order": 2, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/22" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } }, { "id": 17, "name": "S", "slug": "s", "description": "", "menu_order": 3, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/17" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } }, { "id": 18, "name": "M", "slug": "m", "description": "", "menu_order": 4, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/18" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } }, { "id": 19, "name": "L", "slug": "l", "description": "", "menu_order": 5, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/19" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } }, { "id": 20, "name": "XL", "slug": "xl", "description": "", "menu_order": 6, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/20" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } }, { "id": 21, "name": "XXL", "slug": "xxl", "description": "", "menu_order": 7, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/21" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |--------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `search` | string | Limit results to those matching a string. | | `exclude` | string | Ensure result set excludes specific ids. | | `include` | string | Limit result set to specific ids. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `name`. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. | | `hide_empty` | bool | Whether to hide resources not assigned to any products. Default is `false`. | | `parent` | integer | Limit result set to resources assigned to a specific parent. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update an attribute term This API lets you make changes to a product attribute term. ```http PUT /wp-json/wc/v1/products/attributes//terms/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v1/products/attributes/2/terms/23 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "XXS" }' ``` ```javascript const data = { name: "XXS" }; WooCommerce.put("products/attributes/2/terms/23", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'XXS' ]; print_r($woocommerce->put('products/attributes/2/terms/23', $data)); ?> ``` ```python data = { "name": "XXS" } print(wcapi.put("products/attributes/2/terms/23", data).json()) ``` ```ruby data = { name: "XXS" } woocommerce.put("products/attributes/2/terms/23", data).parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } } ``` ## Delete an attribute term This API helps you delete a product attribute term. ```http DELETE /wp-json/wc/v1/products/attributes//terms/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/products/attributes/2/terms/23?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/attributes/2/terms/23", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/attributes/2/terms/23', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/attributes/2/terms/23", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/attributes/2/terms/23", force: true).parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update attribute terms This API helps you to batch create, update and delete multiple product attribute terms. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v1/products/attributes//terms/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/products/attributes//terms/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "XXS" }, { "name": "S" } ], "update": [ { "id": 19, "menu_order": 6 } ], "delete": [ 21, 20 ] }' ``` ```javascript const data = { create: [ { name: "XXS" }, { name: "S" } ], update: [ { id: 19, menu_order: 6 } ], delete: [ 21, 20 ] }; WooCommerce.post("products/attributes/2/terms/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'XXS' ], [ 'name' => 'S' ] ], 'update' => [ [ 'id' => 19, 'menu_order' => 6 ] ], 'delete' => [ 21, 20 ] ]; print_r($woocommerce->post('products/attributes/2/terms/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "XXS" }, { "name": "S" } ], "update": [ { "id": 19, "menu_order": 6 } ], "delete": [ 21, 20 ] } print(wcapi.post("products/attributes/2/terms/batch", data).json()) ``` ```ruby data = { create: [ { name: "XXS" }, { name: "S" } ], update: [ { id: 19, menu_order: 6 } ], delete: [ 21, 20 ] } woocommerce.post("products/attributes/2/terms/batch", data).parsed_response ``` ```json { "create": [ { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } }, { "id": 17, "name": "S", "slug": "s", "description": "", "menu_order": 3, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/17" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } } ], "update": [ { "id": 19, "name": "L", "slug": "l", "description": "", "menu_order": 5, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/19" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } } ], "delete": [ { "id": 21, "name": "XXL", "slug": "xxl", "description": "", "menu_order": 7, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/21" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } }, { "id": 20, "name": "XL", "slug": "xl", "description": "", "menu_order": 6, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms/20" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2/terms" } ] } } ] } ``` --- ## Product attributes *Source: apis/rest-api/v1/product-attributes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product attributes The product attributes API allows you to create, view, update, and delete individual, or a batch, of product attributes. ## Product attribute properties | Attribute | Type | Description | |----------------|---------|-----------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Attribute name. `REQUIRED` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `type` | string | Type of attribute. Default is `select`. Options: `select` and `text` (some plugins can include new types) | | `order_by` | string | Default sort order. Default is `menu_order`. Options: `menu_order`, `name`, `name_num` and `id`. | | `has_archives` | boolean | Enable/Disable attribute archives. Default is `false`. | ## Create a product attribute This API helps you to create a new product attribute. ```http POST /wp-json/wc/v1/products/attributes ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/products/attributes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true }' ``` ```javascript const data = { name: "Color", slug: "pa_color", type: "select", order_by: "menu_order", has_archives: true }; WooCommerce.post("products/attributes", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Color', 'slug' => 'pa_color', 'type' => 'select', 'order_by' => 'menu_order', 'has_archives' => true ]; print_r($woocommerce->post('products/attributes', $data)); ?> ``` ```python data = { "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": True } print(wcapi.post("products/attributes", data).json()) ``` ```ruby data = { name: "Color", slug: "pa_color", type: "select", order_by: "menu_order", has_archives: true } woocommerce.post("products/attributes", data).parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes" } ] } } ``` ## Retrieve a product attribute This API lets you retrieve and view a specific product attribute by ID. ```http GET /wp-json/wc/v1/products/attributes/ ``` ```shell curl https://example.com/wp-json/wc/v1/products/attributes/1 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/attributes/1") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/attributes/1')); ?> ``` ```python print(wcapi.get("products/attributes/1").json()) ``` ```ruby woocommerce.get("products/attributes/1").parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes" } ] } } ``` ## List all product attributes This API helps you to view all the product attributes. ```http GET /wp-json/wc/v1/products/attributes ``` ```shell curl https://example.com/wp-json/wc/v1/products/attributes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/attributes") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/attributes')); ?> ``` ```python print(wcapi.get("products/attributes").json()) ``` ```ruby woocommerce.get("products/attributes").parsed_response ``` ```json [ { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes" } ] } }, { "id": 2, "name": "Size", "slug": "pa_size", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes" } ] } } ] ``` ## Update a product attribute This API lets you make changes to a product attribute. ```http PUT /wp-json/wc/v1/products/attributes/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v1/products/attributes/1 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "order_by": "name" }' ``` ```javascript const data = { order_by: "name" }; WooCommerce.put("products/attributes/1", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'name' ]; print_r($woocommerce->put('products/attributes/1', $data)); ?> ``` ```python data = { "order_by": "name" } print(wcapi.put("products/attributes/1", data).json()) ``` ```ruby data = { order_by: "name" } woocommerce.put("products/attributes/1", data).parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "name", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes" } ] } } ``` ## Delete a product attribute This API helps you delete a product attribute. ```http DELETE /wp-json/wc/v1/products/attributes/ ``` :::warning This also will delete all terms from the selected attribute. ::: ```shell curl -X DELETE https://example.com/wp-json/wc/v1/products/attributes/1?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/attributes/1", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/attributes/1', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/attributes/1", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/attributes/1", force: true).parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update product attributes This API helps you to batch create, update and delete multiple product attributes. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v1/products/attributes/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/products/attributes/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Brand" }, { "name": "Publisher" } ], "update": [ { "id": 2, "order_by": "name" } ], "delete": [ 1 ] }' ``` ```javascript const data = { create: [ { name: "Brand" }, { name: "Publisher" } ], update: [ { id: 2, order_by: "name" } ], delete: [ 1 ] }; WooCommerce.post("products/attributes/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Brand' ], [ 'name' => 'Publisher' ] ], 'update' => [ [ 'id' => 2, 'order_by' => 'name' ] ], 'delete' => [ 1 ] ]; print_r($woocommerce->post('products/attributes/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Brand" }, { "name": "Publisher" } ], "update": [ { "id": 2, "order_by": "name" } ], "delete": [ 1 ] } print(wcapi.post("products/attributes/batch", data).json()) ``` ```ruby data = { create: [ { name: "Round toe" }, { name: "Flat" } ], update: [ { id: 2, order_by: "name" } ], delete: [ 1 ] } woocommerce.post("products/attributes/batch", data).parsed_response ``` ```json { "create": [ { "id": 7, "name": "Brand", "slug": "pa_brand", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/7" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes" } ] } }, { "id": 8, "name": "Publisher", "slug": "pa_publisher", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/8" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes" } ] } } ], "update": [ { "id": 2, "name": "Size", "slug": "pa_size", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes" } ] } } ], "delete": [ { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/attributes" } ] } } ] } ``` --- ## Product categories *Source: apis/rest-api/v1/product-categories.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product categories The product categories API allows you to create, view, update, and delete individual, or a batch, of categories. ## Product category properties | Attribute | Type | Description | |---------------|---------|-----------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Category name. `REQUIRED` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `parent` | integer | The id for the parent of the resource. | | `description` | string | HTML description of the resource. | | `display` | string | Category archive display type. Default is `default`. Options: `default`, `products`, `subcategories` and `both` | | `image` | array | Image data. See [Category Image properties](#category-image-properties) | | `menu_order` | integer | Menu order, used to custom sort the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ### Category Image properties | Attribute | Type | Description | |-----------------|-----------|---------------------------------------------------------------------------------------------------------| | `id` | integer | Image ID (attachment ID). In write-mode used to attach pre-existing images. | | `date_created` | date-time | The date the image was created, in the site's timezone. `READ-ONLY` | | `date_modified` | date-time | The date the image was last modified, in the site's timezone. `READ-ONLY` | | `src` | string | Image URL. In write-mode used to upload new images. | | `title` | string | Image name. | | `alt` | string | Image alternative text. | ## Create a product category This API helps you to create a new product category. ```http POST /wp-json/wc/v1/products/categories ``` > Example of how to create a product category: ```shell curl -X POST https://example.com/wp-json/wc/v1/products/categories \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Clothing", "image": { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" } }' ``` ```javascript const data = { name: "Clothing", image: { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" } }; WooCommerce.post("products/categories", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Clothing', 'image' => [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg' ] ]; print_r($woocommerce->post('products/categories', $data)); ?> ``` ```python data = { "name": "Clothing", "image": { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" } } print(wcapi.post("products/categories", data).json()) ``` ```ruby data = { name: "Clothing", image: { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" } } woocommerce.post("products/categories", data).parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": { "id": 173, "date_created": "2016-05-31T23:51:03", "date_modified": "2016-05-31T23:51:03", "src": "https://example/wp-content/uploads/2016/05/T_3_front-1.jpg", "title": "", "alt": "" }, "menu_order": 0, "count": 18, "_links": { "self": [ { "href": "https://example/wp-json/wc/v1/products/categories/9" } ], "collection": [ { "href": "https://example/wp-json/wc/v1/products/categories" } ] } } ``` ## Retrieve a product category This API lets you retrieve a product category by ID. ```http GET /wp-json/wc/v1/products/categories/ ``` ```shell curl https://example.com/wp-json/wc/v1/products/categories/9 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/categories/9") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/categories/9')); ?> ``` ```python print(wcapi.get("products/categories/9").json()) ``` ```ruby woocommerce.get("products/categories/9").parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": { "id": 173, "date_created": "2016-05-31T23:51:03", "date_modified": "2016-05-31T23:51:03", "src": "https://example/wp-content/uploads/2016/05/T_3_front-1.jpg", "title": "", "alt": "" }, "menu_order": 0, "count": 18, "_links": { "self": [ { "href": "https://example/wp-json/wc/v1/products/categories/9" } ], "collection": [ { "href": "https://example/wp-json/wc/v1/products/categories" } ] } } ``` ## List all product categories This API lets you retrieve all product categories. ```http GET /wp-json/wc/v1/products/categories ``` ```shell curl https://example.com/wp-json/wc/v1/products/categories \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/categories") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/categories')); ?> ``` ```python print(wcapi.get("products/categories").json()) ``` ```ruby woocommerce.get("products/categories").parsed_response ``` ```json [ { "id": 15, "name": "Albums", "slug": "albums", "parent": 11, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 4, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/15" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/11" } ] } }, { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": { "id": 173, "date_created": "2016-05-31T23:51:03", "date_modified": "2016-05-31T23:51:03", "src": "https://example/wp-content/uploads/2016/05/T_3_front-1.jpg", "title": "", "alt": "" }, "menu_order": 0, "count": 18, "_links": { "self": [ { "href": "https://example/wp-json/wc/v1/products/categories/9" } ], "collection": [ { "href": "https://example/wp-json/wc/v1/products/categories" } ] } }, { "id": 10, "name": "Hoodies", "slug": "hoodies", "parent": 9, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 6, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/10" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/9" } ] } }, { "id": 11, "name": "Music", "slug": "music", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 7, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/11" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/categories" } ] } }, { "id": 12, "name": "Posters", "slug": "posters", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 5, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/12" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/categories" } ] } }, { "id": 13, "name": "Singles", "slug": "singles", "parent": 11, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 3, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/13" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/11" } ] } }, { "id": 14, "name": "T-shirts", "slug": "t-shirts", "parent": 9, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 6, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/14" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/9" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |--------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `search` | string | Limit results to those matching a string. | | `exclude` | string | Ensure result set excludes specific ids. | | `include` | string | Limit result set to specific ids. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `name`. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. | | `hide_empty` | bool | Whether to hide resources not assigned to any products. Default is `false`. | | `parent` | integer | Limit result set to resources assigned to a specific parent. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update a product category This API lets you make changes to a product category. ```http PUT /wp-json/wc/v1/products/categories/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v1/products/categories/9 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "description": "All kinds of clothes." }' ``` ```javascript const data = { description: "All kinds of clothes." }; WooCommerce.put("products/categories/9", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'All kinds of clothes.' ]; print_r($woocommerce->put('products/categories/9', $data)); ?> ``` ```python data = { "description": "All kinds of clothes." } print(wcapi.put("products/categories/9", data).json()) ``` ```ruby data = { description: "All kinds of clothes." } woocommerce.put("products/categories/9", data).parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "All kinds of clothes.", "display": "default", "image": { "id": 173, "date_created": "2016-05-31T23:51:03", "date_modified": "2016-05-31T23:51:03", "src": "https://example/wp-content/uploads/2016/05/T_3_front-1.jpg", "title": "", "alt": "" }, "menu_order": 0, "count": 18, "_links": { "self": [ { "href": "https://example/wp-json/wc/v1/products/categories/9" } ], "collection": [ { "href": "https://example/wp-json/wc/v1/products/categories" } ] } } ``` ## Delete a product category This API helps you delete a product category. ```http DELETE /wp-json/wc/v1/products/categories/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/products/categories/9?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/categories/9", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/categories/9', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/categories/9", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/categories/9", force: true).parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "All kinds of clothes.", "display": "default", "image": { "id": 173, "date_created": "2016-05-31T23:51:03", "date_modified": "2016-05-31T23:51:03", "src": "https://example/wp-content/uploads/2016/05/T_3_front-1.jpg", "title": "", "alt": "" }, "menu_order": 0, "count": 18, "_links": { "self": [ { "href": "https://example/wp-json/wc/v1/products/categories/9" } ], "collection": [ { "href": "https://example/wp-json/wc/v1/products/categories" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update product categories This API helps you to batch create, update and delete multiple product categories. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v1/products/categories/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/products/categories/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Albums" }, { "name": "Clothing" } ], "update": [ { "id": 10, "description": "Nice hoodies" } ], "delete": [ 11, 12 ] }' ``` ```javascript const data = { create: [ { name: "Albums" }, { name: "Clothing" } ], update: [ { id: 10, description: "Nice hoodies" } ], delete: [ 11, 12 ] }; WooCommerce.post("products/categories/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Albums' ], [ 'name' => 'Clothing' ] ], 'update' => [ [ 'id' => 10, 'description' => 'Nice hoodies' ] ], 'delete' => [ 11, 12 ] ]; print_r($woocommerce->post('products/categories/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Albums" }, { "name": "Clothing" } ], "update": [ { "id": 10, "description": "Nice hoodies" } ], "delete": [ 11, 12 ] } print(wcapi.post("products/categories/batch", data).json()) ``` ```ruby data = { create: [ { name: "Albums" }, { name: "Clothing" } ], update: [ { id: 10, description: "Nice hoodies" } ], delete: [ 11, 12 ] } woocommerce.post("products/categories/batch", data).parsed_response ``` ```json { "create": [ { "id": 15, "name": "Albums", "slug": "albums", "parent": 11, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/15" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/11" } ] } }, { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/categories" } ] } } ], "update": [ { "id": 10, "name": "Hoodies", "slug": "hoodies", "parent": 9, "description": "Nice hoodies", "display": "default", "image": [], "menu_order": 0, "count": 6, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/10" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/9" } ] } } ], "delete": [ { "id": 11, "name": "Music", "slug": "music", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 7, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/11" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/categories" } ] } }, { "id": 12, "name": "Posters", "slug": "posters", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 5, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/categories/12" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/categories" } ] } } ] } ``` --- ## Product shipping classes *Source: apis/rest-api/v1/product-shipping-classes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product shipping classes The product shipping class API allows you to create, view, update, and delete individual, or a batch, of shipping classes. ## Shipping class properties | Attribute | Type | Description | |---------------|---------|------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Shipping class name. `REQUIRED` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `description` | string | HTML description of the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ## Create a shipping class This API helps you to create a new product shipping class. ```http POST /wp-json/wc/v1/products/shipping_classes ``` > Example of how to create a product shipping class: ```shell curl -X POST https://example.com/wp-json/wc/v1/products/shipping_classes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Priority" }' ``` ```javascript const data = { name: "Priority" }; WooCommerce.post("products/shipping_classes", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Priority' ]; print_r($woocommerce->post('products/shipping_classes', $data)); ?> ``` ```python data = { "name": "Priority" } print(wcapi.post("products/shipping_classes", data).json()) ``` ```ruby data = { name: "Priority" } woocommerce.post("products/shipping_classes", data).parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes" } ] } } ``` ## Retrieve a shipping class This API lets you retrieve a product shipping class by ID. ```http GET /wp-json/wc/v1/products/shipping_classes/ ``` ```shell curl https://example.com/wp-json/wc/v1/products/shipping_classes/32 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/shipping_classes/32") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/shipping_classes/32')); ?> ``` ```python print(wcapi.get("products/shipping_classes/32").json()) ``` ```ruby woocommerce.get("products/shipping_classes/32").parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes" } ] } } ``` ## List all shipping classes This API lets you retrieve all product shipping classes. ```http GET /wp-json/wc/v1/products/shipping_classes ``` ```shell curl https://example.com/wp-json/wc/v1/products/shipping_classes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/shipping_classes") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/shipping_classes')); ?> ``` ```python print(wcapi.get("products/shipping_classes").json()) ``` ```ruby woocommerce.get("products/shipping_classes").parsed_response ``` ```json [ { "id": 33, "name": "Express", "slug": "express", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes/33" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes" } ] } }, { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |--------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `search` | string | Limit results to those matching a string. | | `exclude` | string | Ensure result set excludes specific ids. | | `include` | string | Limit result set to specific ids. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `name`. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. | | `hide_empty` | bool | Whether to hide resources not assigned to any products. Default is `false`. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update a shipping class This API lets you make changes to a product shipping class. ```http PUT /wp-json/wc/v1/products/shipping_classes/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v1/products/shipping_classes/32 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "description": "Priority mail." }' ``` ```javascript const data = { description: "Priority mail." }; WooCommerce.put("products/shipping_classes/32", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Priority mail.' ]; print_r($woocommerce->put('products/shipping_classes/32', $data)); ?> ``` ```python data = { "description": "Priority mail." } print(wcapi.put("products/shipping_classes/32", data).json()) ``` ```ruby data = { description: "Priority mail." } woocommerce.put("products/shipping_classes/32", data).parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "Priority mail.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes" } ] } } ``` ## Delete a shipping class This API helps you delete a product shipping class. ```http DELETE /wp-json/wc/v1/products/shipping_classes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/products/shipping_classes/32?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/shipping_classes/32", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/shipping_classes/32', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/shipping_classes/32", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/shipping_classes/32", force: true).parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "Priority mail.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update shipping classes This API helps you to batch create, update and delete multiple product shipping classes. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v1/products/shipping_classes/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/products/shipping_classes/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Small items" }, { "name": "Large items" } ], "update": [ { "id": 33, "description": "Express shipping" } ], "delete": [ 32 ] }' ``` ```javascript const data = { create: [ { name: "Small items" }, { name: "Large items" } ], update: [ { id: 33, description: "Express shipping" } ], delete: [ 32 ] }; WooCommerce.post("products/shipping_classes/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Small items' ], [ 'name' => 'Large items' ] ], 'update' => [ [ 'id' => 33, 'description' => 'Express shipping' ] ], 'delete' => [ 32 ] ]; print_r($woocommerce->post('products/shipping_classes/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Small items" }, { "name": "Large items" } ], "update": [ { "id": 33, "description": "Express shipping" } ], "delete": [ 32 ] } print(wcapi.post("products/shipping_classes/batch", data).json()) ``` ```ruby data = { create: [ { name: "Small items" }, { name: "Large items" } ], update: [ { id: 33, description: "Express shipping" } ], delete: [ 32 ] } woocommerce.post("products/shipping_classes/batch", data).parsed_response ``` ```json { "create": [ { "id": 34, "name": "Small items", "slug": "small-items", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes" } ] } }, { "id": 35, "name": "Large items", "slug": "large-items", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes/35" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes" } ] } } ], "update": [ { "id": 33, "name": "Express", "slug": "express", "description": "Express shipping", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes/33" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes" } ] } } ], "delete": [ { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/shipping_classes" } ] } } ] } ``` --- ## Product tags *Source: apis/rest-api/v1/product-tags.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product tags The product tags API allows you to create, view, update, and delete individual, or a batch, of product tags. ## Product tag properties | Attribute | Type | Description | |---------------|---------|------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Tag name. `REQUIRED` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `description` | string | HTML description of the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ## Create a product tag This API helps you to create a new product tag. ```http POST /wp-json/wc/v1/products/tags ``` > Example of how to create a product tag: ```shell curl -X POST https://example.com/wp-json/wc/v1/products/tags \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Leather Shoes" }' ``` ```javascript const data = { name: "Leather Shoes" }; WooCommerce.post("products/tags", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Leather Shoes' ]; print_r($woocommerce->post('products/tags', $data)); ?> ``` ```python data = { "name": "Leather Shoes" } print(wcapi.post("products/tags", data).json()) ``` ```ruby data = { name: "Leather Shoes" } woocommerce.post("products/tags", data).parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/tags" } ] } } ``` ## Retrieve a product tag This API lets you retrieve a product tag by ID. ```http GET /wp-json/wc/v1/products/tags/ ``` ```shell curl https://example.com/wp-json/wc/v1/products/tags/34 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/tags/34") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/tags/34')); ?> ``` ```python print(wcapi.get("products/tags/34").json()) ``` ```ruby woocommerce.get("products/tags/34").parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/tags" } ] } } ``` ## List all product tags This API lets you retrieve all product tag. ```http GET /wp-json/wc/v1/products/tags ``` ```shell curl https://example.com/wp-json/wc/v1/products/tags \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/tags") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/tags')); ?> ``` ```python print(wcapi.get("products/tags").json()) ``` ```ruby woocommerce.get("products/tags").parsed_response ``` ```json [ { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/tags" } ] } }, { "id": 35, "name": "Oxford Shoes", "slug": "oxford-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/tags/35" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/tags" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |--------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `search` | string | Limit results to those matching a string. | | `exclude` | string | Ensure result set excludes specific ids. | | `include` | string | Limit result set to specific ids. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `name`. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. | | `hide_empty` | bool | Whether to hide resources not assigned to any products. Default is `false`. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update a product tag This API lets you make changes to a product tag. ```http PUT /wp-json/wc/v1/products/tags/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v1/products/tags/34 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "description": "Genuine leather." }' ``` ```javascript const data = { description: "Genuine leather." }; WooCommerce.put("products/tags/34", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Genuine leather.' ]; print_r($woocommerce->put('products/tags/34', $data)); ?> ``` ```python data = { "description": "Genuine leather." } print(wcapi.put("products/tags/34", data).json()) ``` ```ruby data = { description: "Genuine leather." } woocommerce.put("products/tags/34", data).parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "Genuine leather.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/tags" } ] } } ``` ## Delete a product tag This API helps you delete a product tag. ```http DELETE /wp-json/wc/v1/products/tags/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/products/tags/34?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/tags/34", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/tags/34', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/tags/34", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/tags/34", force: true).parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "Genuine leather.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/tags" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update product tags This API helps you to batch create, update and delete multiple product tags. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v1/products/tags/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/products/tags/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Round toe" }, { "name": "Flat" } ], "update": [ { "id": 34, "description": "Genuine leather." } ], "delete": [ 35 ] }' ``` ```javascript const data = { create: [ { name: "Round toe" }, { name: "Flat" } ], update: [ { id: 34, description: "Genuine leather." } ], delete: [ 35 ] }; WooCommerce.post("products/tags/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Round toe' ], [ 'name' => 'Flat' ] ], 'update' => [ [ 'id' => 34, 'description' => 'Genuine leather.' ] ], 'delete' => [ 35 ] ]; print_r($woocommerce->post('products/tags/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Round toe" }, { "name": "Flat" } ], "update": [ { "id": 34, "description": "Genuine leather." } ], "delete": [ 35 ] } print(wcapi.post("products/tags/batch", data).json()) ``` ```ruby data = { create: [ { name: "Round toe" }, { name: "Flat" } ], update: [ { id: 34, description: "Genuine leather." } ], delete: [ 35 ] } woocommerce.post("products/tags/batch", data).parsed_response ``` ```json { "create": [ { "id": 36, "name": "Round toe", "slug": "round-toe", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/tags/36" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/tags" } ] } }, { "id": 37, "name": "Flat", "slug": "flat", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/tags/37" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/tags" } ] } } ], "update": [ { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "Genuine leather.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/tags" } ] } } ], "delete": [ { "id": 35, "name": "Oxford Shoes", "slug": "oxford-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/tags/35" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/tags" } ] } } ] } ``` --- ## Products *Source: apis/rest-api/v1/products.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Products The products API allows you to create, view, update, and delete individual, or a batch, of products. ## Product properties | Attribute | Type | Description | |----------------------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Product name. | | `slug` | string | Product slug. | | `permalink` | string | Product URL. `READ-ONLY` | | `date_created` | date-time | The date the product was created, in the site's timezone. `READ-ONLY` | | `date_modified` | date-time | The date the product was last modified, in the site's timezone. `READ-ONLY` | | `type` | string | Product type. Default is `simple`. Options (plugins may add new options): `simple`, `grouped`, `external`, `variable`. | | `status` | string | Product status (post status). Default is `publish`. Options (plugins may add new options): `draft`, `pending`, `private` and `publish`. | | `featured` | boolean | Featured product. Default is `false`. | | `catalog_visibility` | string | Catalog visibility. Default is `visible`. Options: `visible` (Catalog and search), `catalog` (Only in catalog), `search` (Only in search) and `hidden` (Hidden from all). | | `description` | string | Product description. | | `short_description` | string | Product short description. | | `sku` | string | Unique identifier. | | `price` | string | Current product price. This is setted from `regular_price` and `sale_price`. `READ-ONLY` | | `regular_price` | string | Product regular price. | | `sale_price` | string | Product sale price. | | `date_on_sale_from` | string | Start date of sale price. Date in the `YYYY-MM-DD` format. | | `date_on_sale_to` | string | Sets the sale end date. Date in the `YYYY-MM-DD` format. | | `price_html` | string | Price formatted in HTML, e.g. `$ 3.00 $ 2.00` `READ-ONLY` | | `on_sale` | boolean | Shows if the product is on sale. `READ-ONLY` | | `purchasable` | boolean | Shows if the product can be bought. `READ-ONLY` | | `total_sales` | integer | Amount of sales. `READ-ONLY` | | `virtual` | boolean | If the product is virtual. Virtual products are intangible and aren't shipped. Default is `false`. | | `downloadable` | boolean | If the product is downloadable. Downloadable products give access to a file upon purchase. Default is `false`. | | `downloads` | array | List of downloadable files. See [Downloads properties](#download-properties). | | `download_limit` | integer | Amount of times the product can be downloaded, the `-1` values means **unlimited re-downloads**. Default is `-1`. | | `download_expiry` | integer | Number of days that the customer has up to be able to download the product, the `-1` means that **downloads never expires**. Default is `-1`. | | `download_type` | string | Download type, this controls the [schema](http://schema.org/) on the front-end. Default is `standard`. Options: `'standard'` (Standard Product), `application` (Application/Software) and `music` (Music). | | `external_url` | string | Product external URL. Only for `external` products. | | `button_text` | string | Product external button text. Only for `external` products. | | `tax_status` | string | Tax status. Default is `taxable`. Options: `taxable`, `shipping` (Shipping only) and `none`. | | `tax_class` | string | Tax class. | | `manage_stock` | boolean | Stock management at product level. Default is `false`. | | `stock_quantity` | integer | Stock quantity. If is a variable product this value will be used to control stock for all variations, unless you define stock at variation level. | | `in_stock` | boolean | Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend. Default is `true`. | | `backorders` | string | If managing stock, this controls if backorders are allowed. If enabled, stock quantity can go below `0`. Default is `no`. Options are: `no` (Do not allow), `notify` (Allow, but notify customer), and `yes` (Allow). | | `backorders_allowed` | boolean | Shows if backorders are allowed. `READ-ONLY` | | `backordered` | boolean | Shows if a product is on backorder (if the product have the `stock_quantity` negative). `READ-ONLY` | | `sold_individually` | boolean | Allow one item to be bought in a single order. Default is `false`. | | `weight` | string | Product weight in decimal format. | | `dimensions` | object | Product dimensions. See [Dimensions properties](#dimension-properties). | | `shipping_required` | boolean | Shows if the product need to be shipped. `READ-ONLY` | | `shipping_taxable` | boolean | Shows whether or not the product shipping is taxable. `READ-ONLY` | | `shipping_class` | string | Shipping class slug. Shipping classes are used by certain shipping methods to group similar products. | | `shipping_class_id` | integer | Shipping class ID. `READ-ONLY` | | `reviews_allowed` | boolean | Allow reviews. Default is `true`. | | `average_rating` | string | Reviews average rating. `READ-ONLY` | | `rating_count` | integer | Amount of reviews that the product have. `READ-ONLY` | | `related_ids` | array | List of related products IDs (`integer`). `READ-ONLY` | | `upsell_ids` | array | List of up-sell products IDs (`integer`). Up-sells are products which you recommend instead of the currently viewed product, for example, products that are more profitable or better quality or more expensive. | | `cross_sell_ids` | array | List of cross-sell products IDs. Cross-sells are products which you promote in the cart, based on the current product. | | `parent_id` | integer | Product parent ID (`post_parent`). | | `purchase_note` | string | Optional note to send the customer after purchase. | | `categories` | array | List of categories. See [Categories properties](#category-properties). | | `tags` | array | List of tags. See [Tags properties](#tag-properties). | | `images` | array | List of images. See [Images properties](#image-properties) | | `attributes` | array | List of attributes. See [Attributes properties](#attribute-properties). | | `default_attributes` | array | Defaults variation attributes, used only for variations and pre-selected attributes on the frontend. See [Default Attributes properties](#default-attribute-properties). | | `variations` | array | List of variations. See [Variations properties](#variation-properties) | | `grouped_products` | array | List of grouped products ID, only for `group` type products. `READ-ONLY` | | `menu_order` | integer | Menu order, used to custom sort products. | ### Download properties | Attribute | Type | Description | |-----------|--------|----------------------------------------------------------------------| | `id` | string | File ID. | | `name` | string | File name. | | `file` | string | File URL. In write-mode you can use this property to send new files. | ### Dimension properties | Attribute | Type | Description | |-----------|--------|-----------------------------------| | `length` | string | Product length in decimal format. | | `width` | string | Product width in decimal format. | | `height` | string | Product height in decimal format. | ### Category properties | Attribute | Type | Description | |-----------|---------|----------------------------------------------------------| | `id` | integer | Category ID. | | `name` | string | Category name. `READ-ONLY` | | `slug` | string | Category slug. `READ-ONLY` | ### Tag properties | Attribute | Type | Description | |-----------|---------|-----------------------------------------------------| | `id` | integer | Tag ID. | | `name` | string | Tag name. `READ-ONLY` | | `slug` | string | Tag slug. `READ-ONLY` | ### Image properties | Attribute | Type | Description | |-----------------|-----------|---------------------------------------------------------------------------------------------------------| | `id` | integer | Image ID (attachment ID). In write-mode used to attach pre-existing images. | | `date_created` | date-time | The date the image was created, in the site's timezone. `READ-ONLY` | | `date_modified` | date-time | The date the image was last modified, in the site's timezone. `READ-ONLY` | | `src` | string | Image URL. In write-mode used to upload new images. | | `name` | string | Image name. | | `alt` | string | Image alternative text. | | `position` | integer | Image position. `0` means that the image is featured. | ### Attribute properties | Attribute | Type | Description | |-------------|---------|-------------------------------------------------------------------------------------------------------------------| | `id` | integer | Attribute ID (required if is a global attribute). | | `name` | string | Attribute name (required if is a non-global attribute). | | `position` | integer | Attribute position. | | `visible` | boolean | Define if the attribute is visible on the "Additional Information" tab in the product's page. Default is `false`. | | `variation` | boolean | Define if the attribute can be used as variation. Default is `false`. | | `options` | array | List of available term names of the attribute. | ### Default attribute properties | Attribute | Type | Description | |-----------|---------|---------------------------------------------------------| | `id` | integer | Attribute ID (required if is a global attribute). | | `name` | string | Attribute name (required if is a non-global attribute). | | `option` | string | Selected attribute term name. | ### Variation properties | Attribute | Type | Description | |----------------------|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Variation ID. `READ-ONLY` | | `date_created` | date-time | The date the variation was created, in the site's timezone. `READ-ONLY` | | `date_modified` | date-time | The date the variation was last modified, in the site's timezone. `READ-ONLY` | | `permalink` | string | Variation URL. `READ-ONLY` | | `sku` | string | Unique identifier. | | `price` | string | Current variation price. This is setted from `regular_price` and `sale_price`. `READ-ONLY` | | `regular_price` | string | Variation regular price. | | `sale_price` | string | Variation sale price. | | `date_on_sale_from` | string | Start date of sale price. Date in the `YYYY-MM-DD` format. | | `date_on_sale_to` | string | Start date of sale price. Date in the `YYYY-MM-DD` format. | | `on_sale` | boolean | Shows if the variation is on sale. `READ-ONLY` | | `purchasable` | boolean | Shows if the variation can be bought. `READ-ONLY` | | `visible` | boolean | If the variation is visible. | | `virtual` | boolean | If the variation is virtual. Virtual variations are intangible and aren't shipped. Default is `false`. | | `downloadable` | boolean | If the variation is downloadable. Downloadable variations give access to a file upon purchase. Default is `false`. | | `downloads` | array | List of downloadable files. See [Downloads properties](#download-properties). | | `download_limit` | integer | Amount of times the variation can be downloaded, the `-1` values means **unlimited re-downloads**. Default is `-1`. | | `download_expiry` | integer | Number of days that the customer has up to be able to download the variation, the `-1` means that **downloads never expires**. Default is `-1`. | | `tax_status` | string | Tax status. Default is `taxable`. Options: `taxable`, `shipping` (Shipping only) and `none`. | | `tax_class` | string | Tax class. | | `manage_stock` | boolean, string | Stock management at variation level. Possible values are either a boolean or `parent`. Default is `false`. | | `stock_quantity` | integer | Stock quantity. If is a variable variation this value will be used to control stock for all variations, unless you define stock at variation level. | | `in_stock` | boolean | Controls whether or not the variation is listed as "in stock" or "out of stock" on the frontend. Default is `true`. | | `backorders` | string | If managing stock, this controls if backorders are allowed. If enabled, stock quantity can go below `0`. Default is `no`. Options are: `no` (Do not allow), `notify` (Allow, but notify customer), and `yes` (Allow). | | `backorders_allowed` | boolean | Shows if backorders are allowed." `READ-ONLY` | | `backordered` | boolean | Shows if a variation is on backorder (if the variation have the `stock_quantity` negative). `READ-ONLY` | | `weight` | string | Variation weight in decimal format. | | `dimensions` | object | Variation dimensions. See [Dimensions properties](#dimension-properties). | | `shipping_class` | string | Shipping class slug. Shipping classes are used by certain shipping methods to group similar products. | | `shipping_class_id` | integer | Shipping class ID. `READ-ONLY` | | `image` | array | Variation featured image. Only position `0` will be used. See [Images properties](#image-properties). | | `attributes` | array | List of variation attributes. See [Variation Attributes properties](#variation-attribute-properties) | ### Variation attribute properties | Attribute | Type | Description | |-----------|---------|---------------------------------------------------------| | `id` | integer | Attribute ID (required if is a global attribute). | | `name` | string | Attribute name (required if is a non-global attribute). | | `option` | string | Selected attribute term name. | ## Create a product This API helps you to create a new product. ```http POST /wp-json/wc/v1/products ``` > Example of how to create a `simple` product: ```shell curl -X POST https://example.com/wp-json/wc/v1/products \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", "position": 1 } ] }' ``` ```javascript const data = { name: "Premium Quality", type: "simple", regular_price: "21.99", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", position: 1 } ] }; WooCommerce.post("products", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Premium Quality', 'type' => 'simple', 'regular_price' => '21.99', 'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', 'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'categories' => [ [ 'id' => 9 ], [ 'id' => 14 ] ], 'images' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg', 'position' => 0 ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg', 'position' => 1 ] ] ]; print_r($woocommerce->post('products', $data)); ?> ``` ```python data = { "name": "Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", "position": 1 } ] } print(wcapi.post("products", data).json()) ``` ```ruby data = { name: "Premium Quality", type: "simple", regular_price: "21.99", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", position: 1 } ] } woocommerce.post("products", data).parsed_response ``` ```json { "id": 162, "name": "Premium Quality", "slug": "premium-quality-3", "permalink": "https://example.com/product/premium-quality-3/", "date_created": "2016-05-31T23:40:07", "date_modified": "2016-05-31T23:40:07", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "price_html": "R$21,99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "download_type": "standard", "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 163, "date_created": "2016-05-31T23:40:07", "date_modified": "2016-05-31T23:40:07", "src": "https://example.com/wp-content/uploads/2016/05/T_2_front.jpg", "name": "", "alt": "", "position": 0 }, { "id": 164, "date_created": "2016-05-31T23:40:10", "date_modified": "2016-05-31T23:40:10", "src": "https://example.com/wp-content/uploads/2016/05/T_2_back.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/162" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products" } ] } } ```
> Example of how to create a `variable` product with global and non-global attributes: ```shell curl -X POST https://example.com/wp-json/wc/v1/products \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Ship Your Idea", "type": "variable", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg", "position": 1 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", "position": 2 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg", "position": 3 } ], "attributes": [ { "id": 6, "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "name": "Size", "position": 0, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "option": "Black" }, { "name": "Size", "option": "S" } ], "variations": [ { "regular_price": "19.99", "image": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", "position": 0 } ], "attributes": [ { "id": 6, "option": "black" }, { "name": "Size", "option": "S" } ] }, { "regular_price": "19.99", "image": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", "position": 0 } ], "attributes": [ { "id": 6, "option": "green" }, { "name": "Size", "option": "M" } ] } ] }' ``` ```javascript const data = { name: "Ship Your Idea", type: "variable", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg", position: 1 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", position: 2 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg", position: 3 } ], attributes: [ { id: 6, position: 0, visible: true, variation: true, options: [ "Black", "Green" ] } { name: "Size", position: 0, visible: false, variation: true, options: [ "S", "M" ] } ], default_attributes: [ { id: 6, option: "Black" }, { name: "Size", option: "S" } ], variations: [ { regular_price: "19.99", image: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", position: 0 } ], attributes: [ { id: 6, option: "black" }, { name: "Size", option: "S" } ] }, { regular_price: "19.99", image: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", position: 0 } ], attributes: [ { id: 6, option: "green" }, { name: "Size", option: "M" } ] } ] }; WooCommerce.post("products", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Ship Your Idea', 'type' => 'variable', 'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', 'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'categories' => [ [ 'id' => 9 ], [ 'id' => 14 ] ], 'images' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg', 'position' => 0 ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg', 'position' => 1 ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg', 'position' => 2 ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg', 'position' => 3 ] ], 'attributes' => [ [ 'id' => 6, 'position' => 0, 'visible' => false, 'variation' => true, 'options' => [ 'Black', 'Green' ] ], [ 'name' => 'Size', 'position' => 0, 'visible' => true, 'variation' => true, 'options' => [ 'S', 'M' ] ] ], 'default_attributes' => [ [ 'id' => 6, 'option' => 'Black' ], [ 'name' => 'Size', 'option' => 'S' ] ], 'variations' => [ [ 'regular_price' => '19.99', 'image' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg', 'position' => 0 ] ], 'attributes' => [ [ 'id' => 6, 'option' => 'black' ], [ 'name' => 'Size', 'option' => 'S' ] ] ], [ 'regular_price' => '19.99', 'image' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg', 'position' => 0 ] ], 'attributes' => [ [ 'id' => 6, 'option' => 'green' ], [ 'name' => 'Size', 'option' => 'M' ] ] ] ] ]; print_r($woocommerce->post('products', $data)); ?> ``` ```python data = { "name": "Ship Your Idea", "type": "variable", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg", "position": 1 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", "position": 2 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg", "position": 3 } ], "attributes": [ { "id": 6, "position": 0, "visible": False, "variation": True, "options": [ "Black", "Green" ] }, { "name": "Size", "position": 0, "visible": True, "variation": True, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "option": "Black" }, { "name": "Size", "option": "S" } ], "variations": [ { "regular_price": "19.99", "image": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", "position": 0 } ], "attributes": [ { "id": 6, "option": "black" }, { "name": "Size", "option": "S" } ] }, { "regular_price": "19.99", "image": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", "position": 0 } ], "attributes": [ { "id": 6, "option": "green" }, { "name": "Size", "option": "M" } ] } ] } print(wcapi.post("products", data).json()) ``` ```ruby data = { name: "Ship Your Idea", type: "variable", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg", position: 1 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", position: 2 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg", position: 3 } ], attributes: [ { id: 6, position: 0, visible: false, variation: true, options: [ "Black", "Green" ] }, { name: "Size", position: 0, visible: true, variation: true, options: [ "S", "M" ] } ], default_attributes: [ { id: 6, option: "Black" }, { name: "Size", option: "S" } ], variations: [ { regular_price: "19.99", image: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", position: 0 } ], attributes: [ { id: 6, option: "black" }, { name: "Size", option: "S" } ] }, { regular_price: "19.99", image: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", position: 0 } ], attributes: [ { id: 6, option: "green" }, { name: "Size", option: "M" } ] } ] } woocommerce.post("products", data).parsed_response ``` ```json { "id": 165, "name": "Ship Your Idea", "slug": "ship-your-idea-4", "permalink": "https://example.com/product/ship-your-idea-4/", "date_created": "2016-05-31T23:50:56", "date_modified": "2016-06-02T23:11:41", "type": "variable", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "19.99", "regular_price": "", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "price_html": "R$19,99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "download_type": "standard", "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 34, 37, 187, 205, 31 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 166, "date_created": "2016-05-31T23:50:57", "date_modified": "2016-05-31T23:50:57", "src": "https://example.com/wp-content/uploads/2016/05/T_4_front.jpg", "name": "", "alt": "", "position": 0 }, { "id": 167, "date_created": "2016-05-31T23:50:57", "date_modified": "2016-05-31T23:50:57", "src": "https://example.com/wp-content/uploads/2016/05/T_4_back.jpg", "name": "", "alt": "", "position": 1 }, { "id": 168, "date_created": "2016-05-31T23:50:58", "date_modified": "2016-05-31T23:50:58", "src": "https://example.com/wp-content/uploads/2016/05/T_3_front.jpg", "name": "", "alt": "", "position": 2 }, { "id": 169, "date_created": "2016-05-31T23:50:59", "date_modified": "2016-05-31T23:50:59", "src": "https://example.com/wp-content/uploads/2016/05/T_3_back.jpg", "name": "", "alt": "", "position": 3 } ], "attributes": [ { "id": 6, "name": "Color", "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "id": 0, "name": "Size", "position": 1, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "name": "Color", "option": "black" }, { "id": 0, "name": "size", "option": "S" } ], "variations": [ { "id": 170, "date_created": "2016-05-31T23:50:56", "date_modified": "2016-06-02T23:11:41", "permalink": "https://example.com/product/ship-your-idea-4/?attribute_pa_color=black&attribute_size=S", "sku": "", "price": "19.99", "regular_price": "19.99", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "on_sale": false, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": [ { "id": 171, "date_created": "2016-05-31T23:51:01", "date_modified": "2016-05-31T23:51:01", "src": "https://example.com/wp-content/uploads/2016/05/T_4_front-1.jpg", "name": "", "alt": "", "position": 0 } ], "attributes": [ { "id": 6, "name": "Color", "option": "black" }, { "id": 0, "name": "size", "option": "S" } ] }, { "id": 172, "date_created": "2016-05-31T23:50:56", "date_modified": "2016-06-02T23:11:41", "permalink": "https://example.com/product/ship-your-idea-4/?attribute_pa_color=green&attribute_size=M", "sku": "", "price": "19.99", "regular_price": "19.99", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "on_sale": false, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": [ { "id": 173, "date_created": "2016-05-31T23:51:03", "date_modified": "2016-05-31T23:51:03", "src": "https://example.com/wp-content/uploads/2016/05/T_3_front-1.jpg", "name": "", "alt": "", "position": 0 } ], "attributes": [ { "id": 6, "name": "Color", "option": "green" }, { "id": 0, "name": "size", "option": "M" } ] } ], "grouped_products": [], "menu_order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/165" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products" } ] } } ```
## Retrieve a product This API lets you retrieve and view a specific product by ID. ```http GET /wp-json/wc/v1/products/ ``` ```shell curl https://example.com/wp-json/wc/v1/products/162 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/162") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/162')); ?> ``` ```python print(wcapi.get("products/162").json()) ``` ```ruby woocommerce.get("products/162").parsed_response ``` ```json { "id": 162, "name": "Premium Quality", "slug": "premium-quality-3", "permalink": "https://example.com/product/premium-quality-3/", "date_created": "2016-05-31T23:40:07", "date_modified": "2016-05-31T23:40:07", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "price_html": "R$21,99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "download_type": "standard", "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 163, "date_created": "2016-05-31T23:40:07", "date_modified": "2016-05-31T23:40:07", "src": "https://example.com/wp-content/uploads/2016/05/T_2_front.jpg", "name": "", "alt": "", "position": 0 }, { "id": 164, "date_created": "2016-05-31T23:40:10", "date_modified": "2016-05-31T23:40:10", "src": "https://example.com/wp-content/uploads/2016/05/T_2_back.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/162" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products" } ] } } ```
## List all products This API helps you to view all the products. ```http GET /wp-json/wc/v1/products ``` ```shell curl https://example.com/wp-json/wc/v1/products \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products')); ?> ``` ```python print(wcapi.get("products").json()) ``` ```ruby woocommerce.get("products").parsed_response ``` ```json [ { "id": 165, "name": "Ship Your Idea", "slug": "ship-your-idea-4", "permalink": "https://example.com/product/ship-your-idea-4/", "date_created": "2016-05-31T23:50:56", "date_modified": "2016-06-02T23:11:41", "type": "variable", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "19.99", "regular_price": "", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "price_html": "R$19,99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "download_type": "standard", "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 34, 37, 187, 205, 31 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 166, "date_created": "2016-05-31T23:50:57", "date_modified": "2016-05-31T23:50:57", "src": "https://example.com/wp-content/uploads/2016/05/T_4_front.jpg", "name": "", "alt": "", "position": 0 }, { "id": 167, "date_created": "2016-05-31T23:50:57", "date_modified": "2016-05-31T23:50:57", "src": "https://example.com/wp-content/uploads/2016/05/T_4_back.jpg", "name": "", "alt": "", "position": 1 }, { "id": 168, "date_created": "2016-05-31T23:50:58", "date_modified": "2016-05-31T23:50:58", "src": "https://example.com/wp-content/uploads/2016/05/T_3_front.jpg", "name": "", "alt": "", "position": 2 }, { "id": 169, "date_created": "2016-05-31T23:50:59", "date_modified": "2016-05-31T23:50:59", "src": "https://example.com/wp-content/uploads/2016/05/T_3_back.jpg", "name": "", "alt": "", "position": 3 } ], "attributes": [ { "id": 6, "name": "Color", "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "id": 0, "name": "Size", "position": 1, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "name": "Color", "option": "black" }, { "id": 0, "name": "size", "option": "S" } ], "variations": [ { "id": 170, "date_created": "2016-05-31T23:50:56", "date_modified": "2016-06-02T23:11:41", "permalink": "https://example.com/product/ship-your-idea-4/?attribute_pa_color=black&attribute_size=S", "sku": "", "price": "19.99", "regular_price": "19.99", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "on_sale": false, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": [ { "id": 171, "date_created": "2016-05-31T23:51:01", "date_modified": "2016-05-31T23:51:01", "src": "https://example.com/wp-content/uploads/2016/05/T_4_front-1.jpg", "name": "", "alt": "", "position": 0 } ], "attributes": [ { "id": 6, "name": "Color", "option": "black" }, { "id": 0, "name": "size", "option": "S" } ] }, { "id": 172, "date_created": "2016-05-31T23:50:56", "date_modified": "2016-06-02T23:11:41", "permalink": "https://example.com/product/ship-your-idea-4/?attribute_pa_color=green&attribute_size=M", "sku": "", "price": "19.99", "regular_price": "19.99", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "on_sale": false, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": [ { "id": 173, "date_created": "2016-05-31T23:51:03", "date_modified": "2016-05-31T23:51:03", "src": "https://example.com/wp-content/uploads/2016/05/T_3_front-1.jpg", "name": "", "alt": "", "position": 0 } ], "attributes": [ { "id": 6, "name": "Color", "option": "green" }, { "id": 0, "name": "size", "option": "M" } ] } ], "grouped_products": [], "menu_order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/165" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products" } ] } }, { "id": 162, "name": "Premium Quality", "slug": "premium-quality-3", "permalink": "https://example.com/product/premium-quality-3/", "date_created": "2016-05-31T23:40:07", "date_modified": "2016-05-31T23:40:07", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "price_html": "R$21,99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "download_type": "standard", "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 163, "date_created": "2016-05-31T23:40:07", "date_modified": "2016-05-31T23:40:07", "src": "https://example.com/wp-content/uploads/2016/05/T_2_front.jpg", "name": "", "alt": "", "position": 0 }, { "id": 164, "date_created": "2016-05-31T23:40:10", "date_modified": "2016-05-31T23:40:10", "src": "https://example.com/wp-content/uploads/2016/05/T_2_back.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/162" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products" } ] } } ] ```
#### Available parameters | Parameter | Type | Description | |------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | string | Ensure result set excludes specific ids. | | `include` | string | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `date`, Options: `date`, `id`, `include`, `title` and `slug`. | | `slug` | string | Limit result set to products with a specific slug. | | `status` | string | Limit result set to products assigned a specific status. Default is `any`. Options: `any`, `draft`, `pending`, `private` and `publish`. | | `customer` | string | Limit result set to orders assigned a specific customer. | | `category` | string | Limit result set to products assigned a specific category, e.g. `?category=9,14`. | | `tag` | string | Limit result set to products assigned a specific tag, e.g. `?tag=9,14`. | | `shipping_class` | string | Limit result set to products assigned a specific shipping class, e.g. `?shipping_class=9,14`. | | `attribute` | string | Limit result set to products with a specific attribute, e.g. `?attribute=pa_color`. | | `attribute_term` | string | Limit result set to products with a specific attribute term (required an assigned `attribute`), e.g. `?attribute=pa_color&attribute_term=9,14`. | | `sku` | string | Limit result set to products with a specific SKU. | ## Update a product This API lets you make changes to a product. ```http PUT /wp-json/wc/v1/products/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v1/products/162 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "regular_price": "24.54" }' ``` ```javascript const data = { regular_price: "24.54" }; WooCommerce.put("products/162", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php '24.54' ]; print_r($woocommerce->put('products/162', $data)); ?> ``` ```python data = { "regular_price": "24.54" } print(wcapi.put("products/162", data).json()) ``` ```ruby data = { regular_price: "24.54" } woocommerce.put("products/162", data).parsed_response ``` ```json { "id": 162, "name": "Premium Quality", "slug": "premium-quality-3", "permalink": "https://example.com/product/premium-quality-3/", "date_created": "2016-05-31T23:40:07", "date_modified": "2016-05-31T23:40:07", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "24.54", "regular_price": "24.54", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "price_html": "R$24,54", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "download_type": "standard", "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 163, "date_created": "2016-05-31T23:40:07", "date_modified": "2016-05-31T23:40:07", "src": "https://example.com/wp-content/uploads/2016/05/T_2_front.jpg", "name": "", "alt": "", "position": 0 }, { "id": 164, "date_created": "2016-05-31T23:40:10", "date_modified": "2016-05-31T23:40:10", "src": "https://example.com/wp-content/uploads/2016/05/T_2_back.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/162" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products" } ] } } ```
## Delete a product This API helps you delete a product. ```http DELETE /wp-json/wc/v1/products/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/products/162?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/162", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/162', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/162", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/162", force: true).parsed_response ``` ```json { "id": 162, "name": "Premium Quality", "slug": "premium-quality-3", "permalink": "https://example.com/product/premium-quality-3/", "date_created": "2016-05-31T23:40:07", "date_modified": "2016-05-31T23:40:07", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "24.54", "regular_price": "24.54", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "price_html": "R$24,54", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "download_type": "standard", "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 163, "date_created": "2016-05-31T23:40:07", "date_modified": "2016-05-31T23:40:07", "src": "https://example.com/wp-content/uploads/2016/05/T_2_front.jpg", "name": "", "alt": "", "position": 0 }, { "id": 164, "date_created": "2016-05-31T23:40:10", "date_modified": "2016-05-31T23:40:10", "src": "https://example.com/wp-content/uploads/2016/05/T_2_back.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/162" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products" } ] } } ```
#### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------------------| | `force` | string | Use `true` whether to permanently delete the product, Default is `false`. | ## Batch update products This API helps you to batch create, update and delete multiple products. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v1/products/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/products/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Woo Single #1", "type": "simple", "regular_price": "21.99", "virtual": true, "downloadable": true, "downloads": [ { "name": "Woo Single", "file": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], "categories": [ { "id": 11 }, { "id": 13 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg", "position": 0 } ] }, { "name": "New Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", "position": 1 } ] } ], "update": [ { "id": 165, "variations": [ { "id": 170, "regular_price": "29.99" }, { "id": 172, "regular_price": "29.99" } ] } ], "delete": [ 162 ] }' ``` ```javascript const data = { create: [ { name: "Woo Single #1", type: "simple", regular_price: "21.99", virtual: true, downloadable: true, downloads: [ { name: "Woo Single", file: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], categories: [ { id: 11 }, { id: 13 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg", position: 0 } ] }, { name: "New Premium Quality", type: "simple", regular_price: "21.99", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", position: 1 } ] } ], update: [ { id: 165, variations: [ { id: 170, regular_price: "29.99" }, { id: 172, regular_price: "29.99" } ] } ], delete: [ 162 ] }; WooCommerce.post("products/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Woo Single #1', 'type' => 'simple', 'regular_price' => '21.99', 'virtual' => true, 'downloadable' => true, 'downloads' => [ [ 'name' => 'Woo Single', 'file' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg' ] ], 'categories' => [ [ 'id' => 11 ], [ 'id' => 13 ] ], 'images' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', 'position' => 0 ] ] ], [ 'name' => 'New Premium Quality', 'type' => 'simple', 'regular_price' => '21.99', 'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', 'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'categories' => [ [ 'id' => 9 ], [ 'id' => 14 ] ], 'images' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg', 'position' => 0 ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg', 'position' => 1 ] ] ] ], 'update' => [ [ 'id' => 165, 'variations' => [ [ 'id' => 170, 'regular_price' => '29.99' ], [ 'id' => 172, 'regular_price' => '29.99' ] ] ] ], 'delete' => [ 162 ] ]; print_r($woocommerce->post('products/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Woo Single #1", "type": "simple", "regular_price": "21.99", "virtual": True, "downloadable": True, "downloads": [ { "name": "Woo Single", "file": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], "categories": [ { "id": 11 }, { "id": 13 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg", "position": 0 } ] }, { "name": "New Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", "position": 1 } ] } ], "update": [ { "id": 165, "variations": [ { "id": 170, "regular_price": "29.99" }, { "id": 172, "regular_price": "29.99" } ] } ], "delete": [ 162 ] } print(wcapi.post("products/batch", data).json()) ``` ```ruby data = { create: [ { name: "Woo Single #1", type: "simple", regular_price: "21.99", virtual: true, downloadable: true, downloads: [ { name: "Woo Single", file: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], categories: [ { id: 11 }, { id: 13 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg", position: 0 } ] }, { name: "New Premium Quality", type: "simple", regular_price: "21.99", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", position: 1 } ] } ], update: [ { id: 165, variations: [ { id: 170, regular_price: "29.99" }, { id: 172, regular_price: "29.99" } ] } ], delete: [ 162 ] } woocommerce.post("products/batch", data).parsed_response ``` ```json { "create": [ { "id": 174, "name": "Woo Single #1", "slug": "woo-single-1-2", "permalink": "https://example.com/product/woo-single-1-2/", "date_created": "2016-06-01T00:21:30", "date_modified": "2016-06-01T00:21:30", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "", "short_description": "", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "price_html": "R$21,99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": true, "downloadable": true, "downloads": [ { "id": "7b5a304f737cfa35dc527c9e790399bf", "name": "Woo Single", "file": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], "download_limit": -1, "download_expiry": -1, "download_type": "standard", "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": false, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 11, "name": "Music", "slug": "music" }, { "id": 13, "name": "Singles", "slug": "singles" } ], "tags": [], "images": [ { "id": 175, "date_created": "2016-06-01T00:21:31", "date_modified": "2016-06-01T00:21:31", "src": "https://example.com/wp-content/uploads/2016/05/cd_4_angle.jpg", "name": "", "alt": "", "position": 0 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/174" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products" } ] } }, { "id": 176, "name": "New Premium Quality", "slug": "new-premium-quality", "permalink": "https://example.com/product/new-premium-quality/", "date_created": "2016-06-01T00:21:33", "date_modified": "2016-06-01T00:21:33", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "price_html": "R$21,99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "download_type": "standard", "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 177, "date_created": "2016-06-01T00:21:33", "date_modified": "2016-06-01T00:21:33", "src": "https://example.com/wp-content/uploads/2016/05/T_2_front-1.jpg", "name": "", "alt": "", "position": 0 }, { "id": 178, "date_created": "2016-06-01T00:21:34", "date_modified": "2016-06-01T00:21:34", "src": "https://example.com/wp-content/uploads/2016/05/T_2_back-1.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/176" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products" } ] } } ], "update": [ { "id": 165, "name": "Ship Your Idea", "slug": "ship-your-idea-4", "permalink": "https://example.com/product/ship-your-idea-4/", "date_created": "2016-05-31T23:50:56", "date_modified": "2016-06-02T23:11:41", "type": "variable", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "29.99", "regular_price": "", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "price_html": "R$29,99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "download_type": "standard", "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 34, 37, 187, 205, 31 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 166, "date_created": "2016-05-31T23:50:57", "date_modified": "2016-05-31T23:50:57", "src": "https://example.com/wp-content/uploads/2016/05/T_4_front.jpg", "name": "", "alt": "", "position": 0 }, { "id": 167, "date_created": "2016-05-31T23:50:57", "date_modified": "2016-05-31T23:50:57", "src": "https://example.com/wp-content/uploads/2016/05/T_4_back.jpg", "name": "", "alt": "", "position": 1 }, { "id": 168, "date_created": "2016-05-31T23:50:58", "date_modified": "2016-05-31T23:50:58", "src": "https://example.com/wp-content/uploads/2016/05/T_3_front.jpg", "name": "", "alt": "", "position": 2 }, { "id": 169, "date_created": "2016-05-31T23:50:59", "date_modified": "2016-05-31T23:50:59", "src": "https://example.com/wp-content/uploads/2016/05/T_3_back.jpg", "name": "", "alt": "", "position": 3 } ], "attributes": [ { "id": 6, "name": "Color", "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "id": 0, "name": "Size", "position": 1, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "name": "Color", "option": "black" }, { "id": 0, "name": "size", "option": "S" } ], "variations": [ { "id": 170, "date_created": "2016-05-31T23:50:56", "date_modified": "2016-06-02T23:11:41", "permalink": "https://example.com/product/ship-your-idea-4/?attribute_pa_color=black&attribute_size=S", "sku": "", "price": "29.99", "regular_price": "29.99", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "on_sale": false, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": [ { "id": 171, "date_created": "2016-05-31T23:51:01", "date_modified": "2016-05-31T23:51:01", "src": "https://example.com/wp-content/uploads/2016/05/T_4_front-1.jpg", "name": "", "alt": "", "position": 0 } ], "attributes": [ { "id": 6, "name": "Color", "option": "black" }, { "id": 0, "name": "size", "option": "S" } ] }, { "id": 172, "date_created": "2016-05-31T23:50:56", "date_modified": "2016-06-02T23:11:41", "permalink": "https://example.com/product/ship-your-idea-4/?attribute_pa_color=green&attribute_size=M", "sku": "", "price": "29.99", "regular_price": "29.99", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "on_sale": false, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": [ { "id": 173, "date_created": "2016-05-31T23:51:03", "date_modified": "2016-05-31T23:51:03", "src": "https://example.com/wp-content/uploads/2016/05/T_3_front-1.jpg", "name": "", "alt": "", "position": 0 } ], "attributes": [ { "id": 6, "name": "Color", "option": "green" }, { "id": 0, "name": "size", "option": "M" } ] } ], "grouped_products": [], "menu_order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/165" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products" } ] } } ], "delete": [ { "id": 162, "name": "Premium Quality", "slug": "premium-quality-3", "permalink": "https://example.com/product/premium-quality-3/", "date_created": "2016-05-31T23:40:07", "date_modified": "2016-06-01T00:13:45", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "24.54", "regular_price": "24.54", "sale_price": "", "date_on_sale_from": "", "date_on_sale_to": "", "price_html": "R$24,54", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "download_type": "standard", "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 163, "date_created": "2016-05-31T23:40:07", "date_modified": "2016-05-31T23:40:07", "src": "https://example.com/wp-content/uploads/2016/05/T_2_front.jpg", "name": "", "alt": "", "position": 0 }, { "id": 164, "date_created": "2016-05-31T23:40:10", "date_modified": "2016-05-31T23:40:10", "src": "https://example.com/wp-content/uploads/2016/05/T_2_back.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/162" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products" } ] } } ] } ```
## Retrieve product reviews This API lets you retrieve and view a specific product review by ID. ```http GET /wp-json/wc/v1/products//reviews/ ``` ```shell curl https://example.com/wp-json/wc/v1/products/162/reviews/9 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/162/reviews/9") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/162')); ?> ``` ```python print(wcapi.get("products/162/reviews/9").json()) ``` ```ruby woocommerce.get("products/162/reviews/9").parsed_response ``` ```json { "id": 9, "date_created": "2015-05-07T13:01:25", "review": "This will go great with my Hoodie that I ordered a few weeks ago.", "rating": 5, "name": "Stuart", "email": "stuart@example.com", "verified": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/162/reviews/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/162/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/products/162" } ] } } ``` ### Product review properties | Attribute | Type | Description | |----------------|---------|----------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | string | The date the review was created, in the site's timezone. `READ-ONLY` | | `rating` | integer | Review rating (0 to 5). `READ-ONLY` | | `name` | string | Reviewer name. `READ-ONLY` | | `email` | string | Reviewer email. `READ-ONLY` | | `verified` | boolean | Shows if the reviewer bought the product or not. `READ-ONLY` | ## List all product reviews This API lets you retrieve all reviews of a product. ```http GET /wp-json/wc/v1/products//reviews ``` ```shell curl https://example.com/wp-json/wc/v1/products/162/reviews \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/162/reviews") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/162/reviews')); ?> ``` ```python print(wcapi.get("products/162/reviews").json()) ``` ```ruby woocommerce.get("products/162/reviews").parsed_response ``` ```json [ { "id": 9, "date_created": "2015-05-07T13:01:25", "review": "This will go great with my Hoodie that I ordered a few weeks ago.", "rating": 5, "name": "Stuart", "email": "stuart@example.com", "verified": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/162/reviews/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/162/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/products/162" } ] } }, { "id": 10, "date_created": "2015-05-07T15:49:53", "review": "Love this shirt! The ninja near and dear to my heart. <3", "rating": 5, "name": "Maria", "email": "maria@example.com", "verified": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/products/162/reviews/10" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/products/162/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/products/162" } ] } } ] ``` --- ## Reports *Source: apis/rest-api/v1/reports.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Reports The reports API allows you to view all types of reports available. ## List all reports This API lets you retrieve and view a simple list of available reports. ```http GET /wp-json/wc/v1/reports ``` ```shell curl https://example.com/wp-json/wc/v1/reports \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("reports") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('reports')); ?> ``` ```python print(wcapi.get("reports").json()) ``` ```ruby woocommerce.get("reports").parsed_response ``` ```json [ { "slug": "sales", "description": "List of sales reports.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/reports/sales" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/reports" } ] } }, { "slug": "top_sellers", "description": "List of top sellers products.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/reports/top_sellers" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/reports" } ] } } ] ``` ## Retrieve sales report This API lets you retrieve and view a sales report. ```http GET /wp-json/wc/v1/reports/sales ``` ```shell curl https://example.com/wp-json/wc/v1/reports/sales?date_min=2016-05-03&date_max=2016-05-04 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("reports/sales", { date_min: "2016-05-03", date_max: "2016-05-04" }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php '2016-05-03', 'date_max' => '2016-05-04' ]; print_r($woocommerce->get('reports/sales', $query)); ?> ``` ```python print(wcapi.get("reports/sales?date_min=2016-05-03&date_max=2016-05-04").json()) ``` ```ruby query = { date_min: "2016-05-03", date_max: "2016-05-04" } woocommerce.get("reports/sales", query).parsed_response ``` ```json [ { "total_sales": "14.00", "net_sales": "4.00", "average_sales": "2.00", "total_orders": 3, "total_items": 6, "total_tax": "0.00", "total_shipping": "10.00", "total_refunds": 0, "total_discount": "0.00", "totals_grouped_by": "day", "totals": { "2016-05-03": { "sales": "14.00", "orders": 3, "items": 6, "tax": "0.00", "shipping": "10.00", "discount": "0.00", "customers": 0 }, "2016-05-04": { "sales": "0.00", "orders": 0, "items": 0, "tax": "0.00", "shipping": "0.00", "discount": "0.00", "customers": 0 } }, "total_customers": 0, "_links": { "about": [ { "href": "https://example.com/wp-json/wc/v1/reports" } ] } } ] ``` #### Sales report properties | Attribute | Type | Description | |---------------------|---------|-----------------------------------------------------------------------| | `total_sales` | string | Gross sales in the period. `READ-ONLY` | | `net_sales` | string | Net sales in the period. `READ-ONLY` | | `average_sales` | string | Average net daily sales. `READ-ONLY` | | `total_orders` | integer | Total of orders placed. `READ-ONLY` | | `total_items` | integer | Total of items purchased. `READ-ONLY` | | `total_tax` | string | Total charged for taxes. `READ-ONLY` | | `total_shipping` | string | Total charged for shipping. `READ-ONLY` | | `total_refunds` | number | Total of refunded orders. `READ-ONLY` | | `total_discount` | integer | Total of coupons used. `READ-ONLY` | | `totals_grouped_by` | string | Group type. `READ-ONLY` | | `totals` | array | Totals. `READ-ONLY` | #### Available parameters | Parameter | Type | Description | |------------|--------|-------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Default is `view`. Options: `view`. | | `period` | string | Report period. Default is today's date. Options: `week`, `month`, `last_month` and `year` | | `date_min` | string | Return sales for a specific start date, the date need to be in the YYYY-MM-DD format. | | `date_max` | string | Return sales for a specific end date, the date need to be in the YYYY-MM-DD format. | ## Retrieve top sellers report This API lets you retrieve and view a list of top sellers report. ```http GET /wp-json/wc/v1/reports/top_sellers ``` ```shell curl https://example.com/wp-json/wc/v1/reports/top_sellers?period=last_month \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("reports/top_sellers", { period: "last_month", }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'last_month' ]; print_r($woocommerce->get('reports/top_sellers', $query)); ?> ``` ```python print(wcapi.get("reports/top_sellers?period=last_month").json()) ``` ```ruby query = { period: "last_month" } woocommerce.get("reports/top_sellers", query).parsed_response ``` ```json [ { "title": "Happy Ninja", "product_id": 37, "quantity": 1, "_links": { "about": [ { "href": "https://example.com/wp-json/wc/v1/reports" } ], "product": [ { "href": "https://example.com/wp-json/wc/v1/products/37" } ] } }, { "title": "Woo Album #4", "product_id": 96, "quantity": 1, "_links": { "about": [ { "href": "https://example.com/wp-json/wc/v1/reports" } ], "product": [ { "href": "https://example.com/wp-json/wc/v1/products/96" } ] } } ] ``` #### Top sellers report properties | Attribute | Type | Description | |---------------------|---------|-----------------------------------------------------------------------| | `title` | string | Product title. `READ-ONLY` | | `product_id` | integer | Product ID. `READ-ONLY` | | `quantity` | integer | Total number of purchases. `READ-ONLY` | #### Available parameters | Parameter | Type | Description | |------------|--------|-------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Default is `view`. Options: `view`. | | `period` | string | Report period. Default is `week`. Options: `week`, `month`, `last_month` and `year` | | `date_min` | string | Return sales for a specific start date, the date need to be in the YYYY-MM-DD format. | | `date_max` | string | Return sales for a specific end date, the date need to be in the YYYY-MM-DD format. | --- ## Tax classes *Source: apis/rest-api/v1/tax-classes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Tax classes The tax classes API allows you to create, view, and delete individual tax classes. ## Tax class properties | Attribute | Type | Description | |-----------|--------|-------------------------------------------------------------------------------| | `slug` | string | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Tax class name. `REQUIRED` | ## Create a tax class This API helps you to create a new tax class. ```http POST /wp-json/wc/v1/taxes/classes ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/taxes/classes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Zero Rate" }' ``` ```javascript const data = { name: "Zero Rate" }; WooCommerce.post("taxes/classes", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Zero Rate' ]; print_r($woocommerce->post('taxes/classes', $data)); ?> ``` ```python data = { "name": "Zero Rate" } print(wcapi.post("taxes/classes", data).json()) ``` ```ruby data = { name: "Zero Rate" } woocommerce.post("taxes/classes", data).parsed_response ``` ```json { "slug": "zero-rate", "name": "Zero Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes/classes" } ] } } ``` ## List all tax classes This API helps you to view all tax classes. ```http GET /wp-json/wc/v1/taxes/classes ``` ```shell curl https://example.com/wp-json/wc/v1/taxes/classes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("taxes/classes") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('taxes/classes')); ?> ``` ```python print(wcapi.get("taxes/classes").json()) ``` ```ruby woocommerce.get("taxes/classes").parsed_response ``` ```json [ { "slug": "standard", "name": "Standard Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes/classes" } ] } }, { "slug": "reduced-rate", "name": "Reduced Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes/classes" } ] } }, { "slug": "zero-rate", "name": "Zero Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes/classes" } ] } } ] ``` ## Delete a tax class This API helps you delete a tax class. :::warning This also will delete all tax rates from the selected class. ::: ```http DELETE /wp-json/wc/v1/taxes/classes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/taxes/classes/zero-rate?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("taxes/classes/zero-rate", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('taxes/classes/zero-rate', ['force' => true])); ?> ``` ```python print(wcapi.delete("taxes/classes/zero-rate", params={"force": True}).json()) ``` ```ruby woocommerce.delete("taxes/classes/zero-rate", force: true).parsed_response ``` ```json { "slug": "zero-rate", "name": "Zero Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes/classes" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, since this resource does not support trashing. | --- ## Tax rates *Source: apis/rest-api/v1/taxes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Tax rates The taxes API allows you to create, view, update, and delete individual tax rates, or a batch of tax rates. ## Tax rate properties | Attribute | Type | Description | |------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `country` | string | Country ISO 3166 code. See [ISO 3166 Codes (Countries)](http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html) for more details | | `state` | string | State code. | | `postcode` | string | Postcode/ZIP. | | `city` | string | City name. | | `rate` | string | Tax rate. | | `name` | string | Tax rate name. | | `priority` | integer | Tax priority. Only 1 matching rate per priority will be used. To define multiple tax rates for a single area you need to specify a different priority per rate. Default is `1`. | | `compound` | boolean | Whether or not this is a compound rate. Compound tax rates are applied on top of other tax rates. Default is `false`. | | `shipping` | boolean | Whether or not this tax rate also gets applied to shipping. Default is `true`. | | `order` | integer | Indicates the order that will appear in queries. | | `class` | string | Tax class. Default is `standard`. | ## Create a tax rate This API helps you to create a new tax rate. ```http POST /wp-json/wc/v1/taxes ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/taxes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "country": "US", "state": "AL", "rate": "4", "name": "State Tax", "shipping": false }' ``` ```javascript const data = { country: "US", state: "AL", rate: "4", name: "State Tax", shipping: false }; WooCommerce.post("taxes", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'US', 'state' => 'AL', 'rate' => '4', 'name' => 'State Tax', 'shipping' => false ]; print_r($woocommerce->post('taxes', $data)); ?> ``` ```python data = { "country": "US", "state": "AL", "rate": "4", "name": "State Tax", "shipping": False } print(wcapi.post("taxes", data).json()) ``` ```ruby data = { country: "US", state: "AL", rate: "4", name: "State Tax", shipping: false } woocommerce.post("taxes", data).parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } } ``` ## Retrieve a tax rate This API lets you retrieve and view a specific tax rate by ID. ```http GET /wp-json/wc/v1/taxes/ ``` ```shell curl https://example.com/wp-json/wc/v1/taxes/72 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("taxes/72") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('taxes/72')); ?> ``` ```python print(wcapi.get("taxes/72").json()) ``` ```ruby woocommerce.get("taxes/72").parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } } ``` ## List all tax rates This API helps you to view all the tax rates. ```http GET /wp-json/wc/v1/taxes ``` ```shell curl https://example.com/wp-json/wc/v1/taxes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("taxes") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('taxes')); ?> ``` ```python print(wcapi.get("taxes").json()) ``` ```ruby woocommerce.get("taxes").parsed_response ``` ```json [ { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 73, "country": "US", "state": "AZ", "postcode": "", "city": "", "rate": "5.6000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 2, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/73" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 74, "country": "US", "state": "AR", "postcode": "", "city": "", "rate": "6.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 3, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/74" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 75, "country": "US", "state": "CA", "postcode": "", "city": "", "rate": "7.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 4, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/75" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 76, "country": "US", "state": "CO", "postcode": "", "city": "", "rate": "2.9000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 5, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/76" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 77, "country": "US", "state": "CT", "postcode": "", "city": "", "rate": "6.3500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 6, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/77" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 78, "country": "US", "state": "DC", "postcode": "", "city": "", "rate": "5.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 7, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/78" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 79, "country": "US", "state": "FL", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 8, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/79" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 80, "country": "US", "state": "GA", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 9, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/80" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 81, "country": "US", "state": "GU", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 10, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/81" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `name`. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. | | `class` | string | Sort by tax class. | ## Update a tax rate This API lets you make changes to a tax rate. ```http PUT /wp-json/wc/v1/taxes/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v1/taxes/72 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "US Tax" }' ``` ```javascript const data = { name: "US Tax" }; WooCommerce.put("taxes/72", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'US Tax' ]; print_r($woocommerce->put('taxes/72', $data)); ?> ``` ```python data = { "name": "US Tax" } print(wcapi.put("taxes/72", data).json()) ``` ```ruby data = { name: "US Tax" } woocommerce.put("taxes/72", data).parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "US Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } } ``` ## Delete a tax rate This API helps you delete a tax rate. ```http DELETE /wp-json/wc/v1/taxes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/taxes/72?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("taxes/72", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('taxes/72', ['force' => true])); ?> ``` ```python print(wcapi.delete("taxes/72", params={"force": True}).json()) ``` ```ruby woocommerce.delete("taxes/72", force: true).parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "US Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update tax rates This API helps you to batch create, update and delete multiple tax rates. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v1/taxes/batch ``` > Example batch creating all US taxes: ```shell curl -X POST https://example.com/wp-json/wc/v1/taxes/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "country": "US", "state": "AL", "rate": "4.0000", "name": "State Tax", "shipping": false, "order": 1 }, { "country": "US", "state": "AZ", "rate": "5.6000", "name": "State Tax", "shipping": false, "order": 2 }, { "country": "US", "state": "AR", "rate": "6.5000", "name": "State Tax", "shipping": true, "order": 3 }, { "country": "US", "state": "CA", "rate": "7.5000", "name": "State Tax", "shipping": false, "order": 4 }, { "country": "US", "state": "CO", "rate": "2.9000", "name": "State Tax", "shipping": false, "order": 5 }, { "country": "US", "state": "CT", "rate": "6.3500", "name": "State Tax", "shipping": true, "order": 6 }, { "country": "US", "state": "DC", "rate": "5.7500", "name": "State Tax", "shipping": true, "order": 7 }, { "country": "US", "state": "FL", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 8 }, { "country": "US", "state": "GA", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 9 }, { "country": "US", "state": "GU", "rate": "4.0000", "name": "State Tax", "shipping": false, "order": 10 }, { "country": "US", "state": "HI", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 11 }, { "country": "US", "state": "ID", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 12 }, { "country": "US", "state": "IL", "rate": "6.2500", "name": "State Tax", "shipping": false, "order": 13 }, { "country": "US", "state": "IN", "rate": "7.0000", "name": "State Tax", "shipping": false, "order": 14 }, { "country": "US", "state": "IA", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 15 }, { "country": "US", "state": "KS", "rate": "6.1500", "name": "State Tax", "shipping": true, "order": 16 }, { "country": "US", "state": "KY", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 17 }, { "country": "US", "state": "LA", "rate": "4.0000", "name": "State Tax", "shipping": false, "order": 18 }, { "country": "US", "state": "ME", "rate": "5.5000", "name": "State Tax", "shipping": false, "order": 19 }, { "country": "US", "state": "MD", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 20 }, { "country": "US", "state": "MA", "rate": "6.2500", "name": "State Tax", "shipping": false, "order": 21 }, { "country": "US", "state": "MI", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 22 }, { "country": "US", "state": "MN", "rate": "6.8750", "name": "State Tax", "shipping": true, "order": 23 }, { "country": "US", "state": "MS", "rate": "7.0000", "name": "State Tax", "shipping": true, "order": 24 }, { "country": "US", "state": "MO", "rate": "4.2250", "name": "State Tax", "shipping": false, "order": 25 }, { "country": "US", "state": "NE", "rate": "5.5000", "name": "State Tax", "shipping": true, "order": 26 }, { "country": "US", "state": "NV", "rate": "6.8500", "name": "State Tax", "shipping": false, "order": 27 }, { "country": "US", "state": "NJ", "rate": "7.0000", "name": "State Tax", "shipping": true, "order": 28 }, { "country": "US", "state": "NM", "rate": "5.1250", "name": "State Tax", "shipping": true, "order": 29 }, { "country": "US", "state": "NY", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 30 }, { "country": "US", "state": "NC", "rate": "4.7500", "name": "State Tax", "shipping": true, "order": 31 }, { "country": "US", "state": "ND", "rate": "5.0000", "name": "State Tax", "shipping": true, "order": 32 }, { "country": "US", "state": "OH", "rate": "5.7500", "name": "State Tax", "shipping": true, "order": 33 }, { "country": "US", "state": "OK", "rate": "4.5000", "name": "State Tax", "shipping": false, "order": 34 }, { "country": "US", "state": "PA", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 35 }, { "country": "US", "state": "PR", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 36 }, { "country": "US", "state": "RI", "rate": "7.0000", "name": "State Tax", "shipping": false, "order": 37 }, { "country": "US", "state": "SC", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 38 }, { "country": "US", "state": "SD", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 39 }, { "country": "US", "state": "TN", "rate": "7.0000", "name": "State Tax", "shipping": true, "order": 40 }, { "country": "US", "state": "TX", "rate": "6.2500", "name": "State Tax", "shipping": true, "order": 41 }, { "country": "US", "state": "UT", "rate": "5.9500", "name": "State Tax", "shipping": false, "order": 42 }, { "country": "US", "state": "VT", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 43 }, { "country": "US", "state": "VA", "rate": "5.3000", "name": "State Tax", "shipping": false, "order": 44 }, { "country": "US", "state": "WA", "rate": "6.5000", "name": "State Tax", "shipping": true, "order": 45 }, { "country": "US", "state": "WV", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 46 }, { "country": "US", "state": "WI", "rate": "5.0000", "name": "State Tax", "shipping": true, "order": 47 }, { "country": "US", "state": "WY", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 48 } ] }' ``` ```javascript const data = { create: [ { country: "US", state: "AL", rate: "4.0000", name: "State Tax", shipping: false, order: 1 }, { country: "US", state: "AZ", rate: "5.6000", name: "State Tax", shipping: false, order: 2 }, { country: "US", state: "AR", rate: "6.5000", name: "State Tax", shipping: true, order: 3 }, { country: "US", state: "CA", rate: "7.5000", name: "State Tax", shipping: false, order: 4 }, { country: "US", state: "CO", rate: "2.9000", name: "State Tax", shipping: false, order: 5 }, { country: "US", state: "CT", rate: "6.3500", name: "State Tax", shipping: true, order: 6 }, { country: "US", state: "DC", rate: "5.7500", name: "State Tax", shipping: true, order: 7 }, { country: "US", state: "FL", rate: "6.0000", name: "State Tax", shipping: true, order: 8 }, { country: "US", state: "GA", rate: "4.0000", name: "State Tax", shipping: true, order: 9 }, { country: "US", state: "GU", rate: "4.0000", name: "State Tax", shipping: false, order: 10 }, { country: "US", state: "HI", rate: "4.0000", name: "State Tax", shipping: true, order: 11 }, { country: "US", state: "ID", rate: "6.0000", name: "State Tax", shipping: false, order: 12 }, { country: "US", state: "IL", rate: "6.2500", name: "State Tax", shipping: false, order: 13 }, { country: "US", state: "IN", rate: "7.0000", name: "State Tax", shipping: false, order: 14 }, { country: "US", state: "IA", rate: "6.0000", name: "State Tax", shipping: false, order: 15 }, { country: "US", state: "KS", rate: "6.1500", name: "State Tax", shipping: true, order: 16 }, { country: "US", state: "KY", rate: "6.0000", name: "State Tax", shipping: true, order: 17 }, { country: "US", state: "LA", rate: "4.0000", name: "State Tax", shipping: false, order: 18 }, { country: "US", state: "ME", rate: "5.5000", name: "State Tax", shipping: false, order: 19 }, { country: "US", state: "MD", rate: "6.0000", name: "State Tax", shipping: false, order: 20 }, { country: "US", state: "MA", rate: "6.2500", name: "State Tax", shipping: false, order: 21 }, { country: "US", state: "MI", rate: "6.0000", name: "State Tax", shipping: true, order: 22 }, { country: "US", state: "MN", rate: "6.8750", name: "State Tax", shipping: true, order: 23 }, { country: "US", state: "MS", rate: "7.0000", name: "State Tax", shipping: true, order: 24 }, { country: "US", state: "MO", rate: "4.2250", name: "State Tax", shipping: false, order: 25 }, { country: "US", state: "NE", rate: "5.5000", name: "State Tax", shipping: true, order: 26 }, { country: "US", state: "NV", rate: "6.8500", name: "State Tax", shipping: false, order: 27 }, { country: "US", state: "NJ", rate: "7.0000", name: "State Tax", shipping: true, order: 28 }, { country: "US", state: "NM", rate: "5.1250", name: "State Tax", shipping: true, order: 29 }, { country: "US", state: "NY", rate: "4.0000", name: "State Tax", shipping: true, order: 30 }, { country: "US", state: "NC", rate: "4.7500", name: "State Tax", shipping: true, order: 31 }, { country: "US", state: "ND", rate: "5.0000", name: "State Tax", shipping: true, order: 32 }, { country: "US", state: "OH", rate: "5.7500", name: "State Tax", shipping: true, order: 33 }, { country: "US", state: "OK", rate: "4.5000", name: "State Tax", shipping: false, order: 34 }, { country: "US", state: "PA", rate: "6.0000", name: "State Tax", shipping: true, order: 35 }, { country: "US", state: "PR", rate: "6.0000", name: "State Tax", shipping: false, order: 36 }, { country: "US", state: "RI", rate: "7.0000", name: "State Tax", shipping: false, order: 37 }, { country: "US", state: "SC", rate: "6.0000", name: "State Tax", shipping: true, order: 38 }, { country: "US", state: "SD", rate: "4.0000", name: "State Tax", shipping: true, order: 39 }, { country: "US", state: "TN", rate: "7.0000", name: "State Tax", shipping: true, order: 40 }, { country: "US", state: "TX", rate: "6.2500", name: "State Tax", shipping: true, order: 41 }, { country: "US", state: "UT", rate: "5.9500", name: "State Tax", shipping: false, order: 42 }, { country: "US", state: "VT", rate: "6.0000", name: "State Tax", shipping: true, order: 43 }, { country: "US", state: "VA", rate: "5.3000", name: "State Tax", shipping: false, order: 44 }, { country: "US", state: "WA", rate: "6.5000", name: "State Tax", shipping: true, order: 45 }, { country: "US", state: "WV", rate: "6.0000", name: "State Tax", shipping: true, order: 46 }, { country: "US", state: "WI", rate: "5.0000", name: "State Tax", shipping: true, order: 47 }, { country: "US", state: "WY", rate: "4.0000", name: "State Tax", shipping: true, order: 48 } ] }; WooCommerce.post("taxes/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'country' => 'US', 'state' => 'AL', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 1 ], [ 'country' => 'US', 'state' => 'AZ', 'rate' => '5.6000', 'name' => 'State Tax', 'shipping' => false, 'order' => 2 ], [ 'country' => 'US', 'state' => 'AR', 'rate' => '6.5000', 'name' => 'State Tax', 'shipping' => true, 'order' => 3 ], [ 'country' => 'US', 'state' => 'CA', 'rate' => '7.5000', 'name' => 'State Tax', 'shipping' => false, 'order' => 4 ], [ 'country' => 'US', 'state' => 'CO', 'rate' => '2.9000', 'name' => 'State Tax', 'shipping' => false, 'order' => 5 ], [ 'country' => 'US', 'state' => 'CT', 'rate' => '6.3500', 'name' => 'State Tax', 'shipping' => true, 'order' => 6 ], [ 'country' => 'US', 'state' => 'DC', 'rate' => '5.7500', 'name' => 'State Tax', 'shipping' => true, 'order' => 7 ], [ 'country' => 'US', 'state' => 'FL', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 8 ], [ 'country' => 'US', 'state' => 'GA', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 9 ], [ 'country' => 'US', 'state' => 'GU', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 10 ], [ 'country' => 'US', 'state' => 'HI', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 11 ], [ 'country' => 'US', 'state' => 'ID', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 12 ], [ 'country' => 'US', 'state' => 'IL', 'rate' => '6.2500', 'name' => 'State Tax', 'shipping' => false, 'order' => 13 ], [ 'country' => 'US', 'state' => 'IN', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 14 ], [ 'country' => 'US', 'state' => 'IA', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 15 ], [ 'country' => 'US', 'state' => 'KS', 'rate' => '6.1500', 'name' => 'State Tax', 'shipping' => true, 'order' => 16 ], [ 'country' => 'US', 'state' => 'KY', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 17 ], [ 'country' => 'US', 'state' => 'LA', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 18 ], [ 'country' => 'US', 'state' => 'ME', 'rate' => '5.5000', 'name' => 'State Tax', 'shipping' => false, 'order' => 19 ], [ 'country' => 'US', 'state' => 'MD', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 20 ], [ 'country' => 'US', 'state' => 'MA', 'rate' => '6.2500', 'name' => 'State Tax', 'shipping' => false, 'order' => 21 ], [ 'country' => 'US', 'state' => 'MI', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 22 ], [ 'country' => 'US', 'state' => 'MN', 'rate' => '6.8750', 'name' => 'State Tax', 'shipping' => true, 'order' => 23 ], [ 'country' => 'US', 'state' => 'MS', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 24 ], [ 'country' => 'US', 'state' => 'MO', 'rate' => '4.2250', 'name' => 'State Tax', 'shipping' => false, 'order' => 25 ], [ 'country' => 'US', 'state' => 'NE', 'rate' => '5.5000', 'name' => 'State Tax', 'shipping' => true, 'order' => 26 ], [ 'country' => 'US', 'state' => 'NV', 'rate' => '6.8500', 'name' => 'State Tax', 'shipping' => false, 'order' => 27 ], [ 'country' => 'US', 'state' => 'NJ', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 28 ], [ 'country' => 'US', 'state' => 'NM', 'rate' => '5.1250', 'name' => 'State Tax', 'shipping' => true, 'order' => 29 ], [ 'country' => 'US', 'state' => 'NY', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 30 ], [ 'country' => 'US', 'state' => 'NC', 'rate' => '4.7500', 'name' => 'State Tax', 'shipping' => true, 'order' => 31 ], [ 'country' => 'US', 'state' => 'ND', 'rate' => '5.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 32 ], [ 'country' => 'US', 'state' => 'OH', 'rate' => '5.7500', 'name' => 'State Tax', 'shipping' => true, 'order' => 33 ], [ 'country' => 'US', 'state' => 'OK', 'rate' => '4.5000', 'name' => 'State Tax', 'shipping' => false, 'order' => 34 ], [ 'country' => 'US', 'state' => 'PA', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 35 ], [ 'country' => 'US', 'state' => 'PR', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 36 ], [ 'country' => 'US', 'state' => 'RI', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 37 ], [ 'country' => 'US', 'state' => 'SC', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 38 ], [ 'country' => 'US', 'state' => 'SD', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 39 ], [ 'country' => 'US', 'state' => 'TN', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 40 ], [ 'country' => 'US', 'state' => 'TX', 'rate' => '6.2500', 'name' => 'State Tax', 'shipping' => true, 'order' => 41 ], [ 'country' => 'US', 'state' => 'UT', 'rate' => '5.9500', 'name' => 'State Tax', 'shipping' => false, 'order' => 42 ], [ 'country' => 'US', 'state' => 'VT', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 43 ], [ 'country' => 'US', 'state' => 'VA', 'rate' => '5.3000', 'name' => 'State Tax', 'shipping' => false, 'order' => 44 ], [ 'country' => 'US', 'state' => 'WA', 'rate' => '6.5000', 'name' => 'State Tax', 'shipping' => true, 'order' => 45 ], [ 'country' => 'US', 'state' => 'WV', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 46 ], [ 'country' => 'US', 'state' => 'WI', 'rate' => '5.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 47 ], [ 'country' => 'US', 'state' => 'WY', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 48 ] ] ]; print_r($woocommerce->post('taxes/batch', $data)); ?> ``` ```python data = { "create": [ { "country": "US", "state": "AL", "rate": "4.0000", "name": "State Tax", "shipping": False, "order": 1 }, { "country": "US", "state": "AZ", "rate": "5.6000", "name": "State Tax", "shipping": False, "order": 2 }, { "country": "US", "state": "AR", "rate": "6.5000", "name": "State Tax", "shipping": True, "order": 3 }, { "country": "US", "state": "CA", "rate": "7.5000", "name": "State Tax", "shipping": False, "order": 4 }, { "country": "US", "state": "CO", "rate": "2.9000", "name": "State Tax", "shipping": False, "order": 5 }, { "country": "US", "state": "CT", "rate": "6.3500", "name": "State Tax", "shipping": True, "order": 6 }, { "country": "US", "state": "DC", "rate": "5.7500", "name": "State Tax", "shipping": True, "order": 7 }, { "country": "US", "state": "FL", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 8 }, { "country": "US", "state": "GA", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 9 }, { "country": "US", "state": "GU", "rate": "4.0000", "name": "State Tax", "shipping": False, "order": 10 }, { "country": "US", "state": "HI", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 11 }, { "country": "US", "state": "ID", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 12 }, { "country": "US", "state": "IL", "rate": "6.2500", "name": "State Tax", "shipping": False, "order": 13 }, { "country": "US", "state": "IN", "rate": "7.0000", "name": "State Tax", "shipping": False, "order": 14 }, { "country": "US", "state": "IA", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 15 }, { "country": "US", "state": "KS", "rate": "6.1500", "name": "State Tax", "shipping": True, "order": 16 }, { "country": "US", "state": "KY", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 17 }, { "country": "US", "state": "LA", "rate": "4.0000", "name": "State Tax", "shipping": False, "order": 18 }, { "country": "US", "state": "ME", "rate": "5.5000", "name": "State Tax", "shipping": False, "order": 19 }, { "country": "US", "state": "MD", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 20 }, { "country": "US", "state": "MA", "rate": "6.2500", "name": "State Tax", "shipping": False, "order": 21 }, { "country": "US", "state": "MI", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 22 }, { "country": "US", "state": "MN", "rate": "6.8750", "name": "State Tax", "shipping": True, "order": 23 }, { "country": "US", "state": "MS", "rate": "7.0000", "name": "State Tax", "shipping": True, "order": 24 }, { "country": "US", "state": "MO", "rate": "4.2250", "name": "State Tax", "shipping": False, "order": 25 }, { "country": "US", "state": "NE", "rate": "5.5000", "name": "State Tax", "shipping": True, "order": 26 }, { "country": "US", "state": "NV", "rate": "6.8500", "name": "State Tax", "shipping": False, "order": 27 }, { "country": "US", "state": "NJ", "rate": "7.0000", "name": "State Tax", "shipping": True, "order": 28 }, { "country": "US", "state": "NM", "rate": "5.1250", "name": "State Tax", "shipping": True, "order": 29 }, { "country": "US", "state": "NY", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 30 }, { "country": "US", "state": "NC", "rate": "4.7500", "name": "State Tax", "shipping": True, "order": 31 }, { "country": "US", "state": "ND", "rate": "5.0000", "name": "State Tax", "shipping": True, "order": 32 }, { "country": "US", "state": "OH", "rate": "5.7500", "name": "State Tax", "shipping": True, "order": 33 }, { "country": "US", "state": "OK", "rate": "4.5000", "name": "State Tax", "shipping": False, "order": 34 }, { "country": "US", "state": "PA", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 35 }, { "country": "US", "state": "PR", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 36 }, { "country": "US", "state": "RI", "rate": "7.0000", "name": "State Tax", "shipping": False, "order": 37 }, { "country": "US", "state": "SC", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 38 }, { "country": "US", "state": "SD", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 39 }, { "country": "US", "state": "TN", "rate": "7.0000", "name": "State Tax", "shipping": True, "order": 40 }, { "country": "US", "state": "TX", "rate": "6.2500", "name": "State Tax", "shipping": True, "order": 41 }, { "country": "US", "state": "UT", "rate": "5.9500", "name": "State Tax", "shipping": False, "order": 42 }, { "country": "US", "state": "VT", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 43 }, { "country": "US", "state": "VA", "rate": "5.3000", "name": "State Tax", "shipping": False, "order": 44 }, { "country": "US", "state": "WA", "rate": "6.5000", "name": "State Tax", "shipping": True, "order": 45 }, { "country": "US", "state": "WV", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 46 }, { "country": "US", "state": "WI", "rate": "5.0000", "name": "State Tax", "shipping": True, "order": 47 }, { "country": "US", "state": "WY", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 48 } ] } print(wcapi.post("taxes/batch", data).json()) ``` ```ruby data = { create: [ { country: "US", state: "AL", rate: "4.0000", name: "State Tax", shipping: false, order: 1 }, { country: "US", state: "AZ", rate: "5.6000", name: "State Tax", shipping: false, order: 2 }, { country: "US", state: "AR", rate: "6.5000", name: "State Tax", shipping: true, order: 3 }, { country: "US", state: "CA", rate: "7.5000", name: "State Tax", shipping: false, order: 4 }, { country: "US", state: "CO", rate: "2.9000", name: "State Tax", shipping: false, order: 5 }, { country: "US", state: "CT", rate: "6.3500", name: "State Tax", shipping: true, order: 6 }, { country: "US", state: "DC", rate: "5.7500", name: "State Tax", shipping: true, order: 7 }, { country: "US", state: "FL", rate: "6.0000", name: "State Tax", shipping: true, order: 8 }, { country: "US", state: "GA", rate: "4.0000", name: "State Tax", shipping: true, order: 9 }, { country: "US", state: "GU", rate: "4.0000", name: "State Tax", shipping: false, order: 10 }, { country: "US", state: "HI", rate: "4.0000", name: "State Tax", shipping: true, order: 11 }, { country: "US", state: "ID", rate: "6.0000", name: "State Tax", shipping: false, order: 12 }, { country: "US", state: "IL", rate: "6.2500", name: "State Tax", shipping: false, order: 13 }, { country: "US", state: "IN", rate: "7.0000", name: "State Tax", shipping: false, order: 14 }, { country: "US", state: "IA", rate: "6.0000", name: "State Tax", shipping: false, order: 15 }, { country: "US", state: "KS", rate: "6.1500", name: "State Tax", shipping: true, order: 16 }, { country: "US", state: "KY", rate: "6.0000", name: "State Tax", shipping: true, order: 17 }, { country: "US", state: "LA", rate: "4.0000", name: "State Tax", shipping: false, order: 18 }, { country: "US", state: "ME", rate: "5.5000", name: "State Tax", shipping: false, order: 19 }, { country: "US", state: "MD", rate: "6.0000", name: "State Tax", shipping: false, order: 20 }, { country: "US", state: "MA", rate: "6.2500", name: "State Tax", shipping: false, order: 21 }, { country: "US", state: "MI", rate: "6.0000", name: "State Tax", shipping: true, order: 22 }, { country: "US", state: "MN", rate: "6.8750", name: "State Tax", shipping: true, order: 23 }, { country: "US", state: "MS", rate: "7.0000", name: "State Tax", shipping: true, order: 24 }, { country: "US", state: "MO", rate: "4.2250", name: "State Tax", shipping: false, order: 25 }, { country: "US", state: "NE", rate: "5.5000", name: "State Tax", shipping: true, order: 26 }, { country: "US", state: "NV", rate: "6.8500", name: "State Tax", shipping: false, order: 27 }, { country: "US", state: "NJ", rate: "7.0000", name: "State Tax", shipping: true, order: 28 }, { country: "US", state: "NM", rate: "5.1250", name: "State Tax", shipping: true, order: 29 }, { country: "US", state: "NY", rate: "4.0000", name: "State Tax", shipping: true, order: 30 }, { country: "US", state: "NC", rate: "4.7500", name: "State Tax", shipping: true, order: 31 }, { country: "US", state: "ND", rate: "5.0000", name: "State Tax", shipping: true, order: 32 }, { country: "US", state: "OH", rate: "5.7500", name: "State Tax", shipping: true, order: 33 }, { country: "US", state: "OK", rate: "4.5000", name: "State Tax", shipping: false, order: 34 }, { country: "US", state: "PA", rate: "6.0000", name: "State Tax", shipping: true, order: 35 }, { country: "US", state: "PR", rate: "6.0000", name: "State Tax", shipping: false, order: 36 }, { country: "US", state: "RI", rate: "7.0000", name: "State Tax", shipping: false, order: 37 }, { country: "US", state: "SC", rate: "6.0000", name: "State Tax", shipping: true, order: 38 }, { country: "US", state: "SD", rate: "4.0000", name: "State Tax", shipping: true, order: 39 }, { country: "US", state: "TN", rate: "7.0000", name: "State Tax", shipping: true, order: 40 }, { country: "US", state: "TX", rate: "6.2500", name: "State Tax", shipping: true, order: 41 }, { country: "US", state: "UT", rate: "5.9500", name: "State Tax", shipping: false, order: 42 }, { country: "US", state: "VT", rate: "6.0000", name: "State Tax", shipping: true, order: 43 }, { country: "US", state: "VA", rate: "5.3000", name: "State Tax", shipping: false, order: 44 }, { country: "US", state: "WA", rate: "6.5000", name: "State Tax", shipping: true, order: 45 }, { country: "US", state: "WV", rate: "6.0000", name: "State Tax", shipping: true, order: 46 }, { country: "US", state: "WI", rate: "5.0000", name: "State Tax", shipping: true, order: 47 }, { country: "US", state: "WY", rate: "4.0000", name: "State Tax", shipping: true, order: 48 } ] } woocommerce.post("taxes/batch", data).parsed_response ``` ```json { "create": [ { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 73, "country": "US", "state": "AZ", "postcode": "", "city": "", "rate": "5.6000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 2, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/73" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 74, "country": "US", "state": "AR", "postcode": "", "city": "", "rate": "6.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 3, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/74" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 75, "country": "US", "state": "CA", "postcode": "", "city": "", "rate": "7.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 4, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/75" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 76, "country": "US", "state": "CO", "postcode": "", "city": "", "rate": "2.9000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 5, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/76" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 77, "country": "US", "state": "CT", "postcode": "", "city": "", "rate": "6.3500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 6, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/77" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 78, "country": "US", "state": "DC", "postcode": "", "city": "", "rate": "5.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 7, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/78" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 79, "country": "US", "state": "FL", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 8, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/79" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 80, "country": "US", "state": "GA", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 9, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/80" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 81, "country": "US", "state": "GU", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 10, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/81" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 82, "country": "US", "state": "HI", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 11, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/82" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 83, "country": "US", "state": "ID", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 12, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/83" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 84, "country": "US", "state": "IL", "postcode": "", "city": "", "rate": "6.2500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 13, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/84" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 85, "country": "US", "state": "IN", "postcode": "", "city": "", "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 14, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/85" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 86, "country": "US", "state": "IA", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 15, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/86" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 87, "country": "US", "state": "KS", "postcode": "", "city": "", "rate": "6.1500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 16, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/87" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 88, "country": "US", "state": "KY", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 17, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/88" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 89, "country": "US", "state": "LA", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 18, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/89" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 90, "country": "US", "state": "ME", "postcode": "", "city": "", "rate": "5.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 19, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/90" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 91, "country": "US", "state": "MD", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 20, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/91" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 92, "country": "US", "state": "MA", "postcode": "", "city": "", "rate": "6.2500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 21, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/92" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 93, "country": "US", "state": "MI", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 22, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/93" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 94, "country": "US", "state": "MN", "postcode": "", "city": "", "rate": "6.8750", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 23, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/94" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 95, "country": "US", "state": "MS", "postcode": "", "city": "", "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 24, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/95" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 96, "country": "US", "state": "MO", "postcode": "", "city": "", "rate": "4.2250", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 25, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/96" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 97, "country": "US", "state": "NE", "postcode": "", "city": "", "rate": "5.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 26, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/97" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 98, "country": "US", "state": "NV", "postcode": "", "city": "", "rate": "6.8500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 27, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/98" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 99, "country": "US", "state": "NJ", "postcode": "", "city": "", "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 28, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/99" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 100, "country": "US", "state": "NM", "postcode": "", "city": "", "rate": "5.1250", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 29, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/100" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 101, "country": "US", "state": "NY", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 30, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/101" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 102, "country": "US", "state": "NC", "postcode": "", "city": "", "rate": "4.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 31, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/102" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 103, "country": "US", "state": "ND", "postcode": "", "city": "", "rate": "5.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 32, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/103" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 104, "country": "US", "state": "OH", "postcode": "", "city": "", "rate": "5.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 33, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/104" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 105, "country": "US", "state": "OK", "postcode": "", "city": "", "rate": "4.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 34, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/105" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 106, "country": "US", "state": "PA", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 35, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/106" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 107, "country": "US", "state": "PR", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 36, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/107" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 108, "country": "US", "state": "RI", "postcode": "", "city": "", "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 37, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/108" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 109, "country": "US", "state": "SC", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 38, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/109" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 110, "country": "US", "state": "SD", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 39, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/110" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 111, "country": "US", "state": "TN", "postcode": "", "city": "", "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 40, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/111" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 112, "country": "US", "state": "TX", "postcode": "", "city": "", "rate": "6.2500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 41, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/112" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 113, "country": "US", "state": "UT", "postcode": "", "city": "", "rate": "5.9500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 42, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/113" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 114, "country": "US", "state": "VT", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 43, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/114" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 115, "country": "US", "state": "VA", "postcode": "", "city": "", "rate": "5.3000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 44, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/115" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 116, "country": "US", "state": "WA", "postcode": "", "city": "", "rate": "6.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 45, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/116" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 117, "country": "US", "state": "WV", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 46, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/117" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 118, "country": "US", "state": "WI", "postcode": "", "city": "", "rate": "5.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 47, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/118" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } }, { "id": 119, "country": "US", "state": "WY", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 48, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/taxes/119" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/taxes" } ] } } ] } ``` --- ## Webhooks *Source: apis/rest-api/v1/webhooks.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Webhooks The webhooks API allows you to create, view, update, and delete individual, or a batch, of webhooks. Webhooks can be managed via the WooCommerce settings screen or by using the REST API endpoints. The `WC_Webhook` class manages all data storage and retrieval of the webhook custom post type, as well as enqueuing webhook actions and processing/delivering/logging webhooks. On `woocommerce_init`, active webhooks are loaded. Each webhook has: * `status`: active (delivers payload), paused (delivery paused by admin), disabled (delivery paused by failure). * `topic`: determines which resource events the webhook is triggered for. * `delivery URL`: URL where the payload is delivered, must be HTTP or HTTPS. * `secret`: an optional secret key that is used to generate a HMAC-SHA256 hash of the request body so the receiver can verify authenticity of the webhook. * `hooks`: an array of hook names that are added and bound to the webhook for processing. ### Topics The topic is a combination resource (e.g. order) and event (e.g. created) and maps to one or more hook names (e.g. `woocommerce_checkout_order_processed`). Webhooks can be created using the topic name and the appropriate hooks are automatically added. Core topics are: * Coupons: `coupon.created`, `coupon.updated` and `coupon.deleted`. * Customers: `customer.created`, `customer.updated` and `customer.deleted`. * Orders: `order.created`, `order.updated` and `order.deleted`. * Products: `product.created`, `product.updated` and `product.deleted`. Custom topics can also be used which map to a single hook name, for example you could add a webhook with topic `action.woocommerce_add_to_cart` that is triggered on that event. Custom topics pass the first hook argument to the payload, so in this example the `cart_item_key` would be included in the payload. ### Delivery/payload Delivery is performed using `wp_remote_post()` (HTTP POST) and processed in the background by default using wp-cron. A few custom headers are added to the request to help the receiver process the webhook: * `X-WC-Webhook-Topic` - e.g. `order.updated`. * `X-WC-Webhook-Resource` - e.g. `order`. * `X-WC-Webhook-Event` - e.g. `updated`. * `X-WC-Webhook-Signature` - a base64 encoded HMAC-SHA256 hash of the payload. * `X-WC-Webhook-ID` - webhook's post ID. * `X-WC-Webhook-Delivery-ID` - delivery log ID (a comment). The payload is JSON encoded and for API resources (coupons, customers, orders, products), the response is exactly the same as if requested via the REST API. ### Logging Requests/responses are logged as comments on the webhook custom post type. Each delivery log includes: * Request duration. * Request URL, method, headers, and body. * Response Code, message, headers, and body. Only the 25 most recent delivery logs are kept in order to reduce comment table bloat. After 5 consecutive failed deliveries (as defined by a non HTTP 2xx response code), the webhook is disabled and must be edited via the REST API to re-enable. Delivery logs can be fetched through the REST API endpoint or in code using `WC_Webhook::get_delivery_logs()`. ### Visual interface You can find the Webhooks interface going to "WooCommerce" > "Settings" > "API" > "Webhooks", see our [Visual Webhooks docs](https://docs.woocommerce.com/document/webhooks/) for more details. ## Webhook properties | Attribute | Type | Description | |-----------------|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | A friendly name for the webhook. Default is `Webhook created on `. | | `status` | string | Webhook status. Default is `active`. Options `active` (delivers payload), `paused` (does not deliver), or `disabled` (does not deliver due delivery failures). | | `topic` | string | Webhook topic, e.g. `coupon.updated`. [See the complete list](#topics). `REQUIRED` | | `resource` | string | Webhook resource, e.g. `coupon` `READ-ONLY` | | `event` | string | Webhook event, e.g. `updated` `READ-ONLY` | | `hooks` | array | WooCommerce action names associated with the webhook. `READ-ONLY` | | `delivery_url` | string | The URL where the webhook payload is delivered. `REQUIRED` | | `secret` | string | Secret key used to generate a hash of the delivered webhook and provided in the request headers. `REQUIRED` `WRITE-ONLY` | | `date_created` | date-time | UTC DateTime when the webhook was created `READ-ONLY` | | `date_modified` | date-time | UTC DateTime when the webhook was last updated `READ-ONLY` | ### Webhooks delivery properties | Attribute | Type | Description | |--------------------|-----------|--------------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `duration` | string | The delivery duration, in seconds. `READ-ONLY` | | `summary` | string | A friendly summary of the response including the HTTP response code, message, and body. `READ-ONLY` | | `request_url` | string | The URL where the webhook was delivered. `READ-ONLY` | | `request_headers` | object | Request headers. See [Request Headers Attributes](#request-header-properties) for more details. `READ-ONLY` | | `request_body` | string | Request body. `READ-ONLY` | | `response_code` | string | The HTTP response code from the receiving server. `READ-ONLY` | | `response_message` | string | The HTTP response message from the receiving server. `READ-ONLY` | | `response_headers` | object | Response headers from the receiving server. `READ-ONLY` | | `response_body` | string | The response body from the receiving server. `READ-ONLY` | | `date_created` | date-time | The date the webhook delivery was logged, in the site's timezone. `READ-ONLY` | #### Request header properties | Attribute | Type | Description | |----------------------------|---------|---------------------------------------------------------------------------------------------------------------------------------------| | `User-Agent` | string | The request user agent, default is "WooCommerce/\{version\} Hookshot (WordPress/\{version\})". `READ-ONLY` | | `Content-Type` | string | The request content-type, default is "application/json". `READ-ONLY` | | `X-WC-Webhook-Source` | string | The webhook source URL. `READ-ONLY` | | `X-WC-Webhook-Topic` | string | The webhook topic. `READ-ONLY` | | `X-WC-Webhook-Resource` | string | The webhook resource. `READ-ONLY` | | `X-WC-Webhook-Event` | string | The webhook event. `READ-ONLY` | | `X-WC-Webhook-Signature` | string | A base64 encoded HMAC-SHA256 hash of the payload. `READ-ONLY` | | `X-WC-Webhook-ID` | integer | The webhook's ID. `READ-ONLY` | | `X-WC-Webhook-Delivery-ID` | integer | The delivery ID. `READ-ONLY` | ## Create a webhook This API helps you to create a new webhook. ```http POST /wp-json/wc/v1/webhooks ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/webhooks \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Order updated", "topic": "order.updated", "delivery_url": "http://requestb.in/1g0sxmo1" }' ``` ```javascript const data = { name: "Order updated", topic: "order.updated", delivery_url: "http://requestb.in/1g0sxmo1" }; WooCommerce.post("webhooks", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Order updated', 'topic' => 'order.updated', 'delivery_url' => 'http://requestb.in/1g0sxmo1' ]; print_r($woocommerce->post('webhooks', $data)); ?> ``` ```python data = { "name": "Order updated", "topic": "order.updated", "delivery_url": "http://requestb.in/1g0sxmo1" } print(wcapi.post("webhooks", data).json()) ``` ```ruby data = { name: "Order updated", topic: "order.updated", delivery_url: "http://requestb.in/1g0sxmo1" } woocommerce.post("webhooks", data).parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "active", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T20:17:52", "date_modified": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks" } ] } } ``` ## Retrieve a webhook This API lets you retrieve and view a specific webhook. ```http GET /wp-json/wc/v1/webhooks/ ``` ```shell curl https://example.com/wp-json/wc/v1/webhooks/142 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("webhooks/142") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('webhooks/142')); ?> ``` ```python print(wcapi.get("webhooks/142").json()) ``` ```ruby woocommerce.get("webhooks/142").parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "active", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T20:17:52", "date_modified": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks" } ] } } ``` ## List all webhooks This API helps you to view all the webhooks. ```http GET /wp-json/wc/v1/webhooks ``` ```shell curl https://example.com/wp-json/wc/v1/webhooks \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("webhooks") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('webhooks')); ?> ``` ```python print(wcapi.get("webhooks").json()) ``` ```ruby woocommerce.get("webhooks").parsed_response ``` ```json [ { "id": 143, "name": "Customer created", "status": "active", "topic": "customer.created", "resource": "customer", "event": "created", "hooks": [ "user_register", "woocommerce_created_customer", "woocommerce_api_create_customer" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T20:17:52", "date_modified": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/143" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks" } ] } }, { "id": 142, "name": "Order updated", "status": "active", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T20:17:52", "date_modified": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |-----------------|---------|-------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | string | Ensure result set excludes specific ids. | | `include` | string | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `date`, Options: `date`, `id`, `include`, `title` and `slug`. | | `slug` | string | Limit result set to posts with a specific slug. | | `status` | string | Limit result set to webhooks assigned a specific status. Default is `all`. Options: `all`, `active`, `paused` and `disabled`. | ## Update a webhook This API lets you make changes to a webhook. ```http PUT /wp-json/wc/v1/webhooks/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v1/webhooks/142 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "status": "paused" }' ``` ```javascript const data = { status: "paused" } WooCommerce.put("webhooks/142", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'paused' ]; print_r($woocommerce->put('webhooks/142', $data)); ?> ``` ```python data = { "status": "paused" } print(wcapi.put("webhooks/142", data).json()) ``` ```ruby data = { status: "paused" } woocommerce.put("webhooks/142", data).parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "paused", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T20:17:52", "date_modified": "2016-05-15T20:30:12", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks" } ] } } ``` ## Delete a webhook This API helps you delete a webhook. ```http DELETE /wp-json/wc/v1/webhooks/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v1/webhooks/142 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("webhooks/142") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('webhooks/142')); ?> ``` ```python print(wcapi.delete("webhooks/142").json()) ``` ```ruby woocommerce.delete("webhooks/142").parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "paused", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T20:17:52", "date_modified": "2016-05-15T20:30:12", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|----------------------------------------------------------------------------| | `force` | boolean | Whether to permanently delete the webhook. Default is `false`. | ## Batch update webhooks This API helps you to batch create, update and delete multiple webhooks. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v1/webhooks/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v1/webhooks/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Coupon created", "topic": "coupon.created", "delivery_url": "http://requestb.in/1g0sxmo1" }, { "name": "Customer deleted", "topic": "customer.deleted", "delivery_url": "http://requestb.in/1g0sxmo1" } ], "delete": [ 143 ] }' ``` ```javascript const data = { create: [ { name: "Round toe", topic: "coupon.created", delivery_url: "http://requestb.in/1g0sxmo1" }, { name: "Customer deleted", topic: "customer.deleted", delivery_url: "http://requestb.in/1g0sxmo1" } ], delete: [ 143 ] }; WooCommerce.post("webhooks/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Round toe', 'topic' => 'coupon.created', 'delivery_url' => 'http://requestb.in/1g0sxmo1' ], [ 'name' => 'Customer deleted', 'topic' => 'customer.deleted', 'delivery_url' => 'http://requestb.in/1g0sxmo1' ] ], 'delete' => [ 143 ] ]; print_r($woocommerce->post('webhooks/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Round toe", "topic": "coupon.created", "delivery_url": "http://requestb.in/1g0sxmo1" }, { "name": "Customer deleted", "topic": "customer.deleted", "delivery_url": "http://requestb.in/1g0sxmo1" } ], "delete": [ 143 ] } print(wcapi.post("webhooks/batch", data).json()) ``` ```ruby data = { create: [ { name: "Round toe", topic: "coupon.created", delivery_url: "http://requestb.in/1g0sxmo1" }, { name: "Customer deleted", topic: "customer.deleted", delivery_url: "http://requestb.in/1g0sxmo1" } ], delete: [ 143 ] } woocommerce.post("webhooks/batch", data).parsed_response ``` ```json { "create": [ { "id": 146, "name": "Coupon created", "status": "active", "topic": "coupon.created", "resource": "coupon", "event": "created", "hooks": [ "woocommerce_process_shop_coupon_meta", "woocommerce_api_create_coupon" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-24T22:56:26", "date_modified": "2016-05-24T22:56:26", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/146" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks" } ] } }, { "id": 147, "name": "Customer deleted", "status": "active", "topic": "customer.deleted", "resource": "customer", "event": "deleted", "hooks": [ "delete_user" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-24T22:56:30", "date_modified": "2016-05-24T22:56:30", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/147" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks" } ] } } ], "delete": [ { "id": 143, "name": "Webhook created on May 24, 2016 @ 03:20 AM", "status": "active", "topic": "customer.created", "resource": "customer", "event": "created", "hooks": [ "user_register", "woocommerce_created_customer", "woocommerce_api_create_customer" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T20:17:52", "date_modified": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/143" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks" } ] } } ] } ``` ## Retrieve webhook delivery This API lets you retrieve and view a specific webhook delivery. ```http GET /wp-json/wc/v1/webhooks//deliveries/ ``` ```shell curl https://example.com/wp-json/wc/v1/webhooks/142/deliveries/54 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("webhooks/142/deliveries/54") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('webhooks/142/deliveries/54')); ?> ``` ```python print(wcapi.get("webhooks/142/deliveries/54").json()) ``` ```ruby woocommerce.get("webhooks/142/deliveries/54").parsed_response ``` ```json { "id": 54, "duration": "0.40888", "summary": "HTTP 200 OK: ok", "request_method": "POST", "request_url": "http://requestb.in/1g0sxmo1", "request_headers": { "User-Agent": "WooCommerce/2.6.0 Hookshot (WordPress/4.5.2)", "Content-Type": "application/json", "X-WC-Webhook-Source": "http://example.com/", "X-WC-Webhook-Topic": "order.updated", "X-WC-Webhook-Resource": "order", "X-WC-Webhook-Event": "updated", "X-WC-Webhook-Signature": "J72iu7hL93aUt2dFnyOBoBypwbmP6nt6Aor33nnOHxU=", "X-WC-Webhook-ID": 142, "X-WC-Webhook-Delivery-ID": 54 }, "request_body": "{\"order\":{\"id\":118,\"order_number\":118,\"order_key\":\"wc_order_5728e9a347a2d\",\"created_at\":\"2016-05-03T18:10:00Z\",\"updated_at\":\"2016-05-16T03:30:30Z\",\"completed_at\":\"2016-05-16T03:29:19Z\",\"status\":\"completed\",\"currency\":\"BRL\",\"total\":\"14.00\",\"subtotal\":\"4.00\",\"total_line_items_quantity\":2,\"total_tax\":\"0.00\",\"total_shipping\":\"10.00\",\"cart_tax\":\"0.00\",\"shipping_tax\":\"0.00\",\"total_discount\":\"0.00\",\"shipping_methods\":\"Flat Rate\",\"payment_details\":{\"method_id\":\"bacs\",\"method_title\":\"Direct Bank Transfer\",\"paid\":true},\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"},\"note\":\"\",\"customer_ip\":\"127.0.0.1\",\"customer_user_agent\":\"curl/7.47.0\",\"customer_id\":0,\"view_order_url\":\"http://example.com/my-account/view-order/118\",\"line_items\":[{\"id\":8,\"subtotal\":\"4.00\",\"subtotal_tax\":\"0.00\",\"total\":\"4.00\",\"total_tax\":\"0.00\",\"price\":\"2.00\",\"quantity\":2,\"tax_class\":null,\"name\":\"Woo Single #2\",\"product_id\":99,\"sku\":\"12345\",\"meta\":[]}],\"shipping_lines\":[{\"id\":9,\"method_id\":\"flat_rate\",\"method_title\":\"Flat Rate\",\"total\":\"10.00\"}],\"tax_lines\":[],\"fee_lines\":[],\"coupon_lines\":[],\"is_vat_exempt\":false,\"customer\":{\"id\":0,\"email\":\"john.doe@claudiosmweb.com\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"}}}}", "response_code": "200", "response_message": "OK", "response_headers": { "connection": "close", "server": "gunicorn/19.3.0", "date": "Tue, 16 May 2016 03:30:31 GMT", "content-type": "text/html; charset=utf-8", "content-length": "2", "sponsored-by": "https://www.runscope.com", "via": "1.1 vegur" }, "response_body": "ok", "date_created": "2016-05-16T03:30:31", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142/deliveries/54" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142/deliveries" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142" } ] } } ``` :::note View the Webhooks Delivery properties for more details on this response. ::: ## List all webhook deliveries This API helps you view all deliveries from a specific webhook. ```http GET /wp-json/wc/v1/webhooks//deliveries ``` ```shell curl https://example.com/wp-json/wc/v1/webhooks/142/deliveries \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("webhooks/142/deliveries") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('webhooks/142/deliveries')); ?> ``` ```python print(wcapi.get("webhooks/142/deliveries").json()) ``` ```ruby woocommerce.get("webhooks/142/deliveries").parsed_response ``` ```json [ { "id": 54, "duration": "0.40888", "summary": "HTTP 200 OK: ok", "request_method": "POST", "request_url": "http://requestb.in/1g0sxmo1", "request_headers": { "User-Agent": "WooCommerce/2.6.0 Hookshot (WordPress/4.5.2)", "Content-Type": "application/json", "X-WC-Webhook-Source": "http://example.com/", "X-WC-Webhook-Topic": "order.updated", "X-WC-Webhook-Resource": "order", "X-WC-Webhook-Event": "updated", "X-WC-Webhook-Signature": "J72iu7hL93aUt2dFnyOBoBypwbmP6nt6Aor33nnOHxU=", "X-WC-Webhook-ID": 142, "X-WC-Webhook-Delivery-ID": 54 }, "request_body": "{\"order\":{\"id\":118,\"order_number\":118,\"order_key\":\"wc_order_5728e9a347a2d\",\"created_at\":\"2016-05-03T18:10:00Z\",\"updated_at\":\"2016-05-16T03:30:30Z\",\"completed_at\":\"2016-05-16T03:29:19Z\",\"status\":\"completed\",\"currency\":\"BRL\",\"total\":\"14.00\",\"subtotal\":\"4.00\",\"total_line_items_quantity\":2,\"total_tax\":\"0.00\",\"total_shipping\":\"10.00\",\"cart_tax\":\"0.00\",\"shipping_tax\":\"0.00\",\"total_discount\":\"0.00\",\"shipping_methods\":\"Flat Rate\",\"payment_details\":{\"method_id\":\"bacs\",\"method_title\":\"Direct Bank Transfer\",\"paid\":true},\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"},\"note\":\"\",\"customer_ip\":\"127.0.0.1\",\"customer_user_agent\":\"curl/7.47.0\",\"customer_id\":0,\"view_order_url\":\"http://example.com/my-account/view-order/118\",\"line_items\":[{\"id\":8,\"subtotal\":\"4.00\",\"subtotal_tax\":\"0.00\",\"total\":\"4.00\",\"total_tax\":\"0.00\",\"price\":\"2.00\",\"quantity\":2,\"tax_class\":null,\"name\":\"Woo Single #2\",\"product_id\":99,\"sku\":\"12345\",\"meta\":[]}],\"shipping_lines\":[{\"id\":9,\"method_id\":\"flat_rate\",\"method_title\":\"Flat Rate\",\"total\":\"10.00\"}],\"tax_lines\":[],\"fee_lines\":[],\"coupon_lines\":[],\"is_vat_exempt\":false,\"customer\":{\"id\":0,\"email\":\"john.doe@claudiosmweb.com\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"}}}}", "response_code": "200", "response_message": "OK", "response_headers": { "connection": "close", "server": "gunicorn/19.3.0", "date": "Tue, 16 May 2016 03:30:31 GMT", "content-type": "text/html; charset=utf-8", "content-length": "2", "sponsored-by": "https://www.runscope.com", "via": "1.1 vegur" }, "response_body": "ok", "date_created": "2016-05-16T03:30:31", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142/deliveries/54" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142/deliveries" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142" } ] } }, { "id": 53, "duration": "0.7615", "summary": "HTTP 200 OK: ok", "request_method": "POST", "request_url": "http://requestb.in/1g0sxmo1", "request_headers": { "User-Agent": "WooCommerce/2.6.0 Hookshot (WordPress/4.5.2)", "Content-Type": "application/json", "X-WC-Webhook-Source": "http://example.com/", "X-WC-Webhook-Topic": "order.updated", "X-WC-Webhook-Resource": "order", "X-WC-Webhook-Event": "updated", "X-WC-Webhook-Signature": "Z996ccyueeoqdXZFq2ND2ETpsPGrXmWKj+yvQ0c2N1w=", "X-WC-Webhook-ID": 142, "X-WC-Webhook-Delivery-ID": 53 }, "request_body": "{\"order\":{\"id\":118,\"order_number\":118,\"order_key\":\"wc_order_5728e9a347a2d\",\"created_at\":\"2016-05-03T18:10:00Z\",\"updated_at\":\"2016-05-16T03:29:13Z\",\"completed_at\":\"2016-05-16T03:29:19Z\",\"status\":\"completed\",\"currency\":\"BRL\",\"total\":\"14.00\",\"subtotal\":\"4.00\",\"total_line_items_quantity\":2,\"total_tax\":\"0.00\",\"total_shipping\":\"10.00\",\"cart_tax\":\"0.00\",\"shipping_tax\":\"0.00\",\"total_discount\":\"0.00\",\"shipping_methods\":\"Flat Rate\",\"payment_details\":{\"method_id\":\"bacs\",\"method_title\":\"Direct Bank Transfer\",\"paid\":true},\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"},\"note\":\"\",\"customer_ip\":\"127.0.0.1\",\"customer_user_agent\":\"curl/7.47.0\",\"customer_id\":0,\"view_order_url\":\"http://example.com/my-account/view-order/118\",\"line_items\":[{\"id\":8,\"subtotal\":\"4.00\",\"subtotal_tax\":\"0.00\",\"total\":\"4.00\",\"total_tax\":\"0.00\",\"price\":\"2.00\",\"quantity\":2,\"tax_class\":null,\"name\":\"Woo Single #2\",\"product_id\":99,\"sku\":\"12345\",\"meta\":[]}],\"shipping_lines\":[{\"id\":9,\"method_id\":\"flat_rate\",\"method_title\":\"Flat Rate\",\"total\":\"10.00\"}],\"tax_lines\":[],\"fee_lines\":[],\"coupon_lines\":[],\"is_vat_exempt\":false,\"customer\":{\"id\":0,\"email\":\"john.doe@claudiosmweb.com\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"}}}}", "response_code": "200", "response_message": "OK", "response_headers": { "connection": "close", "server": "gunicorn/19.3.0", "date": "Tue, 16 May 2016 03:29:20 GMT", "content-type": "text/html; charset=utf-8", "content-length": "2", "sponsored-by": "https://www.runscope.com", "via": "1.1 vegur" }, "response_body": "ok", "date_created": "2016-05-16T03:29:19", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142/deliveries/53" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142/deliveries" } ], "up": [ { "href": "https://example.com/wp-json/wc/v1/webhooks/142" } ] } } ] ``` --- ## Coupons *Source: apis/rest-api/v2/coupons.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Coupons The coupons API allows you to create, view, update, and delete individual, or a batch, of coupon codes. ## Coupon properties | Attribute | Type | Description | | ----------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | | `id` | integer | Unique identifier for the object. `READ-ONLY` | | `code` | string | Coupon code. `MANDATORY` | | `amount` | string | The amount of discount. Should always be numeric, even if setting a percentage. | | `date_created` | date-time | The date the coupon was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the coupon was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the coupon was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the coupon was last modified, as GMT. `READ-ONLY` | | `discount_type` | string | Determines the type of discount that will be applied. Options: `percent`, `fixed_cart` and `fixed_product`. Default is `fixed_cart`. | | `description` | string | Coupon description. | | `date_expires` | string | The date the coupon expires, in the site's timezone. | | `date_expires_gmt` | string | The date the coupon expires, as GMT. | | `usage_count` | integer | Number of times the coupon has been used already. `READ-ONLY` | | `individual_use` | boolean | If true, the coupon can only be used individually. Other applied coupons will be removed from the cart. Default is `false`. | | `product_ids` | array | List of product IDs the coupon can be used on. | | `excluded_product_ids` | array | List of product IDs the coupon cannot be used on. | | `usage_limit` | integer | How many times the coupon can be used in total. | | `usage_limit_per_user` | integer | How many times the coupon can be used per customer. | | `limit_usage_to_x_items` | integer | Max number of items in the cart the coupon can be applied to. | | `free_shipping` | boolean | If true and if the free shipping method requires a coupon, this coupon will enable free shipping. Default is `false`. | | `product_categories` | array | List of category IDs the coupon applies to. | | `excluded_product_categories` | array | List of category IDs the coupon does not apply to. | | `exclude_sale_items` | boolean | If true, this coupon will not be applied to items that have sale prices. Default is `false`. | | `minimum_amount` | string | Minimum order amount that needs to be in the cart before coupon applies. | | `maximum_amount` | string | Maximum order amount allowed when using the coupon. | | `email_restrictions` | array | List of email addresses that can use this coupon. | | `used_by` | array | List of user IDs (or guest email addresses) that have used the coupon. `READ-ONLY` | | `meta_data` | array | Meta data. See [Coupon - Meta data properties](#coupon---meta-data-properties) | ### Coupon - Meta data properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------- | | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ## Create a coupon This API helps you to create a new coupon. ```http POST /wp-json/wc/v2/coupons ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/coupons \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "code": "10off", "discount_type": "percent", "amount": "10", "individual_use": true, "exclude_sale_items": true, "minimum_amount": "100.00" }' ``` ```javascript const data = { code: "10off", discount_type: "percent", amount: "10", individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" }; WooCommerce.post("coupons", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php '10off', 'discount_type' => 'percent', 'amount' => '10', 'individual_use' => true, 'exclude_sale_items' => true, 'minimum_amount' => '100.00' ]; print_r($woocommerce->post('coupons', $data)); ?> ``` ```python data = { "code": "10off", "discount_type": "percent", "amount": "10", "individual_use": True, "exclude_sale_items": True, "minimum_amount": "100.00" } print(wcapi.post("coupons", data).json()) ``` ```ruby data = { code: "10off", discount_type: "percent", amount: "10", individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" } woocommerce.post("coupons", data).parsed_response ``` ```json { "id": 719, "code": "10off", "amount": "10.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:23:00", "date_modified_gmt": "2017-03-21T18:23:00", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/coupons" } ] } } ``` ## Retrieve a coupon This API lets you retrieve and view a specific coupon by ID. ```http GET /wp-json/wc/v2/coupons/ ``` ```shell curl https://example.com/wp-json/wc/v2/coupons/719 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("coupons/719") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('coupons/719')); ?> ``` ```python print(wcapi.get("coupons/719").json()) ``` ```ruby woocommerce.get("coupons/719").parsed_response ``` ```json { "id": 719, "code": "10off", "amount": "10.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:23:00", "date_modified_gmt": "2017-03-21T18:23:00", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/coupons" } ] } } ``` ## List all coupons This API helps you to list all the coupons that have been created. ```http GET /wp-json/wc/v2/coupons ``` ```shell curl https://example.com/wp-json/wc/v2/coupons \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("coupons") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('coupons')); ?> ``` ```python print(wcapi.get("coupons").json()) ``` ```ruby woocommerce.get("coupons").parsed_response ``` ```json [ { "id": 720, "code": "free shipping", "amount": "0.00", "date_created": "2017-03-21T15:25:02", "date_created_gmt": "2017-03-21T18:25:02", "date_modified": "2017-03-21T15:25:02", "date_modified_gmt": "2017-03-21T18:25:02", "discount_type": "fixed_cart", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": true, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": false, "minimum_amount": "0.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/coupons/720" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/coupons" } ] } }, { "id": 719, "code": "10off", "amount": "10.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:23:00", "date_modified_gmt": "2017-03-21T18:23:00", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/coupons" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | --------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `id`, `include`, `title` and `slug`. Default is `date`. | | `code` | string | Limit result set to resources with a specific code. | ## Update a coupon This API lets you make changes to a coupon. ```http PUT /wp-json/wc/v2/coupons/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/coupons/719 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "amount": "5" }' ``` ```javascript const data = { amount: "5" }; WooCommerce.put("coupons/719", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php '5' ]; print_r($woocommerce->put('coupons/719', $data)); ?> ``` ```python data = { "amount": "5" } print(wcapi.put("coupons/719", data).json()) ``` ```ruby data = { amount: "5" } woocommerce.put("coupons/719", data).parsed_response ``` ```json { "id": 719, "code": "10off", "amount": "5.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:26:16", "date_modified_gmt": "2017-03-21T18:26:16", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/coupons" } ] } } ``` ## Delete a coupon This API helps you delete a coupon. ```http DELETE /wp-json/wc/v2/coupons/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/coupons/719?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("coupons/719", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('coupons/719', ['force' => true])); ?> ``` ```python print(wcapi.delete("coupons/719", params={"force": True}).json()) ``` ```ruby woocommerce.delete("coupons/719", force: true).parsed_response ``` ```json { "id": 719, "code": "10off", "amount": "5.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:26:16", "date_modified_gmt": "2017-03-21T18:26:16", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/coupons" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|--------------------------------------------------------------------------| | `force` | boolean | Use `true` to permanently delete the coupon. Default is `false`. | ## Batch update coupons This API helps you to batch create, update and delete multiple coupons. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/coupons/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/coupons/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "code": "20off", "discount_type": "percent", "amount": "20", "individual_use": true, "exclude_sale_items": true, "minimum_amount": "100.00" }, { "code": "30off", "discount_type": "percent", "amount": "30", "individual_use": true, "exclude_sale_items": true, "minimum_amount": "100.00" } ], "update": [ { "id": 719, "minimum_amount": "50.00" } ], "delete": [ 720 ] }' ``` ```javascript const data = { create: [ { code: "20off", discount_type: "percent", amount: "20", individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" }, { code: "30off", discount_type: "percent", amount: "30", individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" } ], update: [ { id: 719, minimum_amount: "50.00" } ], delete: [ 720 ] }; WooCommerce.post("coupons/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'code' => '20off', 'discount_type' => 'percent', 'amount' => '20', 'individual_use' => true, 'exclude_sale_items' => true, 'minimum_amount' => '100.00' ], [ 'code' => '30off', 'discount_type' => 'percent', 'amount' => '30', 'individual_use' => true, 'exclude_sale_items' => true, 'minimum_amount' => '100.00' ] ], 'update' => [ [ 'id' => 719, 'minimum_amount' => '50.00' ] ], 'delete' => [ 720 ] ]; print_r($woocommerce->post('coupons/batch', $data)); ?> ``` ```python data = { "create": [ { "code": "20off", "discount_type": "percent", "amount": "20", "individual_use": True, "exclude_sale_items": True, "minimum_amount": "100.00" }, { "code": "30off", "discount_type": "percent", "amount": "30", "individual_use": True, "exclude_sale_items": True, "minimum_amount": "100.00" } ], "update": [ { "id": 719, "minimum_amount": "50.00" } ], "delete": [ 720 ] } print(wcapi.post("coupons/batch", data).json()) ``` ```ruby data = { create: [ { code: "20off", discount_type: "percent", amount: "20", individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" }, { code: "30off", discount_type: "percent", amount: "30", individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" } ], update: [ { id: 719, minimum_amount: "50.00" } ], delete: [ 720 ] } woocommerce.post("coupons/batch", data).parsed_response ``` ```json { "create": [ { "id": 721, "code": "20off", "amount": "20.00", "date_created": "2017-03-21T15:27:29", "date_created_gmt": "2017-03-21T18:27:29", "date_modified": "2017-03-21T15:27:29", "date_modified_gmt": "2017-03-21T18:27:29", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/coupons/721" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/coupons" } ] } }, { "id": 722, "code": "30off", "amount": "30.00", "date_created": "2017-03-21T15:27:31", "date_created_gmt": "2017-03-21T18:27:31", "date_modified": "2017-03-21T15:27:31", "date_modified_gmt": "2017-03-21T18:27:31", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/coupons/722" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/coupons" } ] } } ], "update": [ { "id": 719, "code": "10off", "amount": "5.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:27:32", "date_modified_gmt": "2017-03-21T18:27:32", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "50.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/coupons" } ] } } ], "delete": [ { "id": 720, "code": "free shipping", "amount": "0.00", "date_created": "2017-03-21T15:25:02", "date_created_gmt": "2017-03-21T18:25:02", "date_modified": "2017-03-21T15:25:02", "date_modified_gmt": "2017-03-21T18:25:02", "discount_type": "fixed_cart", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": true, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": false, "minimum_amount": "0.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/coupons/720" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/coupons" } ] } } ] } ``` --- ## Customers *Source: apis/rest-api/v2/customers.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Customers The customer API allows you to create, view, update, and delete individual, or a batch, of customers. ## Customer properties | Attribute | Type | Description | | -------------------- | --------- | ---------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | date-time | The date the customer was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the customer was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the customer was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the customer was last modified, as GMT. `READ-ONLY` | | `email` | string | The email address for the customer. `MANDATORY` | | `first_name` | string | Customer first name. | | `last_name` | string | Customer last name. | | `role` | string | Customer role. `READ-ONLY` | | `username` | string | Customer login name. | | `password` | string | Customer password. `WRITE-ONLY` | | `billing` | object | List of billing address data. See [Customer - Billing properties](#customer---billing-properties) | | `shipping` | object | List of shipping address data. See [Customer - Shipping properties](#customer---shipping-properties) | | `is_paying_customer` | bool | Is the customer a paying customer? `READ-ONLY` | | `orders_count` | integer | Quantity of orders made by the customer. `READ-ONLY` | | `total_spent` | string | Total amount spent. `READ-ONLY` | | `avatar_url` | string | Avatar URL. `READ-ONLY` | | `meta_data` | array | Meta data. See [Customer - Meta data properties](#customer---meta-data-properties) | ### Customer - Billing properties | Attribute | Type | Description | | ------------ | ------ | ---------------------------------------------------- | | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1 | | `address_2` | string | Address line 2 | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | ISO code of the country. | | `email` | string | Email address. | | `phone` | string | Phone number. | ### Customer - Shipping properties | Attribute | Type | Description | | ------------ | ------ | ---------------------------------------------------- | | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1 | | `address_2` | string | Address line 2 | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | ISO code of the country. | ### Customer - Meta data properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------- | | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ## Create a customer This API helps you to create a new customer. ```http POST /wp-json/wc/v2/customers ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/customers \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } }' ``` ```javascript const data = { email: "john.doe@example.com", first_name: "John", last_name: "Doe", username: "john.doe", billing: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" } }; WooCommerce.post("customers", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'john.doe@example.com', 'first_name' => 'John', 'last_name' => 'Doe', 'username' => 'john.doe', 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ] ]; print_r($woocommerce->post('customers', $data)); ?> ``` ```python data = { "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } } print(wcapi.post("customers", data).json()) ``` ```ruby data = { email: "john.doe@example.com", first_name: "John", last_name: "Doe", username: "john.doe", billing: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" } } woocommerce.post("customers", data).parsed_response ``` ```json { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:09:30", "date_modified_gmt": "2017-03-21T19:09:30", "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/customers" } ] } } ``` ## Retrieve a customer This API lets you retrieve and view a specific customer by ID. ```http GET /wp-json/wc/v2/customers/ ``` ```shell curl https://example.com/wp-json/wc/v2/customers/25 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("customers/25") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('customers/25')); ?> ``` ```python print(wcapi.get("customers/25").json()) ``` ```ruby woocommerce.get("customers/25").parsed_response ``` ```json { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:09:30", "date_modified_gmt": "2017-03-21T19:09:30", "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/customers" } ] } } ``` ## List all customers This API helps you to view all the customers. ```http GET /wp-json/wc/v2/customers ``` ```shell curl https://example.com/wp-json/wc/v2/customers \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("customers") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('customers')); ?> ``` ```python print(wcapi.get("customers").json()) ``` ```ruby woocommerce.get("customers").parsed_response ``` ```json [ { "id": 26, "date_created": "2017-03-21T16:11:14", "date_created_gmt": "2017-03-21T19:11:14", "date_modified": "2017-03-21T16:11:16", "date_modified_gmt": "2017-03-21T19:11:16", "email": "joao.silva@example.com", "first_name": "João", "last_name": "Silva", "role": "customer", "username": "joao.silva", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "is_paying_customer": false, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/be7b5febff88a2d947c3289e90cdf017?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/customers/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/customers" } ] } }, { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:09:30", "date_modified_gmt": "2017-03-21T19:09:30", "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/customers" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ---------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific IDs. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `asc`. | | `orderby` | string | Sort collection by object attribute. Options: `id`, `include`, `name` and `registered_date`. Default is `name`. | | `email` | string | Limit result set to resources with a specific email. | | `role` | string | Limit result set to resources with a specific role. Options: `all`, `administrator`, `editor`, `author`, `contributor`, `subscriber`, `customer` and `shop_manager`. Default is `customer`. | ## Update a customer This API lets you make changes to a customer. ```http PUT /wp-json/wc/v2/customers/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/customers/25 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "first_name": "James", "billing": { "first_name": "James" }, "shipping": { "first_name": "James" } }' ``` ```javascript const data = { first_name: "James", billing: { first_name: "James" }, shipping: { first_name: "James" } }; WooCommerce.put("customers/25", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'James', 'billing' => [ 'first_name' => 'James' ], 'shipping' => [ 'first_name' => 'James' ] ]; print_r($woocommerce->put('customers/25', $data)); ?> ``` ```python data = { "first_name": "James", "billing": { "first_name": "James" }, "shipping": { "first_name": "James" } } print(wcapi.put("customers/25", data).json()) ``` ```ruby data = { first_name: "James", billing: { first_name: "James" }, shipping: { first_name: "James" } } woocommerce.put("customers/25", data).parsed_response ``` ```json { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:12:28", "date_modified_gmt": "2017-03-21T19:12:28", "email": "john.doe@example.com", "first_name": "James", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/customers" } ] } } ``` ## Delete a customer This API helps you delete a customer. ```http DELETE /wp-json/wc/v2/customers/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/customers/25?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("customers/25", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('customers/25', ['force' => true])); ?> ``` ```python print(wcapi.delete("customers/25", params={"force": True}).json()) ``` ```ruby woocommerce.delete("customers/25", force: true).parsed_response ``` ```json { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:12:28", "date_modified_gmt": "2017-03-21T19:12:28", "email": "john.doe@example.com", "first_name": "James", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/customers" } ] } } ``` #### Available parameters | Parameter | Type | Description | |------------|---------|---------------------------------------------------------------| | `force` | boolean | Required to be `true`, as resource does not support trashing. | | `reassign` | integer | User ID to reassign posts to. | ## Batch update customers This API helps you to batch create, update and delete multiple customers. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/customers/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/customers/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "email": "john.doe2@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe2", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } }, { "email": "joao.silva2@example.com", "first_name": "João", "last_name": "Silva", "username": "joao.silva2", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" } } ], "update": [ { "id": 26, "billing": { "phone": "(11) 1111-1111" } } ], "delete": [ 25 ] }' ``` ```javascript const data = { create: [ { email: "john.doe2@example.com", first_name: "John", last_name: "Doe", username: "john.doe2", billing: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" } }, { email: "joao.silva2@example.com", first_name: "João", last_name: "Silva", username: "joao.silva2", billing: { first_name: "João", last_name: "Silva", company: "", address_1: "Av. Brasil, 432", address_2: "", city: "Rio de Janeiro", state: "RJ", postcode: "12345-000", country: "BR", email: "joao.silva@example.com", phone: "(55) 5555-5555" }, shipping: { first_name: "João", last_name: "Silva", company: "", address_1: "Av. Brasil, 432", address_2: "", city: "Rio de Janeiro", state: "RJ", postcode: "12345-000", country: "BR" } } ], update: [ { id: 26, billing: { phone: "(11) 1111-1111" } } ], delete: [ 25 ] }; WooCommerce.post("customers/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'email' => 'john.doe2@example.com', 'first_name' => 'John', 'last_name' => 'Doe', 'username' => 'john.doe2', 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ] ], [ 'email' => 'joao.silva2@example.com', 'first_name' => 'João', 'last_name' => 'Silva', 'username' => 'joao.silva2', 'billing' => [ 'first_name' => 'João', 'last_name' => 'Silva', 'company' => '', 'address_1' => 'Av. Brasil, 432', 'address_2' => '', 'city' => 'Rio de Janeiro', 'state' => 'RJ', 'postcode' => '12345-000', 'country' => 'BR', 'email' => 'joao.silva@example.com', 'phone' => '(55) 5555-5555' ], 'shipping' => [ 'first_name' => 'João', 'last_name' => 'Silva', 'company' => '', 'address_1' => 'Av. Brasil, 432', 'address_2' => '', 'city' => 'Rio de Janeiro', 'state' => 'RJ', 'postcode' => '12345-000', 'country' => 'BR' ] ] ], 'update' => [ [ 'id' => 26, 'billing' => [ 'phone' => '(11) 1111-1111' ] ] ], 'delete' => [ 25 ] ]; print_r($woocommerce->post('customers/batch', $data)); ?> ``` ```python data = { "create": [ { "email": "john.doe2@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe2", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } }, { "email": "joao.silva2@example.com", "first_name": "João", "last_name": "Silva", "username": "joao.silva2", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" } } ], "update": [ { "id": 26, "billing": { "phone": "(11) 1111-1111" } } ], "delete": [ 25 ] } print(wcapi.post("customers/batch", data).json()) ``` ```ruby data = { create: [ { email: "john.doe2@example.com", first_name: "John", last_name: "Doe", username: "john.doe2", billing: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" } }, { email: "joao.silva2@example.com", first_name: "João", last_name: "Silva", username: "joao.silva2", billing: { first_name: "João", last_name: "Silva", company: "", address_1: "Av. Brasil, 432", address_2: "", city: "Rio de Janeiro", state: "RJ", postcode: "12345-000", country: "BR", email: "joao.silva@example.com", phone: "(55) 5555-5555" }, shipping: { first_name: "João", last_name: "Silva", company: "", address_1: "Av. Brasil, 432", address_2: "", city: "Rio de Janeiro", state: "RJ", postcode: "12345-000", country: "BR" } } ], update: [ { id: 26, billing: { phone: "(11) 1111-1111" } } ], delete: [ 25 ] } woocommerce.post("customers/batch", data).parsed_response ``` ```json { "create": [ { "id": 27, "date_created": "2017-03-21T16:13:58", "date_created_gmt": "2017-03-21T19:13:58", "date_modified": "2017-03-21T16:13:59", "date_modified_gmt": "2017-03-21T19:13:59", "email": "john.doe2@example.com", "first_name": "John", "last_name": "Doe", "role": "customer", "username": "john.doe2", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/6ad0b094bac53a85bb282ccdb3958279?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/customers/27" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/customers" } ] } }, { "id": 28, "date_created": "2017-03-21T16:14:00", "date_created_gmt": "2017-03-21T19:14:00", "date_modified": "2017-03-21T16:14:01", "date_modified_gmt": "2017-03-21T19:14:01", "email": "joao.silva2@example.com", "first_name": "João", "last_name": "Silva", "role": "customer", "username": "joao.silva2", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "is_paying_customer": false, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/ea9ad095f2970f27cbff07e7f5e99453?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/customers/28" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/customers" } ] } } ], "update": [ { "id": 26, "date_created": "2017-03-21T16:11:14", "date_created_gmt": "2017-03-21T19:11:14", "date_modified": "2017-03-21T16:14:03", "date_modified_gmt": "2017-03-21T19:14:03", "email": "joao.silva@example.com", "first_name": "João", "last_name": "Silva", "role": "customer", "username": "joao.silva", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(11) 1111-1111" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "is_paying_customer": false, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/be7b5febff88a2d947c3289e90cdf017?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/customers/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/customers" } ] } } ], "delete": [ { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:12:28", "date_modified_gmt": "2017-03-21T19:12:28", "email": "john.doe@example.com", "first_name": "James", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "orders_count": 0, "total_spent": "0.00", "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/customers" } ] } } ] } ``` ## Retrieve customer downloads This API lets you retrieve customer downloads permissions. ```http GET /wp-json/wc/v2/customers//downloads ``` ```shell curl https://example.com/wp-json/wc/v2/customers/26/downloads \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("customers/26/downloads") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('customers/26/downloads')); ?> ``` ```python print(wcapi.get("customers/26/downloads").json()) ``` ```ruby woocommerce.get("customers/26/downloads").parsed_response ``` ```json [ { "download_id": "91447fd1849316bbc89dfb7e986a6006", "download_url": "https://example.com/?download_file=87&order=wc_order_58d17c18352&email=joao.silva%40example.com&key=91447fd1849316bbc89dfb7e986a6006", "product_id": 87, "product_name": "Woo Album #2", "download_name": "Woo Album #2 – Song 2", "order_id": 723, "order_key": "wc_order_58d17c18352", "downloads_remaining": "3", "access_expires": "never", "access_expires_gmt": "never", "file": { "name": "Song 2", "file": "http://example.com/wp-content/uploads/woocommerce_uploads/2013/06/Song.mp3" }, "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v2/customers/26/downloads" } ], "product": [ { "href": "https://example.com/wp-json/wc/v2/products/87" } ], "order": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } } ] ``` ### Customer downloads properties | Attribute | Type | Description | | --------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------- | | `download_id` | string | Download ID (MD5). `READ-ONLY` | | `download_url` | string | Download file URL. `READ-ONLY` | | `product_id` | integer | Downloadable product ID. `READ-ONLY` | | `product_name` | string | Product name. `READ-ONLY` | | `download_name` | string | Downloadable file name. `READ-ONLY` | | `order_id` | integer | Order ID. `READ-ONLY` | | `order_key` | string | Order key. `READ-ONLY` | | `downloads_remaining` | string | Number of downloads remaining. `READ-ONLY` | | `access_expires` | string | The date when download access expires, in the site's timezone. `READ-ONLY` | | `access_expires_gmt` | string | The date when download access expires, as GMT. `READ-ONLY` | | `file` | object | File details. `READ-ONLY` See [Customers downloads - File properties](#customer-downloads---file-properties) | ### Customer downloads - File properties | Attribute | Type | Description | | --------- | ------ | ---------------------------------------------------- | | `name` | string | File name. `READ-ONLY` | | `file` | string | File URL. `READ-ONLY` | --- ## REST API v2 *Source: apis/rest-api/v2/index.mdx* import DocCardList from '@theme/DocCardList'; Legacy version of the WooCommerce REST API. Use `/wp-json/wc/v2/` endpoints. Consider migrating to v3 for new integrations. --- ## Order notes *Source: apis/rest-api/v2/order-notes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Order notes The order notes API allows you to create, view, and delete individual order notes. Order notes are added by administrators and programmatically to store data about an order, or order events. ## Order note properties | Attribute | Type | Description | | ------------------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | date-time | The date the order note was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the order note was created, as GMT. `READ-ONLY` | | `note` | string | Order note content. `MANDATORY` | | `customer_note` | boolean | If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only. Default is `false`. | ## Create an order note This API helps you to create a new note for an order. ```http POST /wp-json/wc/v2/orders//notes ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/orders/723/notes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "note": "Order ok!!!" }' ``` ```javascript const data = { note: "Order ok!!!" }; WooCommerce.post("orders/723/notes", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Order ok!!!' ]; print_r($woocommerce->post('orders/723/notes', $data)); ?> ``` ```python data = { "note": "Order ok!!!" } print(wcapi.post("orders/723/notes", data).json()) ``` ```ruby data = { note: "Order ok!!!" } woocommerce.post("orders/723/notes", data).parsed_response ``` ```json { "id": 281, "date_created": "2017-03-21T16:46:41", "date_created_gmt": "2017-03-21T19:46:41", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes/281" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } } ``` ## Retrieve an order note This API lets you retrieve and view a specific note from an order. ```http GET /wp-json/wc/v2/orders//notes/ ``` ```shell curl https://example.com/wp-json/wc/v2/orders/723/notes/281 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders/723/notes/281") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders/723/notes/281')); ?> ``` ```python print(wcapi.get("orders/723/notes/281").json()) ``` ```ruby woocommerce.get("orders/723/notes/281").parsed_response ``` ```json { "id": 281, "date_created": "2017-03-21T16:46:41", "date_created_gmt": "2017-03-21T19:46:41", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes/281" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } } ``` ## List all order notes This API helps you to view all the notes from an order. ```http GET /wp-json/wc/v2/orders//notes ``` ```shell curl https://example.com/wp-json/wc/v2/orders/723/notes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders/723/notes") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders/723/notes')); ?> ``` ```python print(wcapi.get("orders/723/notes").json()) ``` ```ruby woocommerce.get("orders/723/notes").parsed_response ``` ```json [ { "id": 281, "date_created": "2017-03-21T16:46:41", "date_created_gmt": "2017-03-21T19:46:41", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes/281" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } }, { "id": 280, "date_created": "2017-03-21T16:16:58", "date_created_gmt": "2017-03-21T19:16:58", "note": "Order status changed from On hold to Completed.", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes/280" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } }, { "id": 279, "date_created": "2017-03-21T16:16:46", "date_created_gmt": "2017-03-21T19:16:46", "note": "Awaiting BACS payment Order status changed from Pending payment to On hold.", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes/279" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `type` | string | Limit result to customers or internal notes. Options: `any`, `customer` and `internal`. Default is `any`. | ## Delete an order note This API helps you delete an order note. ```http DELETE /wp-json/wc/v2/orders//notes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/orders/723/notes/281?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("orders/723/notes/281", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('orders/723/notes/281', ['force' => true])); ?> ``` ```python print(wcapi.delete("orders/723/notes/281", params={"force": True}).json()) ``` ```ruby woocommerce.delete("orders/723/notes/281", force: true).parsed_response ``` ```json { "id": 281, "date_created": "2017-03-21T16:46:41", "date_created_gmt": "2017-03-21T19:46:41", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes/281" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | --- ## Refunds *Source: apis/rest-api/v2/order-refunds.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Refunds The refunds API allows you to create, view, and delete individual refunds. ## Order refund properties | Attribute | Type | Description | |--------------------|-----------|----------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | date-time | The date the order refund was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the order refund was created, as GMT. `READ-ONLY` | | `amount` | string | Refund amount. | | `reason` | string | Reason for refund. | | `refunded_by` | integer | User ID of user who created the refund. | | `meta_data` | array | Meta data. See [Order refund - Meta data properties](#order-refund---meta-data-properties) | | `line_items` | array | Line items data. See [Order refund - Line items properties](#order-refund---line-items-properties) | | `api_refund` | boolean | When true, the payment gateway API is used to generate the refund. Default is `true`. `WRITE-ONLY` | ### Order refund - Meta data properties | Attribute | Type | Description | |-----------|---------|----------------------------------------------------| | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ### Order refund - Line items properties | Attribute | Type | Description | |----------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Item ID. `READ-ONLY` | | `name` | string | Product name. | | `product_id` | integer | Product ID. | | `variation_id` | integer | Variation ID, if applicable. | | `quantity` | integer | Quantity ordered. | | `tax_class` | string | Tax class of product. | | `subtotal` | string | Line subtotal (before discounts). | | `subtotal_tax` | string | Line subtotal tax (before discounts). `READ-ONLY` | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). `READ-ONLY` | | `taxes` | array | Line taxes. See [Order refund line item - Taxes properties](#order-refund-line-item---taxes-properties) `READ-ONLY` | | `meta_data` | array | Meta data. See [Order refund - Meta data properties](#order-refund---meta-data-properties) | | `sku` | string | Product SKU. `READ-ONLY` | | `price` | string | Product price. `READ-ONLY` | #### Order refund line item - Taxes properties | Attribute | Type | Description | |------------|---------|---------------------------------------------------------| | `id` | integer | Tax rate ID. `READ-ONLY` | | `total` | string | Tax total. `READ-ONLY` | | `subtotal` | string | Tax subtotal. `READ-ONLY` | ## Create a refund This API helps you to create a new refund for an order. ```http POST /wp-json/wc/v2/orders//refunds ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/orders/723/refunds \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "amount": "10" }' ``` ```javascript const data = { amount: "10" }; WooCommerce.post("orders/723/refunds", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php '10' ]; print_r($woocommerce->post('orders/723/refunds', $data)); ?> ``` ```python data = { "amount": "10" } print(wcapi.post("orders/723/refunds", data).json()) ``` ```ruby data = { amount: "10" } woocommerce.post("orders/723/refunds", data).parsed_response ``` ```json { "id": 726, "date_created": "2017-03-21T17:07:11", "date_created_gmt": "2017-03-21T20:07:11", "amount": "10.00", "reason": "", "meta_data": [], "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/refunds/726" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } } ``` ## Retrieve a refund This API lets you retrieve and view a specific refund from an order. ```http GET /wp-json/wc/v2/orders//refunds/ ``` ```shell curl https://example.com/wp-json/wc/v2/orders/723/refunds/726 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders/723/refunds/726") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders/723/refunds/726')); ?> ``` ```python print(wcapi.get("orders/723/refunds/726").json()) ``` ```ruby woocommerce.get("orders/723/refunds/726").parsed_response ``` ```json { "id": 726, "date_created": "2017-03-21T17:07:11", "date_created_gmt": "2017-03-21T20:07:11", "amount": "10.00", "reason": "", "meta_data": [], "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/refunds/726" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------| | `dp` | integer | Number of decimal points to use in each resource. | ## List all refunds This API helps you to view all the refunds from an order. ```http GET /wp-json/wc/v2/orders//refunds ``` ```shell curl https://example.com/wp-json/wc/v2/orders/723/refunds \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders/723/refunds") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders/723/refunds')); ?> ``` ```python print(wcapi.get("orders/723/refunds").json()) ``` ```ruby woocommerce.get("orders/723/refunds").parsed_response ``` ```json [ { "id": 726, "date_created": "2017-03-21T17:07:11", "date_created_gmt": "2017-03-21T20:07:11", "amount": "10.00", "reason": "", "refunded_by": 1, "meta_data": [], "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/refunds/726" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } }, { "id": 724, "date_created": "2017-03-21T16:55:37", "date_created_gmt": "2017-03-21T19:55:37", "amount": "9.00", "reason": "", "refunded_by": 1, "meta_data": [], "line_items": [ { "id": 314, "name": "Woo Album #2", "product_id": 87, "variation_id": 0, "quantity": -1, "tax_class": "", "subtotal": "-9.00", "subtotal_tax": "0.00", "total": "-9.00", "total_tax": "0.00", "taxes": [], "meta_data": [ { "id": 2076, "key": "_refunded_item_id", "value": "311" } ], "sku": "", "price": -9 } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/refunds/724" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |------------------|---------|------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `id`, `include`, `title` and `slug`. Default is `date`. | | `parent` | array | Limit result set to those of particular parent IDs. | | `parent_exclude` | array | Limit result set to all items except those of a particular parent ID. | | `dp` | integer | Number of decimal points to use in each resource. Default is `2`. | ## Delete a refund This API helps you delete an order refund. ```http DELETE /wp-json/wc/v2/orders//refunds/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/orders/723/refunds/726?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("orders/723/refunds/726", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('orders/723/refunds/726', ['force' => true])); ?> ``` ```python print(wcapi.delete("orders/723/refunds/726", params={"force": True}).json()) ``` ```ruby woocommerce.delete("orders/723/refunds/726", force: true).parsed_response ``` ```json { "id": 726, "date_created": "2017-03-21T17:07:11", "date_created_gmt": "2017-03-21T20:07:11", "amount": "10.00", "reason": "", "meta_data": [], "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/refunds/726" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | boolean | Required to be `true`, as resource does not support trashing. | --- ## Orders *Source: apis/rest-api/v2/orders.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Orders The orders API allows you to create, view, update, and delete individual, or a batch, of orders. ## Order properties | Attribute | Type | Description | |------------------------|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `parent_id` | integer | Parent order ID. | | `number` | string | Order number. `READ-ONLY` | | `order_key` | string | Order key. `READ-ONLY` | | `created_via` | string | Shows where the order was created. `READ-ONLY` | | `version` | string | Version of WooCommerce which last updated the order. `READ-ONLY` | | `status` | string | Order status. Options: `pending`, `processing`, `on-hold`, `completed`, `cancelled`, `refunded`, `failed` and `trash`. Default is `pending`. | | `currency` | string | Currency the order was created with, in ISO format. Options: `AED`, `AFN`, `ALL`, `AMD`, `ANG`, `AOA`, `ARS`, `AUD`, `AWG`, `AZN`, `BAM`, `BBD`, `BDT`, `BGN`, `BHD`, `BIF`, `BMD`, `BND`, `BOB`, `BRL`, `BSD`, `BTC`, `BTN`, `BWP`, `BYR`, `BZD`, `CAD`, `CDF`, `CHF`, `CLP`, `CNY`, `COP`, `CRC`, `CUC`, `CUP`, `CVE`, `CZK`, `DJF`, `DKK`, `DOP`, `DZD`, `EGP`, `ERN`, `ETB`, `EUR`, `FJD`, `FKP`, `GBP`, `GEL`, `GGP`, `GHS`, `GIP`, `GMD`, `GNF`, `GTQ`, `GYD`, `HKD`, `HNL`, `HRK`, `HTG`, `HUF`, `IDR`, `ILS`, `IMP`, `INR`, `IQD`, `IRR`, `IRT`, `ISK`, `JEP`, `JMD`, `JOD`, `JPY`, `KES`, `KGS`, `KHR`, `KMF`, `KPW`, `KRW`, `KWD`, `KYD`, `KZT`, `LAK`, `LBP`, `LKR`, `LRD`, `LSL`, `LYD`, `MAD`, `MDL`, `MGA`, `MKD`, `MMK`, `MNT`, `MOP`, `MRO`, `MUR`, `MVR`, `MWK`, `MXN`, `MYR`, `MZN`, `NAD`, `NGN`, `NIO`, `NOK`, `NPR`, `NZD`, `OMR`, `PAB`, `PEN`, `PGK`, `PHP`, `PKR`, `PLN`, `PRB`, `PYG`, `QAR`, `RON`, `RSD`, `RUB`, `RWF`, `SAR`, `SBD`, `SCR`, `SDG`, `SEK`, `SGD`, `SHP`, `SLL`, `SOS`, `SRD`, `SSP`, `STD`, `SYP`, `SZL`, `THB`, `TJS`, `TMT`, `TND`, `TOP`, `TRY`, `TTD`, `TWD`, `TZS`, `UAH`, `UGX`, `USD`, `UYU`, `UZS`, `VEF`, `VND`, `VUV`, `WST`, `XAF`, `XCD`, `XOF`, `XPF`, `YER`, `ZAR` and `ZMW`. Default is `USD`. | | `date_created` | date-time | The date the order was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the order was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the order was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the order was last modified, as GMT. `READ-ONLY` | | `discount_total` | string | Total discount amount for the order. `READ-ONLY` | | `discount_tax` | string | Total discount tax amount for the order. `READ-ONLY` | | `shipping_total` | string | Total shipping amount for the order. `READ-ONLY` | | `shipping_tax` | string | Total shipping tax amount for the order. `READ-ONLY` | | `cart_tax` | string | Sum of line item taxes only. `READ-ONLY` | | `total` | string | Grand total. `READ-ONLY` | | `total_tax` | string | Sum of all taxes. `READ-ONLY` | | `prices_include_tax` | boolean | True the prices included tax during checkout. `READ-ONLY` | | `customer_id` | integer | User ID who owns the order. 0 for guests. Default is `0`. | | `customer_ip_address` | string | Customer's IP address. `READ-ONLY` | | `customer_user_agent` | string | User agent of the customer. `READ-ONLY` | | `customer_note` | string | Note left by customer during checkout. | | `billing` | object | Billing address. See [Order - Billing properties](#order---billing-properties) | | `shipping` | object | Shipping address. See [Order - Shipping properties](#order---shipping-properties) | | `payment_method` | string | Payment method ID. | | `payment_method_title` | string | Payment method title. | | `transaction_id` | string | Unique transaction ID. | | `date_paid` | date-time | The date the order was paid, in the site's timezone. `READ-ONLY` | | `date_paid_gmt` | date-time | The date the order was paid, as GMT. `READ-ONLY` | | `date_completed` | date-time | The date the order was completed, in the site's timezone. `READ-ONLY` | | `date_completed_gmt` | date-time | The date the order was completed, as GMT. `READ-ONLY` | | `cart_hash` | string | MD5 hash of cart items to ensure orders are not modified. `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | | `line_items` | array | Line items data. See [Order - Line items properties](#order---line-items-properties) | | `tax_lines` | array | Tax lines data. See [Order - Tax lines properties](#order---tax-lines-properties) `READ-ONLY` | | `shipping_lines` | array | Shipping lines data. See [Order - Shipping lines properties](#order---shipping-lines-properties) | | `fee_lines` | array | Fee lines data. See [Order - Fee lines properties](#order---fee-lines-properties) | | `coupon_lines` | array | Coupons line data. See [Order - Coupon lines properties](#order---coupon-lines-properties) | | `refunds` | array | List of refunds. See [Order - Refunds properties](#order---refunds-properties) `READ-ONLY` | | `set_paid` | boolean | Define if the order is paid. It will set the status to processing and reduce stock items. Default is `false`. `WRITE-ONLY` | ### Order - Billing properties | Attribute | Type | Description | | ------------ | ------ | ---------------------------------------------------- | | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1 | | `address_2` | string | Address line 2 | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | Country code in ISO 3166-1 alpha-2 format. | | `email` | string | Email address. | | `phone` | string | Phone number. | ### Order - Shipping properties | Attribute | Type | Description | | ------------ | ------ | ---------------------------------------------------- | | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1 | | `address_2` | string | Address line 2 | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | Country code in ISO 3166-1 alpha-2 format. | ### Order - Meta data properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------- | | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ### Order - Line items properties | Attribute | Type | Description | | -------------- | ------- | ------------------------------------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `name` | string | Product name. | | `parent_name` | string or null | Parent product name if the product is a variation; otherwise `null`. | | `product_id` | integer | Product ID. | | `variation_id` | integer | Variation ID, if applicable. | | `quantity` | integer | Quantity ordered. | | `tax_class` | integer | Tax class of product. | | `subtotal` | string | Line subtotal (before discounts). | | `subtotal_tax` | string | Line subtotal tax (before discounts). `READ-ONLY` | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). `READ-ONLY` | | `taxes` | array | Line taxes. See [Order - Taxes properties](#order---taxes-properties) `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | | `sku` | string | Product SKU. `READ-ONLY` | | `price` | string | Product price. `READ-ONLY` | ### Order - Tax lines properties | Attribute | Type | Description | | -------------------- | ------- | ----------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `rate_code` | string | Tax rate code. `READ-ONLY` | | `rate_id` | string | Tax rate ID. `READ-ONLY` | | `label` | string | Tax rate label. `READ-ONLY` | | `compound` | boolean | Show if is a compound tax rate. `READ-ONLY` | | `tax_total` | string | Tax total (not including shipping taxes). `READ-ONLY` | | `shipping_tax_total` | string | Shipping tax total. `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | ### Order - Shipping lines properties | Attribute | Type | Description | | -------------- | ------- | ------------------------------------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `method_title` | string | Shipping method name. | | `method_id` | string | Shipping method ID. | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). `READ-ONLY` | | `taxes` | array | Line taxes. See [Order - Taxes properties](#order---taxes-properties) `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | ### Order - Fee lines properties | Attribute | Type | Description | | ------------ | ------- | ------------------------------------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `name` | string | Fee name. | | `tax_class` | string | Tax class of fee. | | `tax_status` | string | Tax status of fee. Options: `taxable` and `none`. | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). `READ-ONLY` | | `taxes` | array | Line taxes. See [Order - Taxes properties](#order---taxes-properties) `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | ### Order - Coupon lines properties | Attribute | Type | Description | | -------------- | ------- | -------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `code` | string | Coupon code. | | `discount` | string | Discount total. | | `discount_tax` | string | Discount total tax. `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | ### Order - Refunds properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------------- | | `id` | integer | Refund ID. `READ-ONLY` | | `reason` | string | Refund reason. `READ-ONLY` | | `total` | string | Refund total. `READ-ONLY` | ### Order - Taxes properties | Attribute | Type | Description | |----------------------|---------|-------------------------------------------------------------------------------------| | `id` | integer | Item ID. `READ-ONLY` | | `rate_code` | string | Tax rate code. `READ-ONLY` | | `rate_id` | string | Tax rate ID. `READ-ONLY` | | `label` | string | Tax rate label. `READ-ONLY` | | `compound` | boolean | Show if is a compound tax rate. `READ-ONLY` | | `tax_total` | string | Tax total (not including shipping taxes). `READ-ONLY` | | `shipping_tax_total` | string | Shipping tax total. `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | ## Create an order This API helps you to create a new order. ```http POST /wp-json/wc/v2/orders ``` > Example of create a paid order: ```shell curl -X POST https://example.com/wp-json/wc/v2/orders \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": true, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 93, "quantity": 2 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "10.00" } ] }' ``` ```javascript const data = { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", set_paid: true, billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 93, quantity: 2 }, { product_id: 22, variation_id: 23, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "10.00" } ] }; WooCommerce.post("orders", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'bacs', 'payment_method_title' => 'Direct Bank Transfer', 'set_paid' => true, 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ], 'line_items' => [ [ 'product_id' => 93, 'quantity' => 2 ], [ 'product_id' => 22, 'variation_id' => 23, 'quantity' => 1 ] ], 'shipping_lines' => [ [ 'method_id' => 'flat_rate', 'method_title' => 'Flat Rate', 'total' => '10.00' ] ] ]; print_r($woocommerce->post('orders', $data)); ?> ``` ```python data = { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": True, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 93, "quantity": 2 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": '10.00' } ] } print(wcapi.post("orders", data).json()) ``` ```ruby data = { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", set_paid: true, billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 93, quantity: 2 }, { product_id: 22, variation_id: 23, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: '10.00' } ] } woocommerce.post("orders", data).parsed_response ``` ```json { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "processing", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:28:08", "date_modified_gmt": "2017-03-22T19:28:08", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": null, "date_completed_gmt": null, "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders" } ] } } ``` ## Retrieve an order This API lets you retrieve and view a specific order. ```http GET /wp-json/wc/v2/orders/ ``` ```shell curl https://example.com/wp-json/wc/v2/orders/727 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders/727") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders/727')); ?> ``` ```python print(wcapi.get("orders/727").json()) ``` ```ruby woocommerce.get("orders/727").parsed_response ``` ```json { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "processing", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:28:08", "date_modified_gmt": "2017-03-22T19:28:08", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": null, "date_completed_gmt": null, "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------| | `dp` | string | Number of decimal points to use in each resource. | ## List all orders This API helps you to view all the orders. ```http GET /wp-json/wc/v2/orders ``` ```shell curl https://example.com/wp-json/wc/v2/orders \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("orders") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('orders')); ?> ``` ```python print(wcapi.get("orders").json()) ``` ```ruby woocommerce.get("orders").parsed_response ``` ```json [ { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "processing", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:28:08", "date_modified_gmt": "2017-03-22T19:28:08", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": null, "date_completed_gmt": null, "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" }, { "id": 13109, "key": "_order_stock_reduced", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders" } ] } }, { "id": 723, "parent_id": 0, "number": "723", "order_key": "wc_order_58d17c18352", "created_via": "checkout", "version": "3.0.0", "status": "completed", "currency": "USD", "date_created": "2017-03-21T16:16:00", "date_created_gmt": "2017-03-21T19:16:00", "date_modified": "2017-03-21T16:54:51", "date_modified_gmt": "2017-03-21T19:54:51", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "0.00", "total": "39.00", "total_tax": "0.00", "prices_include_tax": false, "customer_id": 26, "customer_ip_address": "127.0.0.1", "customer_user_agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:52.0) gecko/20100101 firefox/52.0", "customer_note": "", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(11) 1111-1111" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "payment_method": "bacs", "payment_method_title": "Direct bank transfer", "transaction_id": "", "date_paid": null, "date_paid_gmt": null, "date_completed": "2017-03-21T16:54:51", "date_completed_gmt": "2017-03-21T19:54:51", "cart_hash": "5040ce7273261e31d8bcf79f9be3d279", "meta_data": [ { "id": 13023, "key": "_download_permissions_granted", "value": "yes" } ], "line_items": [ { "id": 311, "name": "Woo Album #2", "product_id": 87, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "9.00", "subtotal_tax": "0.00", "total": "9.00", "total_tax": "0.00", "taxes": [], "meta_data": [], "sku": "", "price": 9 }, { "id": 313, "name": "Woo Ninja", "product_id": 34, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "20.00", "subtotal_tax": "0.00", "total": "20.00", "total_tax": "0.00", "taxes": [], "meta_data": [], "sku": "", "price": 20 } ], "tax_lines": [], "shipping_lines": [ { "id": 312, "method_title": "Flat rate", "method_id": "flat_rate:25", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [ { "id": 2057, "key": "Items", "value": "Woo Album #2 × 1" } ] } ], "fee_lines": [], "coupon_lines": [], "refunds": [ { "id": 726, "refund": "", "total": "-10.00" }, { "id": 724, "refund": "", "total": "-9.00" } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders" } ], "customer": [ { "href": "https://example.com/wp-json/wc/v2/customers/26" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ---------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `id`, `include`, `title` and `slug`. Default is `date`. | | `parent` | array | Limit result set to those of particular parent IDs. | | `parent_exclude` | array | Limit result set to all items except those of a particular parent ID. | | `status` | string | Limit result set to orders assigned a specific status. Options: `any`, `pending`, `processing`, `on-hold`, `completed`, `cancelled`, `refunded` and `failed`. Default is `any`. | | `customer` | integer | Limit result set to orders assigned a specific customer. | | `product` | integer | Limit result set to orders assigned a specific product. | | `dp` | integer | Number of decimal points to use in each resource. Default is `2`. | ## Update an Order This API lets you make changes to an order. ### HTTP Request ```http PUT /wp-json/wc/v2/orders/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/orders/727 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "status": "completed" }' ``` ```javascript const data = { status: "completed" }; WooCommerce.put("orders/727", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'completed' ]; print_r($woocommerce->put('orders/727', $data)); ?> ``` ```python data = { "status": "completed" } print(wcapi.put("orders/727", data).json()) ``` ```ruby data = { status: "completed" } woocommerce.put("orders/727", data).parsed_response ``` ```json { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "completed", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:30:35", "date_modified_gmt": "2017-03-22T19:30:35", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": "2017-03-22T16:30:35", "date_completed_gmt": "2017-03-22T19:30:35", "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" }, { "id": 13109, "key": "_order_stock_reduced", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders" } ] } } ``` ## Delete an order This API helps you delete an order. ```http DELETE /wp-json/wc/v2/orders/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/orders/727?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("orders/727", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('orders/727', ['force' => true])); ?> ``` ```python print(wcapi.delete("orders/727", params={"force": True}).json()) ``` ```ruby woocommerce.delete("orders/727", force: true).parsed_response ``` ```json { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "completed", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:30:35", "date_modified_gmt": "2017-03-22T19:30:35", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": "2017-03-22T16:30:35", "date_completed_gmt": "2017-03-22T19:30:35", "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" }, { "id": 13109, "key": "_order_stock_reduced", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|-------------------------------------------------------------------------| | `force` | string | Use `true` whether to permanently delete the order, Default is `false`. | ## Batch update orders This API helps you to batch create, update and delete multiple orders. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/orders/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/orders/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 79, "quantity": 1 }, { "product_id": 93, "quantity": 1 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "30.00" } ] }, { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": true, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 22, "variation_id": 23, "quantity": 1 }, { "product_id": 22, "variation_id": 24, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "20.00" } ] } ], "update": [ { "id": 727, "shipping_methods": "Local Delivery" } ], "delete": [ 723 ] }' ``` ```javascript const data = { create: [ { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 79, quantity: 1 }, { product_id: 93, quantity: 1 }, { product_id: 22, variation_id: 23, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "30.00" } ] }, { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", set_paid: true, billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 22, variation_id: 23, quantity: 1 }, { product_id: 22, variation_id: 24, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "20.00" } ] } ], update: [ { id: 727, shipping_methods: "Local Delivery" } ], delete: [ 723 ] }; WooCommerce.post("orders/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'payment_method' => 'bacs', 'payment_method_title' => 'Direct Bank Transfer', 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ], 'line_items' => [ [ 'product_id' => 79, 'quantity' => 1 ], [ 'product_id' => 93, 'quantity' => 1 ], [ 'product_id' => 22, 'variation_id' => 23, 'quantity' => 1 ] ], 'shipping_lines' => [ [ 'method_id' => 'flat_rate', 'method_title' => 'Flat Rate', 'total' => '30.00' ] ] ], [ 'payment_method' => 'bacs', 'payment_method_title' => 'Direct Bank Transfer', 'set_paid' => true, 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ], 'line_items' => [ [ 'product_id' => 22, 'variation_id' => 23, 'quantity' => 1 ], [ 'product_id' => 22, 'variation_id' => 24, 'quantity' => 1 ] ], 'shipping_lines' => [ [ 'method_id' => 'flat_rate', 'method_title' => 'Flat Rate', 'total' => '20.00' ] ] ] ], 'update' => [ [ 'id' => 727, 'shipping_methods' => 'Local Delivery' ] ], 'delete' => [ 723 ] ]; print_r($woocommerce->post('orders/batch', $data)); ?> ``` ```python data = { "create": [ { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 79, "quantity": 1 }, { "product_id": 93, "quantity": 1 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "30.00" } ] }, { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": True, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 22, "variation_id": 23, "quantity": 1 }, { "product_id": 22, "variation_id": 24, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "20.00" } ] } ], "update": [ { "id": 727, "shipping_methods": "Local Delivery" } ], "delete": [ 723 ] } print(wcapi.post("orders/batch", data).json()) ``` ```ruby data = { create: [ { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 79, quantity: 1 }, { product_id: 93, quantity: 1 }, { product_id: 22, variation_id: 23, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "30.00" } ] }, { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", set_paid: true, billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 22, variation_id: 23, quantity: 1 }, { product_id: 22, variation_id: 24, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "20.00" } ] } ], update: [ { id: 727, shipping_methods: "Local Delivery" } ], delete: [ 723 ] } woocommerce.post("orders/batch", data).parsed_response ``` ```json { "create": [ { "id": 728, "parent_id": 0, "number": "728", "order_key": "wc_order_58d2d18e580", "created_via": "rest-api", "version": "3.0.0", "status": "pending", "currency": "USD", "date_created": "2017-03-22T16:33:34", "date_created_gmt": "2017-03-22T19:33:34", "date_modified": "2017-03-22T16:33:34", "date_modified_gmt": "2017-03-22T19:33:34", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "30.00", "shipping_tax": "0.00", "cart_tax": "2.25", "total": "62.25", "total_tax": "2.25", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": null, "date_paid_gmt": null, "date_completed": null, "date_completed_gmt": null, "cart_hash": "", "meta_data": [], "line_items": [ { "id": 319, "name": "Woo Logo", "product_id": 79, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "15.00", "subtotal_tax": "1.13", "total": "15.00", "total_tax": "1.13", "taxes": [ { "id": 75, "total": "1.125", "subtotal": "1.125" } ], "meta_data": [], "sku": "", "price": 15 }, { "id": 320, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "3.00", "subtotal_tax": "0.23", "total": "3.00", "total_tax": "0.23", "taxes": [ { "id": 75, "total": "0.225", "subtotal": "0.225" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 321, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2133, "key": "pa_color", "value": "black" }, { "id": 2134, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 323, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "2.25", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 322, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "30.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/728" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders" } ] } }, { "id": 729, "parent_id": 0, "number": "729", "order_key": "wc_order_58d2d196171", "created_via": "rest-api", "version": "3.0.0", "status": "processing", "currency": "USD", "date_created": "2017-03-22T16:33:42", "date_created_gmt": "2017-03-22T19:33:42", "date_modified": "2017-03-22T16:33:47", "date_modified_gmt": "2017-03-22T19:33:47", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "20.00", "shipping_tax": "0.00", "cart_tax": "2.40", "total": "54.40", "total_tax": "2.40", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:33:47", "date_paid_gmt": "2017-03-22T19:33:47", "date_completed": null, "date_completed_gmt": null, "cart_hash": "", "meta_data": [ { "id": 13198, "key": "_download_permissions_granted", "value": "yes" } ], "line_items": [ { "id": 324, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2153, "key": "pa_color", "value": "black" }, { "id": 2154, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 }, { "id": 325, "name": "Ship Your Idea – Color: Green, Size: S Test", "product_id": 22, "variation_id": 24, "quantity": 1, "tax_class": "", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": "1.5", "subtotal": "1.5" } ], "meta_data": [ { "id": 2164, "key": "pa_color", "value": "green" }, { "id": 2165, "key": "size", "value": "S Test" } ], "sku": "", "price": 20 } ], "tax_lines": [ { "id": 327, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "2.40", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 326, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "20.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/729" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders" } ] } } ], "update": [ { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "completed", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:30:35", "date_modified_gmt": "2017-03-22T19:30:35", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": "2017-03-22T16:30:35", "date_completed_gmt": "2017-03-22T19:30:35", "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" }, { "id": 13109, "key": "_order_stock_reduced", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders" } ] } } ], "delete": [ { "id": 723, "parent_id": 0, "number": "723", "order_key": "wc_order_58d17c18352", "created_via": "checkout", "version": "3.0.0", "status": "completed", "currency": "USD", "date_created": "2017-03-21T16:16:00", "date_created_gmt": "2017-03-21T19:16:00", "date_modified": "2017-03-21T16:54:51", "date_modified_gmt": "2017-03-21T19:54:51", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "0.00", "total": "39.00", "total_tax": "0.00", "prices_include_tax": false, "customer_id": 26, "customer_ip_address": "127.0.0.1", "customer_user_agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:52.0) gecko/20100101 firefox/52.0", "customer_note": "", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(11) 1111-1111" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "payment_method": "bacs", "payment_method_title": "Direct bank transfer", "transaction_id": "", "date_paid": null, "date_paid_gmt": null, "date_completed": "2017-03-21T16:54:51", "date_completed_gmt": "2017-03-21T19:54:51", "cart_hash": "5040ce7273261e31d8bcf79f9be3d279", "meta_data": [ { "id": 13023, "key": "_download_permissions_granted", "value": "yes" } ], "line_items": [ { "id": 311, "name": "Woo Album #2", "product_id": 87, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "9.00", "subtotal_tax": "0.00", "total": "9.00", "total_tax": "0.00", "taxes": [], "meta_data": [], "sku": "", "price": 9 }, { "id": 313, "name": "Woo Ninja", "product_id": 34, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "20.00", "subtotal_tax": "0.00", "total": "20.00", "total_tax": "0.00", "taxes": [], "meta_data": [], "sku": "", "price": 20 } ], "tax_lines": [], "shipping_lines": [ { "id": 312, "method_title": "Flat rate", "method_id": "flat_rate:25", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [ { "id": 2057, "key": "Items", "value": "Woo Album #2 × 1" } ] } ], "fee_lines": [], "coupon_lines": [], "refunds": [ { "id": 726, "refund": "", "total": "-10.00" }, { "id": 724, "refund": "", "total": "-9.00" } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/orders/723" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/orders" } ], "customer": [ { "href": "https://example.com/wp-json/wc/v2/customers/26" } ] } } ] } ``` --- ## Payment gateways *Source: apis/rest-api/v2/payment-gateways.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Payment gateways The payment gateways API allows you to view, and update individual payment gateways. Results are not paginated - all gateways will be returned. ## Payment gateway properties | Attribute | Type | Description | | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------- | | `id` | string | Payment gateway ID. `READ-ONLY` | | `title` | string | Payment gateway title on checkout. | | `description` | string | Payment gateway description on checkout. | | `order` | integer | Payment gateway sort order. | | `enabled` | boolean | Payment gateway enabled status. | | `method_title` | string | Payment gateway method title. `READ-ONLY` | | `method_description` | string | Payment gateway method description. `READ-ONLY` | | `settings` | object | Payment gateway settings. See [Payment gateway - Settings properties](#payment-gateway---settings-properties) | ### Payment gateway - Settings properties | Attribute | Type | Description | | ------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | string | A unique identifier for the setting. `READ-ONLY` | | `label` | string | A human readable label for the setting used in interfaces. `READ-ONLY` | | `description` | string | A human readable description for the setting used in interfaces. `READ-ONLY` | | `type` | string | Type of setting. Options: `text`, `email`, `number`, `color`, `password`, `textarea`, `select`, `multiselect`, `radio`, `image_width` and `checkbox`. `READ-ONLY` | | `value` | string | Setting value. | | `default` | string | Default value for the setting. `READ-ONLY` | | `tip` | string | Additional help text shown to the user about the setting. `READ-ONLY` | | `placeholder` | string | Placeholder text to be displayed in text inputs. `READ-ONLY` | ## Retrieve a payment gateway This API lets you retrieve and view a specific payment gateway. ```http GET /wp-json/wc/v2/payment_gateways/ ``` ```shell curl https://example.com/wp-json/wc/v2/payment_gateways/bacs \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("payment_gateways/bacs") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('payment_gateways/bacs')); ?> ``` ```python print(wcapi.get("payment_gateways/bacs").json()) ``` ```ruby woocommerce.get("payment_gateways/bacs").parsed_response ``` ```json { "id": "bacs", "title": "Direct bank transfer", "description": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "order": 0, "enabled": true, "method_title": "BACS", "method_description": "Allows payments by BACS, more commonly known as direct bank/wire transfer.", "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Direct bank transfer", "default": "Direct bank transfer", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "instructions": { "id": "instructions", "label": "Instructions", "description": "Instructions that will be added to the thank you page and emails.", "type": "textarea", "value": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "default": "", "tip": "Instructions that will be added to the thank you page and emails.", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways/bacs" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways" } ] } } ``` ## List all payment gateways This API helps you to view all the payment gateways. ```http GET /wp-json/wc/v2/payment_gateways ``` ```shell curl https://example.com/wp-json/wc/v2/payment_gateways \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("payment_gateways") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('payment_gateways')); ?> ``` ```python print(wcapi.get("payment_gateways").json()) ``` ```ruby woocommerce.get("payment_gateways").parsed_response ``` ```json [ { "id": "bacs", "title": "Direct bank transfer", "description": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "order": 0, "enabled": true, "method_title": "BACS", "method_description": "Allows payments by BACS, more commonly known as direct bank/wire transfer.", "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Direct bank transfer", "default": "Direct bank transfer", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "instructions": { "id": "instructions", "label": "Instructions", "description": "Instructions that will be added to the thank you page and emails.", "type": "textarea", "value": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "default": "", "tip": "Instructions that will be added to the thank you page and emails.", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways/bacs" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways" } ] } }, { "id": "cheque", "title": "Check payments", "description": "Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.", "order": 1, "enabled": false, "method_title": "Check payments", "method_description": "Allows check payments. Why would you take checks in this day and age? Well you probably wouldn't but it does allow you to make test purchases for testing order emails and the 'success' pages etc.", "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Check payments", "default": "Check payments", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "instructions": { "id": "instructions", "label": "Instructions", "description": "Instructions that will be added to the thank you page and emails.", "type": "textarea", "value": "", "default": "", "tip": "Instructions that will be added to the thank you page and emails.", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways/cheque" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways" } ] } }, { "id": "cod", "title": "Cash on delivery", "description": "Pay with cash upon delivery.", "order": 2, "enabled": false, "method_title": "Cash on delivery", "method_description": "Have your customers pay with cash (or by other means) upon delivery.", "settings": { "title": { "id": "title", "label": "Title", "description": "Payment method description that the customer will see on your checkout.", "type": "text", "value": "Cash on delivery", "default": "Cash on delivery", "tip": "Payment method description that the customer will see on your checkout.", "placeholder": "" }, "instructions": { "id": "instructions", "label": "Instructions", "description": "Instructions that will be added to the thank you page.", "type": "textarea", "value": "", "default": "Pay with cash upon delivery.", "tip": "Instructions that will be added to the thank you page.", "placeholder": "" }, "enable_for_methods": { "id": "enable_for_methods", "label": "Enable for shipping methods", "description": "If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.", "type": "multiselect", "value": "", "default": "", "tip": "If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.", "placeholder": "", "options": { "flat_rate": "Flat rate", "free_shipping": "Free shipping", "local_pickup": "Local pickup" } }, "enable_for_virtual": { "id": "enable_for_virtual", "label": "Accept COD if the order is virtual", "description": "", "type": "checkbox", "value": "yes", "default": "yes", "tip": "", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways/cod" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways" } ] } }, { "id": "paypal", "title": "PayPal", "description": "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account.", "order": 3, "enabled": true, "method_title": "PayPal", "method_description": "PayPal Standard sends customers to PayPal to enter their payment information. PayPal IPN requires fsockopen/cURL support to update order statuses after payment. Check the system status page for more details.", "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "PayPal", "default": "PayPal", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "email": { "id": "email", "label": "PayPal email", "description": "Please enter your PayPal email address; this is needed in order to take payment.", "type": "email", "value": "me@example.com", "default": "me@example.com", "tip": "Please enter your PayPal email address; this is needed in order to take payment.", "placeholder": "you@youremail.com" }, "testmode": { "id": "testmode", "label": "Enable PayPal sandbox", "description": "PayPal sandbox can be used to test payments. Sign up for a developer account.", "type": "checkbox", "value": "yes", "default": "no", "tip": "PayPal sandbox can be used to test payments. Sign up for a developer account.", "placeholder": "" }, "debug": { "id": "debug", "label": "Enable logging", "description": "Log PayPal events, such as IPN requests, inside /var/www/woocommerce/wp-content/uploads/wc-logs/paypal-de01f7c6894774e7ac8e4207bb8bac2f.log", "type": "checkbox", "value": "yes", "default": "no", "tip": "Log PayPal events, such as IPN requests, inside /var/www/woocommerce/wp-content/uploads/wc-logs/paypal-de01f7c6894774e7ac8e4207bb8bac2f.log", "placeholder": "" }, "receiver_email": { "id": "receiver_email", "label": "Receiver email", "description": "If your main PayPal email differs from the PayPal email entered above, input your main receiver email for your PayPal account here. This is used to validate IPN requests.", "type": "email", "value": "me@example.com", "default": "", "tip": "If your main PayPal email differs from the PayPal email entered above, input your main receiver email for your PayPal account here. This is used to validate IPN requests.", "placeholder": "you@youremail.com" }, "identity_token": { "id": "identity_token", "label": "PayPal identity token", "description": "Optionally enable \"Payment Data Transfer\" (Profile > Profile and Settings > My Selling Tools > Website Preferences) and then copy your identity token here. This will allow payments to be verified without the need for PayPal IPN.", "type": "text", "value": "", "default": "", "tip": "Optionally enable \"Payment Data Transfer\" (Profile > Profile and Settings > My Selling Tools > Website Preferences) and then copy your identity token here. This will allow payments to be verified without the need for PayPal IPN.", "placeholder": "" }, "invoice_prefix": { "id": "invoice_prefix", "label": "Invoice prefix", "description": "Please enter a prefix for your invoice numbers. If you use your PayPal account for multiple stores ensure this prefix is unique as PayPal will not allow orders with the same invoice number.", "type": "text", "value": "WC-", "default": "WC-", "tip": "Please enter a prefix for your invoice numbers. If you use your PayPal account for multiple stores ensure this prefix is unique as PayPal will not allow orders with the same invoice number.", "placeholder": "" }, "send_shipping": { "id": "send_shipping", "label": "Send shipping details to PayPal instead of billing.", "description": "PayPal allows us to send one address. If you are using PayPal for shipping labels you may prefer to send the shipping address rather than billing.", "type": "checkbox", "value": "no", "default": "no", "tip": "PayPal allows us to send one address. If you are using PayPal for shipping labels you may prefer to send the shipping address rather than billing.", "placeholder": "" }, "address_override": { "id": "address_override", "label": "Enable \"address_override\" to prevent address information from being changed.", "description": "PayPal verifies addresses therefore this setting can cause errors (we recommend keeping it disabled).", "type": "checkbox", "value": "no", "default": "no", "tip": "PayPal verifies addresses therefore this setting can cause errors (we recommend keeping it disabled).", "placeholder": "" }, "paymentaction": { "id": "paymentaction", "label": "Payment action", "description": "Choose whether you wish to capture funds immediately or authorize payment only.", "type": "select", "value": "sale", "default": "sale", "tip": "Choose whether you wish to capture funds immediately or authorize payment only.", "placeholder": "", "options": { "sale": "Capture", "authorization": "Authorize" } }, "page_style": { "id": "page_style", "label": "Page style", "description": "Optionally enter the name of the page style you wish to use. These are defined within your PayPal account. This affects classic PayPal checkout screens.", "type": "text", "value": "", "default": "", "tip": "Optionally enter the name of the page style you wish to use. These are defined within your PayPal account. This affects classic PayPal checkout screens.", "placeholder": "Optional" }, "image_url": { "id": "image_url", "label": "Image url", "description": "Optionally enter the URL to a 150x50px image displayed as your logo in the upper left corner of the PayPal checkout pages.", "type": "text", "value": "", "default": "", "tip": "Optionally enter the URL to a 150x50px image displayed as your logo in the upper left corner of the PayPal checkout pages.", "placeholder": "Optional" }, "api_username": { "id": "api_username", "label": "API username", "description": "Get your API credentials from PayPal.", "type": "text", "value": "", "default": "", "tip": "Get your API credentials from PayPal.", "placeholder": "Optional" }, "api_password": { "id": "api_password", "label": "API password", "description": "Get your API credentials from PayPal.", "type": "password", "value": "", "default": "", "tip": "Get your API credentials from PayPal.", "placeholder": "Optional" }, "api_signature": { "id": "api_signature", "label": "API signature", "description": "Get your API credentials from PayPal.", "type": "text", "value": "", "default": "", "tip": "Get your API credentials from PayPal.", "placeholder": "Optional" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways/paypal" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways" } ] } } ] ``` ## Update a payment gateway This API lets you make changes to a payment gateway. ```http PUT /wp-json/wc/v2/payment_gateways/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/payment_gateways/bacs \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "enabled": false }' ``` ```javascript const data = { enabled: false }; WooCommerce.put("payment_gateways/bacs", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php false ]; print_r($woocommerce->put('payment_gateways/bacs', $data)); ?> ``` ```python data = { "enabled": False } print(wcapi.put("payment_gateways/bacs", data).json()) ``` ```ruby data = { enabled: false } woocommerce.put("payment_gateways/bacs", data).parsed_response ``` ```json { "id": "bacs", "title": "Direct bank transfer", "description": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "order": 0, "enabled": false, "method_title": "BACS", "method_description": "Allows payments by BACS, more commonly known as direct bank/wire transfer.", "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Direct bank transfer", "default": "Direct bank transfer", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "instructions": { "id": "instructions", "label": "Instructions", "description": "Instructions that will be added to the thank you page and emails.", "type": "textarea", "value": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "default": "", "tip": "Instructions that will be added to the thank you page and emails.", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways/bacs" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/payment_gateways" } ] } } ``` --- ## Product attribute terms *Source: apis/rest-api/v2/product-attribute-terms.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product attribute terms The product attribute terms API allows you to create, view, update, and delete individual, or a batch, of attribute terms. ## Product attribute term properties | Attribute | Type | Description | | ------------- | ------- | ---------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Term name. `MANDATORY` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `description` | string | HTML description of the resource. | | `menu_order` | integer | Menu order, used to custom sort the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ## Create an attribute term This API helps you to create a new product attribute term. ```http POST /wp-json/wc/v2/products/attributes//terms ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/products/attributes/2/terms \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "XXS" }' ``` ```javascript const data = { name: "XXS" }; WooCommerce.post("products/attributes/2/terms", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'XXS' ]; print_r($woocommerce->post('products/attributes/2/terms', $data)); ?> ``` ```python data = { "name": "XXS" } print(wcapi.post("products/attributes/2/terms", data).json()) ``` ```ruby data = { name: "XXS" } woocommerce.post("products/attributes/2/terms", data).parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } } ``` ## Retrieve an attribute term This API lets you retrieve a product attribute term by ID. ```http GET /wp-json/wc/v2/products/attributes//terms/ ``` ```shell curl https://example.com/wp-json/wc/v2/products/attributes/2/terms/23 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/attributes/2/terms/23") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/attributes/2/terms/23')); ?> ``` ```python print(wcapi.get("products/attributes/2/terms/23").json()) ``` ```ruby woocommerce.get("products/attributes/2/terms/23").parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } } ``` ## List all attribute terms This API lets you retrieve all terms from a product attribute. ```http GET /wp-json/wc/v2/products/attributes//terms ``` ```shell curl https://example.com/wp-json/wc/v2/products/attributes/2/terms \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/attributes/2/terms") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/attributes/2/terms')); ?> ``` ```python print(wcapi.get("products/attributes/2/terms").json()) ``` ```ruby woocommerce.get("products/attributes/2/terms").parsed_response ``` ```json [ { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } }, { "id": 22, "name": "XS", "slug": "xs", "description": "", "menu_order": 2, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/22" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } }, { "id": 17, "name": "S", "slug": "s", "description": "", "menu_order": 3, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/17" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } }, { "id": 18, "name": "M", "slug": "m", "description": "", "menu_order": 4, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/18" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } }, { "id": 19, "name": "L", "slug": "l", "description": "", "menu_order": 5, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/19" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } }, { "id": 20, "name": "XL", "slug": "xl", "description": "", "menu_order": 6, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/20" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } }, { "id": 21, "name": "XXL", "slug": "xxl", "description": "", "menu_order": 7, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/21" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | -------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `exclude` | array | Ensure result set excludes specific ids. | | `include` | array | Limit result set to specific ids. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `asc`. | | `orderby` | string | Sort collection by resource attribute. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. Default is `name`. | | `hide_empty` | boolean | Whether to hide resources not assigned to any products. Default is `false`. | | `parent` | integer | Limit result set to resources assigned to a specific parent. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update an attribute term This API lets you make changes to a product attribute term. ```http PUT /wp-json/wc/v2/products/attributes//terms/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/products/attributes/2/terms/23 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "XXS" }' ``` ```javascript const data = { name: "XXS" }; WooCommerce.put("products/attributes/2/terms/23", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'XXS' ]; print_r($woocommerce->put('products/attributes/2/terms/23', $data)); ?> ``` ```python data = { "name": "XXS" } print(wcapi.put("products/attributes/2/terms/23", data).json()) ``` ```ruby data = { name: "XXS" } woocommerce.put("products/attributes/2/terms/23", data).parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } } ``` ## Delete an attribute term This API helps you delete a product attribute term. ```http DELETE /wp-json/wc/v2/products/attributes//terms/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/products/attributes/2/terms/23?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/attributes/2/terms/23", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/attributes/2/terms/23', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/attributes/2/terms/23", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/attributes/2/terms/23", force: true).parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|---------|---------------------------------------------------------------| | `force` | boolean | Required to be `true`, as resource does not support trashing. | ## Batch update attribute terms This API helps you to batch create, update and delete multiple product attribute terms. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/products/attributes//terms/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/products/attributes//terms/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "XXS" }, { "name": "S" } ], "update": [ { "id": 19, "menu_order": 6 } ], "delete": [ 21, 20 ] }' ``` ```javascript const data = { create: [ { name: "XXS" }, { name: "S" } ], update: [ { id: 19, menu_order: 6 } ], delete: [ 21, 20 ] }; WooCommerce.post("products/attributes/2/terms/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'XXS' ], [ 'name' => 'S' ] ], 'update' => [ [ 'id' => 19, 'menu_order' => 6 ] ], 'delete' => [ 21, 20 ] ]; print_r($woocommerce->post('products/attributes/2/terms/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "XXS" }, { "name": "S" } ], "update": [ { "id": 19, "menu_order": 6 } ], "delete": [ 21, 20 ] } print(wcapi.post("products/attributes/2/terms/batch", data).json()) ``` ```ruby data = { create: [ { name: "XXS" }, { name: "S" } ], update: [ { id: 19, menu_order: 6 } ], delete: [ 21, 20 ] } woocommerce.post("products/attributes/2/terms/batch", data).parsed_response ``` ```json { "create": [ { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } }, { "id": 17, "name": "S", "slug": "s", "description": "", "menu_order": 3, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/17" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } } ], "update": [ { "id": 19, "name": "L", "slug": "l", "description": "", "menu_order": 6, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/19" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } } ], "delete": [ { "id": 21, "name": "XXL", "slug": "xxl", "description": "", "menu_order": 7, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/21" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } }, { "id": 20, "name": "XL", "slug": "xl", "description": "", "menu_order": 6, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms/20" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2/terms" } ] } } ] } ``` --- ## Product attributes *Source: apis/rest-api/v2/product-attributes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product attributes The product attributes API allows you to create, view, update, and delete individual, or a batch, of product attributes. ## Product attribute properties | Attribute | Type | Description | | -------------- | ------- | ------------------------------------------------------------------------------------------------ | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Attribute name. `MANDATORY` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `type` | string | Type of attribute. By default only `select` is supported. | | `order_by` | string | Default sort order. Options: `menu_order`, `name`, `name_num` and `id`. Default is `menu_order`. | | `has_archives` | boolean | Enable/Disable attribute archives. Default is `false`. | ## Create a product attribute This API helps you to create a new product attribute. ```http POST /wp-json/wc/v2/products/attributes ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/products/attributes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true }' ``` ```javascript const data = { name: "Color", slug: "pa_color", type: "select", order_by: "menu_order", has_archives: true }; WooCommerce.post("products/attributes", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Color', 'slug' => 'pa_color', 'type' => 'select', 'order_by' => 'menu_order', 'has_archives' => true ]; print_r($woocommerce->post('products/attributes', $data)); ?> ``` ```python data = { "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": True } print(wcapi.post("products/attributes", data).json()) ``` ```ruby data = { name: "Color", slug: "pa_color", type: "select", order_by: "menu_order", has_archives: true } woocommerce.post("products/attributes", data).parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes" } ] } } ``` ## Retrieve a product attribute This API lets you retrieve and view a specific product attribute by ID. ```http GET /wp-json/wc/v2/products/attributes/ ``` ```shell curl https://example.com/wp-json/wc/v2/products/attributes/1 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/attributes/1") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/attributes/1')); ?> ``` ```python print(wcapi.get("products/attributes/1").json()) ``` ```ruby woocommerce.get("products/attributes/1").parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes" } ] } } ``` ## List all product attributes This API helps you to view all the product attributes. ```http GET /wp-json/wc/v2/products/attributes ``` ```shell curl https://example.com/wp-json/wc/v2/products/attributes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/attributes") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/attributes')); ?> ``` ```python print(wcapi.get("products/attributes").json()) ``` ```ruby woocommerce.get("products/attributes").parsed_response ``` ```json [ { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes" } ] } }, { "id": 2, "name": "Size", "slug": "pa_size", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ---------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | ## Update a product attribute This API lets you make changes to a product attribute. ```http PUT /wp-json/wc/v2/products/attributes/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/products/attributes/1 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "order_by": "name" }' ``` ```javascript const data = { order_by: "name" }; WooCommerce.put("products/attributes/1", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'name' ]; print_r($woocommerce->put('products/attributes/1', $data)); ?> ``` ```python data = { "order_by": "name" } print(wcapi.put("products/attributes/1", data).json()) ``` ```ruby data = { order_by: "name" } woocommerce.put("products/attributes/1", data).parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "name", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes" } ] } } ``` ## Delete a product attribute This API helps you delete a product attribute. ```http DELETE /wp-json/wc/v2/products/attributes/ ``` :::warning This also will delete all terms from the selected attribute. ::: ```shell curl -X DELETE https://example.com/wp-json/wc/v2/products/attributes/1?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/attributes/1", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/attributes/1', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/attributes/1", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/attributes/1", force: true).parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|---------|---------------------------------------------------------------| | `force` | boolean | Required to be `true`, as resource does not support trashing. | ## Batch update product attributes This API helps you to batch create, update and delete multiple product attributes. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/products/attributes/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/products/attributes/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Brand" }, { "name": "Publisher" } ], "update": [ { "id": 2, "order_by": "name" } ], "delete": [ 1 ] }' ``` ```javascript const data = { create: [ { name: "Brand" }, { name: "Publisher" } ], update: [ { id: 2, order_by: "name" } ], delete: [ 1 ] }; WooCommerce.post("products/attributes/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Brand' ], [ 'name' => 'Publisher' ] ], 'update' => [ [ 'id' => 2, 'order_by' => 'name' ] ], 'delete' => [ 1 ] ]; print_r($woocommerce->post('products/attributes/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Brand" }, { "name": "Publisher" } ], "update": [ { "id": 2, "order_by": "name" } ], "delete": [ 1 ] } print(wcapi.post("products/attributes/batch", data).json()) ``` ```ruby data = { create: [ { name: "Brand" }, { name: "Publisher" } ], update: [ { id: 2, order_by: "name" } ], delete: [ 1 ] } woocommerce.post("products/attributes/batch", data).parsed_response ``` ```json { "create": [ { "id": 7, "name": "Brand", "slug": "pa_brand", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/7" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes" } ] } }, { "id": 8, "name": "Publisher", "slug": "pa_publisher", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/8" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes" } ] } } ], "update": [ { "id": 2, "name": "Size", "slug": "pa_size", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes" } ] } } ], "delete": [ { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes/1" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/attributes" } ] } } ] } ``` --- ## Product categories *Source: apis/rest-api/v2/product-categories.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product categories The product categories API allows you to create, view, update, and delete individual, or a batch, of categories. ## Product category properties | Attribute | Type | Description | | ------------- | ------- | ---------------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Category name. `MANDATORY` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `parent` | integer | The ID for the parent of the resource. | | `description` | string | HTML description of the resource. | | `display` | string | Category archive display type. Options: `default`, `products`, `subcategories` and `both`. Default is `default`. | | `image` | object | Image data. See [Product category - Image properties](#product-category---image-properties) | | `menu_order` | integer | Menu order, used to custom sort the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ### Product category - Image properties | Attribute | Type | Description | | ------------------- | --------- | ------------------------------------------------------------------------------------------------------- | | `id` | integer | Image ID. | | `date_created` | date-time | The date the image was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the image was created, as GMT `READ-ONLY` | | `date_modified` | date-time | The date the image was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the image was last modified, as GMT. `READ-ONLY` | | `src` | string | Image URL. | | `title` | string | Image name. | | `alt` | string | Image alternative text. | ## Create a product category This API helps you to create a new product category. ```http POST /wp-json/wc/v2/products/categories ``` > Example of how to create a product category: ```shell curl -X POST https://example.com/wp-json/wc/v2/products/categories \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Clothing", "image": { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" } }' ``` ```javascript const data = { name: "Clothing", image: { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" } }; WooCommerce.post("products/categories", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Clothing', 'image' => [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg' ] ]; print_r($woocommerce->post('products/categories', $data)); ?> ``` ```python data = { "name": "Clothing", "image": { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" } } print(wcapi.post("products/categories", data).json()) ``` ```ruby data = { name: "Clothing", image: { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" } } woocommerce.post("products/categories", data).parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": { "id": 730, "date_created": "2017-03-23T00:01:07", "date_created_gmt": "2017-03-23T03:01:07", "date_modified": "2017-03-23T00:01:07", "date_modified_gmt": "2017-03-23T03:01:07", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg", "title": "", "alt": "" }, "menu_order": 0, "count": 36, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ] } } ``` ## Retrieve a product category This API lets you retrieve a product category by ID. ```http GET /wp-json/wc/v2/products/categories/ ``` ```shell curl https://example.com/wp-json/wc/v2/products/categories/9 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/categories/9") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/categories/9')); ?> ``` ```python print(wcapi.get("products/categories/9").json()) ``` ```ruby woocommerce.get("products/categories/9").parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": { "id": 730, "date_created": "2017-03-23T00:01:07", "date_created_gmt": "2017-03-23T03:01:07", "date_modified": "2017-03-23T00:01:07", "date_modified_gmt": "2017-03-23T03:01:07", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg", "title": "", "alt": "" }, "menu_order": 0, "count": 36, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ] } } ``` ## List all product categories This API lets you retrieve all product categories. ```http GET /wp-json/wc/v2/products/categories ``` ```shell curl https://example.com/wp-json/wc/v2/products/categories \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/categories") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/categories')); ?> ``` ```python print(wcapi.get("products/categories").json()) ``` ```ruby woocommerce.get("products/categories").parsed_response ``` ```json [ { "id": 15, "name": "Albums", "slug": "albums", "parent": 11, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 4, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/15" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/11" } ] } }, { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": { "id": 730, "date_created": "2017-03-23T00:01:07", "date_created_gmt": "2017-03-23T03:01:07", "date_modified": "2017-03-23T00:01:07", "date_modified_gmt": "2017-03-23T03:01:07", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg", "title": "", "alt": "" }, "menu_order": 0, "count": 36, "_links": { "self": [ { "href": "https://example/wp-json/wc/v2/products/categories/9" } ], "collection": [ { "href": "https://example/wp-json/wc/v2/products/categories" } ] } }, { "id": 10, "name": "Hoodies", "slug": "hoodies", "parent": 9, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 6, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/10" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/9" } ] } }, { "id": 11, "name": "Music", "slug": "music", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 7, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/11" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ] } }, { "id": 12, "name": "Posters", "slug": "posters", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 5, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/12" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ] } }, { "id": 13, "name": "Singles", "slug": "singles", "parent": 11, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 3, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/13" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/11" } ] } }, { "id": 14, "name": "T-shirts", "slug": "t-shirts", "parent": 9, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 6, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/14" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/9" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `exclude` | array | Ensure result set excludes specific ids. | | `include` | array | Limit result set to specific ids. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `asc`. | | `orderby` | string | Sort collection by resource attribute. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. Default is `name`. | | `hide_empty` | boolean | Whether to hide resources not assigned to any products. Default is `false`. | | `parent` | integer | Limit result set to resources assigned to a specific parent. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update a product category This API lets you make changes to a product category. ```http PUT /wp-json/wc/v2/products/categories/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/products/categories/9 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "description": "All kinds of clothes." }' ``` ```javascript const data = { description: "All kinds of clothes." }; WooCommerce.put("products/categories/9", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'All kinds of clothes.' ]; print_r($woocommerce->put('products/categories/9', $data)); ?> ``` ```python data = { "description": "All kinds of clothes." } print(wcapi.put("products/categories/9", data).json()) ``` ```ruby data = { description: "All kinds of clothes." } woocommerce.put("products/categories/9", data).parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "All kinds of clothes.", "display": "default", "image": { "id": 730, "date_created": "2017-03-23T00:01:07", "date_created_gmt": "2017-03-23T03:01:07", "date_modified": "2017-03-23T00:01:07", "date_modified_gmt": "2017-03-23T03:01:07", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg", "title": "", "alt": "" }, "menu_order": 0, "count": 36, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ] } } ``` ## Delete a product category This API helps you delete a product category. ```http DELETE /wp-json/wc/v2/products/categories/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/products/categories/9?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/categories/9", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/categories/9', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/categories/9", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/categories/9", force: true).parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "All kinds of clothes.", "display": "default", "image": { "id": 730, "date_created": "2017-03-23T00:01:07", "date_created_gmt": "2017-03-23T03:01:07", "date_modified": "2017-03-23T00:01:07", "date_modified_gmt": "2017-03-23T03:01:07", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg", "title": "", "alt": "" }, "menu_order": 0, "count": 36, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update product categories This API helps you to batch create, update and delete multiple product categories. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/products/categories/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/products/categories/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Albums" }, { "name": "Clothing" } ], "update": [ { "id": 10, "description": "Nice hoodies" } ], "delete": [ 11, 12 ] }' ``` ```javascript const data = { create: [ { name: "Albums" }, { name: "Clothing" } ], update: [ { id: 10, description: "Nice hoodies" } ], delete: [ 11, 12 ] }; WooCommerce.post("products/categories/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Albums' ], [ 'name' => 'Clothing' ] ], 'update' => [ [ 'id' => 10, 'description' => 'Nice hoodies' ] ], 'delete' => [ 11, 12 ] ]; print_r($woocommerce->post('products/categories/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Albums" }, { "name": "Clothing" } ], "update": [ { "id": 10, "description": "Nice hoodies" } ], "delete": [ 11, 12 ] } print(wcapi.post("products/categories/batch", data).json()) ``` ```ruby data = { create: [ { name: "Albums" }, { name: "Clothing" } ], update: [ { id: 10, description: "Nice hoodies" } ], delete: [ 11, 12 ] } woocommerce.post("products/categories/batch", data).parsed_response ``` ```json { "create": [ { "id": 15, "name": "Albums", "slug": "albums", "parent": 11, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/15" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/11" } ] } }, { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ] } } ], "update": [ { "id": 10, "name": "Hoodies", "slug": "hoodies", "parent": 9, "description": "Nice hoodies", "display": "default", "image": [], "menu_order": 0, "count": 6, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/10" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/9" } ] } } ], "delete": [ { "id": 11, "name": "Music", "slug": "music", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 7, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/11" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ] } }, { "id": 12, "name": "Posters", "slug": "posters", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 5, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/categories/12" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/categories" } ] } } ] } ``` --- ## Product shipping classes *Source: apis/rest-api/v2/product-shipping-classes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product shipping classes The product shipping class API allows you to create, view, update, and delete individual, or a batch, of shipping classes. ## Product shipping class properties | Attribute | Type | Description | | ------------- | ------- | ---------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Shipping class name. `MANDATORY` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `description` | string | HTML description of the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ## Create a shipping class This API helps you to create a new product shipping class. ```http POST /wp-json/wc/v2/products/shipping_classes ``` > Example of how to create a product shipping class: ```shell curl -X POST https://example.com/wp-json/wc/v2/products/shipping_classes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Priority" }' ``` ```javascript const data = { name: "Priority" }; WooCommerce.post("products/shipping_classes", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Priority' ]; print_r($woocommerce->post('products/shipping_classes', $data)); ?> ``` ```python data = { "name": "Priority" } print(wcapi.post("products/shipping_classes", data).json()) ``` ```ruby data = { name: "Priority" } woocommerce.post("products/shipping_classes", data).parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes" } ] } } ``` ## Retrieve a shipping class This API lets you retrieve a product shipping class by ID. ```http GET /wp-json/wc/v2/products/shipping_classes/ ``` ```shell curl https://example.com/wp-json/wc/v2/products/shipping_classes/32 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/shipping_classes/32") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/shipping_classes/32')); ?> ``` ```python print(wcapi.get("products/shipping_classes/32").json()) ``` ```ruby woocommerce.get("products/shipping_classes/32").parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes" } ] } } ``` ## List all shipping classes This API lets you retrieve all product shipping classes. ```http GET /wp-json/wc/v2/products/shipping_classes ``` ```shell curl https://example.com/wp-json/wc/v2/products/shipping_classes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/shipping_classes") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/shipping_classes')); ?> ``` ```python print(wcapi.get("products/shipping_classes").json()) ``` ```ruby woocommerce.get("products/shipping_classes").parsed_response ``` ```json [ { "id": 33, "name": "Express", "slug": "express", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes/33" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes" } ] } }, { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `exclude` | array | Ensure result set excludes specific ids. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `asc`. | | `orderby` | string | Sort collection by resource attribute. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. Default is `name`. | | `hide_empty` | boolean | Whether to hide resources not assigned to any products. Default is `false`. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update a shipping class This API lets you make changes to a product shipping class. ```http PUT /wp-json/wc/v2/products/shipping_classes/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/products/shipping_classes/32 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "description": "Priority mail." }' ``` ```javascript const data = { description: "Priority mail." }; WooCommerce.put("products/shipping_classes/32", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Priority mail.' ]; print_r($woocommerce->put('products/shipping_classes/32', $data)); ?> ``` ```python data = { "description": "Priority mail." } print(wcapi.put("products/shipping_classes/32", data).json()) ``` ```ruby data = { description: "Priority mail." } woocommerce.put("products/shipping_classes/32", data).parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "Priority mail.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes" } ] } } ``` ## Delete a shipping class This API helps you delete a product shipping class. ```http DELETE /wp-json/wc/v2/products/shipping_classes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/products/shipping_classes/32?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/shipping_classes/32", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/shipping_classes/32', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/shipping_classes/32", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/shipping_classes/32", force: true).parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "Priority mail.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update shipping classes This API helps you to batch create, update and delete multiple product shipping classes. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/products/shipping_classes/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/products/shipping_classes/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Small items" }, { "name": "Large items" } ], "update": [ { "id": 33, "description": "Express shipping" } ], "delete": [ 32 ] }' ``` ```javascript const data = { create: [ { name: "Small items" }, { name: "Large items" } ], update: [ { id: 33, description: "Express shipping" } ], delete: [ 32 ] }; WooCommerce.post("products/shipping_classes/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Small items' ], [ 'name' => 'Large items' ] ], 'update' => [ [ 'id' => 33, 'description' => 'Express shipping' ] ], 'delete' => [ 32 ] ]; print_r($woocommerce->post('products/shipping_classes/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Small items" }, { "name": "Large items" } ], "update": [ { "id": 33, "description": "Express shipping" } ], "delete": [ 32 ] } print(wcapi.post("products/shipping_classes/batch", data).json()) ``` ```ruby data = { create: [ { name: "Small items" }, { name: "Large items" } ], update: [ { id: 33, description: "Express shipping" } ], delete: [ 32 ] } woocommerce.post("products/shipping_classes/batch", data).parsed_response ``` ```json { "create": [ { "id": 34, "name": "Small items", "slug": "small-items", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes" } ] } }, { "id": 35, "name": "Large items", "slug": "large-items", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes/35" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes" } ] } } ], "update": [ { "id": 33, "name": "Express", "slug": "express", "description": "Express shipping", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes/33" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes" } ] } } ], "delete": [ { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/shipping_classes" } ] } } ] } ``` --- ## Product tags *Source: apis/rest-api/v2/product-tags.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product tags The product tags API allows you to create, view, update, and delete individual, or a batch, of product tags. ## Product tag properties | Attribute | Type | Description | | ------------- | ------- | ---------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Tag name. `MANDATORY` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `description` | string | HTML description of the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ## Create a product tag This API helps you to create a new product tag. ```http POST /wp-json/wc/v2/products/tags ``` > Example of how to create a product tag: ```shell curl -X POST https://example.com/wp-json/wc/v2/products/tags \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Leather Shoes" }' ``` ```javascript const data = { name: "Leather Shoes" }; WooCommerce.post("products/tags", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Leather Shoes' ]; print_r($woocommerce->post('products/tags', $data)); ?> ``` ```python data = { "name": "Leather Shoes" } print(wcapi.post("products/tags", data).json()) ``` ```ruby data = { name: "Leather Shoes" } woocommerce.post("products/tags", data).parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/tags" } ] } } ``` ## Retrieve a product tag This API lets you retrieve a product tag by ID. ```http GET /wp-json/wc/v2/products/tags/ ``` ```shell curl https://example.com/wp-json/wc/v2/products/tags/34 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/tags/34") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/tags/34')); ?> ``` ```python print(wcapi.get("products/tags/34").json()) ``` ```ruby woocommerce.get("products/tags/34").parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/tags" } ] } } ``` ## List all product tags This API lets you retrieve all product tag. ```http GET /wp-json/wc/v2/products/tags ``` ```shell curl https://example.com/wp-json/wc/v2/products/tags \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/tags") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/tags')); ?> ``` ```python print(wcapi.get("products/tags").json()) ``` ```ruby woocommerce.get("products/tags").parsed_response ``` ```json [ { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/tags" } ] } }, { "id": 35, "name": "Oxford Shoes", "slug": "oxford-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/tags/35" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/tags" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `exclude` | array | Ensure result set excludes specific ids. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `asc`. | | `orderby` | string | Sort collection by resource attribute. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. Default is `name`. | | `hide_empty` | boolean | Whether to hide resources not assigned to any products. Default is `false`. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update a product tag This API lets you make changes to a product tag. ```http PUT /wp-json/wc/v2/products/tags/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/products/tags/34 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "description": "Genuine leather." }' ``` ```javascript const data = { description: "Genuine leather." }; WooCommerce.put("products/tags/34", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php put('products/tags/34', $data)); ?> ``` ```python data = { "description": "Genuine leather." } print(wcapi.put("products/tags/34", data).json()) ``` ```ruby data = { description: "Genuine leather." } woocommerce.put("products/tags/34", data).parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "Genuine leather.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/tags" } ] } } ``` ## Delete a product tag This API helps you delete a product tag. ```http DELETE /wp-json/wc/v2/products/tags/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/products/tags/34?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/tags/34", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/tags/34', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/tags/34", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/tags/34", force: true).parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "Genuine leather.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/tags" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update product tags This API helps you to batch create, update and delete multiple product tags. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/products/tags/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/products/tags/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Round toe" }, { "name": "Flat" } ], "update": [ { "id": 34, "description": "Genuine leather." } ], "delete": [ 35 ] }' ``` ```javascript const data = { create: [ { name: "Round toe" }, { name: "Flat" } ], update: [ { id: 34, description: "Genuine leather." } ], delete: [ 35 ] }; WooCommerce.post("products/tags/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Round toe' ], [ 'name' => 'Flat' ] ], 'update' => [ [ 'id' => 34, 'description' => 'Genuine leather.' ] ], 'delete' => [ 35 ] ]; print_r($woocommerce->post('products/tags/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Round toe" }, { "name": "Flat" } ], "update": [ { "id": 34, "description": "Genuine leather." } ], "delete": [ 35 ] } print(wcapi.post("products/tags/batch", data).json()) ``` ```ruby data = { create: [ { name: "Round toe" }, { name: "Flat" } ], update: [ { id: 34, description: "Genuine leather." } ], delete: [ 35 ] } woocommerce.post("products/tags/batch", data).parsed_response ``` ```json { "create": [ { "id": 36, "name": "Round toe", "slug": "round-toe", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/tags/36" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/tags" } ] } }, { "id": 37, "name": "Flat", "slug": "flat", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/tags/37" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/tags" } ] } } ], "update": [ { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "Genuine leather.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/tags" } ] } } ], "delete": [ { "id": 35, "name": "Oxford Shoes", "slug": "oxford-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/tags/35" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/tags" } ] } } ] } ``` --- ## Product variations *Source: apis/rest-api/v2/product-variations.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product variations The product variations API allows you to create, view, update, and delete individual, or a batch, of product variations. ## Product variation properties | Attribute | Type | Description | |-------------------------|-----------|---------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | date-time | The date the variation was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the variation was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the variation was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the variation was last modified, as GMT. `READ-ONLY` | | `description` | string | Variation description. | | `permalink` | string | Variation URL. `READ-ONLY` | | `sku` | string | Unique identifier. | | `price` | string | Current variation price. `READ-ONLY` | | `regular_price` | string | Variation regular price. | | `sale_price` | string | Variation sale price. | | `date_on_sale_from` | date-time | Start date of sale price, in the site's timezone. | | `date_on_sale_from_gmt` | date-time | Start date of sale price, as GMT. | | `date_on_sale_to` | date-time | End date of sale price, in the site's timezone. | | `date_on_sale_to_gmt` | date-time | End date of sale price, as GMT. | | `on_sale` | boolean | Shows if the variation is on sale. `READ-ONLY` | | `visible` | boolean | Define if the attribute is visible on the "Additional information" tab in the product's page. Default is `true`. | | `purchasable` | boolean | Shows if the variation can be bought. `READ-ONLY` | | `virtual` | boolean | If the variation is virtual. Default is `false`. | | `downloadable` | boolean | If the variation is downloadable. Default is `false`. | | `downloads` | array | List of downloadable files. See [Product variation - Downloads properties](#product-variation---downloads-properties) | | `download_limit` | integer | Number of times downloadable files can be downloaded after purchase. Default is `-1`. | | `download_expiry` | integer | Number of days until access to downloadable files expires. Default is `-1`. | | `tax_status` | string | Tax status. Options: `taxable`, `shipping` and `none`. Default is `taxable`. | | `tax_class` | string | Tax class. | | `manage_stock` | boolean, string | Stock management at variation level. Possible values are either a boolean or `parent`. Default is `false`. | | `stock_quantity` | integer | Stock quantity. | | `in_stock` | boolean | Controls whether or not the variation is listed as "in stock" or "out of stock" on the frontend. Default is `true`. | | `backorders` | string | If managing stock, this controls if backorders are allowed. Options: `no`, `notify` and `yes`. Default is `no`. | | `backorders_allowed` | boolean | Shows if backorders are allowed. `READ-ONLY` | | `backordered` | boolean | Shows if the variation is on backordered. `READ-ONLY` | | `weight` | string | Variation weight. | | `dimensions` | object | Variation dimensions. See [Product variation - Dimensions properties](#product-variation---dimensions-properties) | | `shipping_class` | string | Shipping class slug. | | `shipping_class_id` | string | Shipping class ID. `READ-ONLY` | | `image` | object | Variation image data. See [Product variation - Image properties](#product-variation---image-properties) | | `attributes` | array | List of attributes. See [Product variation - Attributes properties](#product-variation---attributes-properties) | | `menu_order` | integer | Menu order, used to custom sort products. | | `meta_data` | array | Meta data. See [Product variation - Meta data properties](#product-variation---meta-data-properties) | ### Product variation - Downloads properties | Attribute | Type | Description | |-----------|--------|-------------| | `id` | string | File ID. | | `name` | string | File name. | | `file` | string | File URL. | ### Product variation - Dimensions properties | Attribute | Type | Description | |-----------|--------|-------------------| | `length` | string | Variation length. | | `width` | string | Variation width. | | `height` | string | Variation height. | ### Product variation - Image properties | Attribute | Type | Description | |---------------------|-----------|---------------------------------------------------------------------------------------------------------| | `id` | integer | Image ID. | | `date_created` | date-time | The date the image was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the image was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the image was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the image was last modified, as GMT. `READ-ONLY` | | `src` | string | Image URL. | | `name` | string | Image name. | | `alt` | string | Image alternative text. | | `position` | integer | Image position. 0 means that the image is featured. | ### Product variation - Attributes properties | Attribute | Type | Description | |-----------|---------|-------------------------------| | `id` | integer | Attribute ID. | | `name` | string | Attribute name. | | `option` | string | Selected attribute term name. | ### Product variation - Meta data properties | Attribute | Type | Description | |-----------|---------|----------------------------------------------------| | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ## Create a product variation This API helps you to create a new product variation. ```http POST /wp-json/wc/v2/products//variations ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/products/22/variations \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "regular_price": "9.00", "image": { "id": 423 }, "attributes": [ { "id": 6, "option": "Black" } ] }' ``` ```javascript const data = { regular_price: "9.00", image: { id: 423 }, attributes: [ { id: 9, option: "Black" } ] }; WooCommerce.post("products/22/variations", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php '9.00', 'image' => [ 'id' => 423 ], 'attributes' => [ [ 'id' => 9, 'option' => 'Black' ] ] ]; print_r($woocommerce->post('products/22/variations', $data)); ?> ``` ```python data = { "regular_price": "9.00", "image": { "id": 423 }, "attributes": [ { "id": 9, "option": "Black" } ] } print(wcapi.post("products/22/variations", data).json()) ``` ```ruby data = { regular_price: "9.00", image: { id: 423 }, attributes: [ { id: 9, position: "Black" } ] } woocommerce.post("products/22/variations", data).parsed_response ``` ```json { "id": 732, "date_created": "2017-03-23T00:36:38", "date_created_gmt": "2017-03-23T03:36:38", "date_modified": "2017-03-23T00:36:38", "date_modified_gmt": "2017-03-23T03:36:38", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black", "sku": "", "price": "9.00", "regular_price": "9.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "visible": true, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 423, "date_created": "2016-10-19T12:21:14", "date_created_gmt": "2016-10-19T16:21:14", "date_modified": "2016-10-19T12:21:14", "date_modified_gmt": "2016-10-19T16:21:14", "src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg", "name": "", "alt": "", "position": 0 }, "attributes": [ { "id": 6, "name": "Color", "option": "Black" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations/732" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } } ``` ## Retrieve a product variation This API lets you retrieve and view a specific product variation by ID. ```http GET /wp-json/wc/v2/products//variations/ ``` ```shell curl https://example.com/wp-json/wc/v2/products/22/variations/732 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/22/variations/732") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/22/variations/732')); ?> ``` ```python print(wcapi.get("products/22/variations/732").json()) ``` ```ruby woocommerce.get("products/22/variations/732").parsed_response ``` ```json { "id": 732, "date_created": "2017-03-23T00:36:38", "date_created_gmt": "2017-03-23T03:36:38", "date_modified": "2017-03-23T00:36:38", "date_modified_gmt": "2017-03-23T03:36:38", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black", "sku": "", "price": "9.00", "regular_price": "9.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "visible": true, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 423, "date_created": "2016-10-19T12:21:14", "date_created_gmt": "2016-10-19T16:21:14", "date_modified": "2016-10-19T12:21:14", "date_modified_gmt": "2016-10-19T16:21:14", "src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg", "name": "", "alt": "", "position": 0 }, "attributes": [ { "id": 6, "name": "Color", "option": "Black" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations/732" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } } ``` ## List all product variations This API helps you to view all the product variations. ```http GET /wp-json/wc/v2/products//variations ``` ```shell curl https://example.com/wp-json/wc/v2/products/22/variations \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/22/variations") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/22/variations')); ?> ``` ```python print(wcapi.get("products/22/variations").json()) ``` ```ruby woocommerce.get("products/22/variations").parsed_response ``` ```json [ { "id": 733, "date_created": "2017-03-23T00:53:11", "date_created_gmt": "2017-03-23T03:53:11", "date_modified": "2017-03-23T00:53:11", "date_modified_gmt": "2017-03-23T03:53:11", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green", "sku": "", "price": "9.00", "regular_price": "9.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "visible": true, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 425, "date_created": "2016-10-19T12:21:16", "date_created_gmt": "2016-10-19T16:21:16", "date_modified": "2016-10-19T12:21:16", "date_modified_gmt": "2016-10-19T16:21:16", "src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg", "name": "", "alt": "", "position": 0 }, "attributes": [ { "id": 6, "name": "Color", "option": "Green" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations/733" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } }, { "id": 732, "date_created": "2017-03-23T00:36:38", "date_created_gmt": "2017-03-23T03:36:38", "date_modified": "2017-03-23T00:36:38", "date_modified_gmt": "2017-03-23T03:36:38", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black", "sku": "", "price": "9.00", "regular_price": "9.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "visible": true, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 423, "date_created": "2016-10-19T12:21:14", "date_created_gmt": "2016-10-19T16:21:14", "date_modified": "2016-10-19T12:21:14", "date_modified_gmt": "2016-10-19T16:21:14", "src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg", "name": "", "alt": "", "position": 0 }, "attributes": [ { "id": 6, "name": "Color", "option": "Black" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations/732" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `id`, `include`, `title` and `slug`. Default is `date`. | | `parent` | array | Limit result set to those of particular parent IDs. | | `parent_exclude` | array | Limit result set to all items except those of a particular parent ID. | | `slug` | string | Limit result set to products with a specific slug. | | `status` | string | Limit result set to products assigned a specific status. Options: `any`, `draft`, `pending`, `private` and `publish`. Default is `any`. | | `type` | string | Limit result set to products assigned a specific type. Options: `simple`, `grouped`, `external` and `variable`. | | `sku` | string | Limit result set to products with a specific SKU. | | `featured` | boolean | Limit result set to featured products. | | `category` | string | Limit result set to products assigned a specific category ID. | | `tag` | string | Limit result set to products assigned a specific tag ID. | | `shipping_class` | string | Limit result set to products assigned a specific shipping class ID. | | `attribute` | string | Limit result set to products with a specific attribute. | | `attribute_term` | string | Limit result set to products with a specific attribute term ID (required an assigned attribute). | | `tax_class` | string | Limit result set to products with a specific tax class. Default options: `standard`, `reduced-rate` and `zero-rate`. | | `in_stock` | boolean | Limit result set to products in stock or out of stock. | | `on_sale` | boolean | Limit result set to products on sale. | | `min_price` | string | Limit result set to products based on a minimum price. | | `max_price` | string | Limit result set to products based on a maximum price. | | `image_size` | string | Use a specific registered image size for the returned variation image `src`. Falls back to the full size if the requested size is not registered. Default is `full`. | ## Update a product variation This API lets you make changes to a product variation. ```http PUT /wp-json/wc/v2/products//variations/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/products/22/variations/733 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "regular_price": "10.00" }' ``` ```javascript const data = { regular_price: "10.00" }; WooCommerce.put("products/22/variations/733", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php '10.00' ]; print_r($woocommerce->put('products/22/variations/733', $data)); ?> ``` ```python data = { "regular_price": "10.00" } print(wcapi.put("products/22/variations/733", data).json()) ``` ```ruby data = { regular_price: "10.00" } woocommerce.put("products/22/variations/733", data).parsed_response ``` ```json { "id": 733, "date_created": "2017-03-23T00:53:11", "date_created_gmt": "2017-03-23T03:53:11", "date_modified": "2017-03-23T00:53:11", "date_modified_gmt": "2017-03-23T03:53:11", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green", "sku": "", "price": "10.00", "regular_price": "10.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "visible": true, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 425, "date_created": "2016-10-19T12:21:16", "date_created_gmt": "2016-10-19T16:21:16", "date_modified": "2016-10-19T12:21:16", "date_modified_gmt": "2016-10-19T16:21:16", "src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg", "name": "", "alt": "", "position": 0 }, "attributes": [ { "id": 6, "name": "Color", "option": "Green" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations/733" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } } ``` ## Delete a product variation This API helps you delete a product variation. ```http DELETE /wp-json/wc/v2/products//variations/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/products/22/variations/733?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/22/variations/733", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/22/variations/733', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/22/variations/733", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/22/variations/733", force: true).parsed_response ``` ```json { "id": 733, "date_created": "2017-03-23T00:53:11", "date_created_gmt": "2017-03-23T03:53:11", "date_modified": "2017-03-23T00:53:11", "date_modified_gmt": "2017-03-23T03:53:11", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green", "sku": "", "price": "10.00", "regular_price": "10.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "visible": true, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 425, "date_created": "2016-10-19T12:21:16", "date_created_gmt": "2016-10-19T16:21:16", "date_modified": "2016-10-19T12:21:16", "date_modified_gmt": "2016-10-19T16:21:16", "src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg", "name": "", "alt": "", "position": 0 }, "attributes": [ { "id": 6, "name": "Color", "option": "Green" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations/733" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update product variations This API helps you to batch create, update and delete multiple product variations. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/products//variations/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/products/22/variations/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "Blue" } ] }, { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "White" } ] } ], "update": [ { "id": 733, "regular_price": "10.00" } ], "delete": [ 732 ] }' ``` ```javascript const data = { create: [ { regular_price: "10.00", attributes: [ { id: 6, option: "Blue" } ] }, { regular_price: "10.00", attributes: [ { id: 6, option: "White" } ] } ], update: [ { id: 733, regular_price: "10.00" } ], delete: [ 732 ] }; WooCommerce.post("products/22/variations/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'regular_price' => '10.00', 'attributes' => [ [ 'id' => 6, 'option' => 'Blue' ] ] ], [ 'regular_price' => '10.00', 'attributes' => [ [ 'id' => 6, 'option' => 'White' ] ] ] ], 'update' => [ [ 'id' => 733, 'regular_price' => '10.00' ] ], 'delete' => [ 732 ] ]; print_r($woocommerce->post('products/22/variations/batch', $data)); ?> ``` ```python data = { "create": [ { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "Blue" } ] }, { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "White" } ] } ], "update": [ { "id": 733, "regular_price": "10.00" } ], "delete": [ 732 ] } print(wcapi.post("products/22/variations/batch", data).json()) ``` ```ruby data = { create: [ { regular_price: "10.00", attributes: [ { id: 6, option: "Blue" } ] }, { regular_price: "10.00", attributes: [ { id: 6, option: "White" } ] } ], update: [ { id: 733, regular_price: "10.00" } ], delete: [ 732 ] } woocommerce.post("products/22/variations/batch", data).parsed_response ``` ```json { "create": [ { "id": 735, "date_created": "2017-03-23T01:19:37", "date_created_gmt": "2017-03-23T04:19:37", "date_modified": "2017-03-23T01:19:37", "date_modified_gmt": "2017-03-23T04:19:37", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=blue", "sku": "", "price": "10.00", "regular_price": "10.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "visible": true, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 0, "date_created": "2017-03-22T22:19:40", "date_created_gmt": "2017-03-23T04:19:40", "date_modified": "2017-03-22T22:19:40", "date_modified_gmt": "2017-03-23T04:19:40", "src": "https://example.com/wp-content/plugins/woocommerce/assets/images/placeholder.png", "name": "Placeholder", "alt": "Placeholder", "position": 0 }, "attributes": [ { "id": 6, "name": "Color", "option": "Blue" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations/735" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } }, { "id": 736, "date_created": "2017-03-23T01:19:40", "date_created_gmt": "2017-03-23T04:19:40", "date_modified": "2017-03-23T01:19:40", "date_modified_gmt": "2017-03-23T04:19:40", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=white", "sku": "", "price": "10.00", "regular_price": "10.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "visible": true, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 0, "date_created": "2017-03-22T22:19:42", "date_created_gmt": "2017-03-23T04:19:42", "date_modified": "2017-03-22T22:19:42", "date_modified_gmt": "2017-03-23T04:19:42", "src": "https://example.com/wp-content/plugins/woocommerce/assets/images/placeholder.png", "name": "Placeholder", "alt": "Placeholder", "position": 0 }, "attributes": [ { "id": 6, "name": "Color", "option": "White" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations/736" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } } ], "update": [ { "id": 733, "date_created": "2017-03-23T00:53:11", "date_created_gmt": "2017-03-23T03:53:11", "date_modified": "2017-03-23T00:53:11", "date_modified_gmt": "2017-03-23T03:53:11", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green", "sku": "", "price": "10.00", "regular_price": "10.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "visible": true, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 425, "date_created": "2016-10-19T12:21:16", "date_created_gmt": "2016-10-19T16:21:16", "date_modified": "2016-10-19T12:21:16", "date_modified_gmt": "2016-10-19T16:21:16", "src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg", "name": "", "alt": "", "position": 0 }, "attributes": [ { "id": 6, "name": "Color", "option": "Green" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations/733" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } } ], "delete": [ { "id": 732, "date_created": "2017-03-23T00:36:38", "date_created_gmt": "2017-03-23T03:36:38", "date_modified": "2017-03-23T00:36:38", "date_modified_gmt": "2017-03-23T03:36:38", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black", "sku": "", "price": "9.00", "regular_price": "9.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "visible": true, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 423, "date_created": "2016-10-19T12:21:14", "date_created_gmt": "2016-10-19T16:21:14", "date_modified": "2016-10-19T12:21:14", "date_modified_gmt": "2016-10-19T16:21:14", "src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg", "name": "", "alt": "", "position": 0 }, "attributes": [ { "id": 6, "name": "Color", "option": "Black" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations/732" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } } ] } ``` --- ## Products *Source: apis/rest-api/v2/products.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Products The products API allows you to create, view, update, and delete individual, or a batch, of products. ## Product properties | Attribute | Type | Description | | | |-------------------------|-----------|----------------------------------------------------------------------------------------------------------------------|-------|-------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | | | `name` | string | Product name. | | | | `slug` | string | Product slug. | | | | `permalink` | string | Product URL. `READ-ONLY` | | | | `date_created` | date-time | The date the product was created, in the site's timezone. `READ-ONLY` | | | | `date_created_gmt` | date-time | The date the product was created, as GMT. `READ-ONLY` | | | | `date_modified` | date-time | The date the product was last modified, in the site's timezone. `READ-ONLY` | | | | `date_modified_gmt` | date-time | The date the product was last modified, as GMT. `READ-ONLY` | | | | `type` | string | Product type. Options: `simple`, `grouped`, `external` and `variable`. Default is `simple`. | | | | `status` | string | Product status (post status). Options: `draft`, `pending`, `private` and `publish`. Default is `publish`. | | | | `featured` | boolean | Featured product. Default is `false`. | | | | `catalog_visibility` | string | Catalog visibility. Options: `visible`, `catalog`, `search` and `hidden`. Default is `visible`. | | | | `description` | string | Product description. | | | | `short_description` | string | Product short description. | | | | `sku` | string | Unique identifier. | | | | `price` | string | Current product price. `READ-ONLY` | | | | `regular_price` | string | Product regular price. | | | | `sale_price` | string | Product sale price. | | | | `date_on_sale_from` | date-time | Start date of sale price, in the site's timezone. | | | | `date_on_sale_from_gmt` | date-time | Start date of sale price, as GMT. | | | | `date_on_sale_to` | date-time | End date of sale price, in the site's timezone. | | | | `date_on_sale_to_gmt` | date-time | End date of sale price, as GMT. | | | | `price_html` | string | Price formatted in HTML. `READ-ONLY` | | | | `on_sale` | boolean | Shows if the product is on sale. `READ-ONLY` | | | | `purchasable` | boolean | Shows if the product can be bought. `READ-ONLY` | | | | `total_sales` | integer | Amount of sales. `READ-ONLY` | | | | `virtual` | boolean | If the product is virtual. Default is `false`. | | | | `downloadable` | boolean | If the product is downloadable. Default is `false`. | | | | `downloads` | array | List of downloadable files. See [Product - Downloads properties](#product---downloads-properties) | | | | `download_limit` | integer | Number of times downloadable files can be downloaded after purchase. Default is `-1`. | | | | `download_expiry` | integer | Number of days until access to downloadable files expires. Default is `-1`. | | | | `external_url` | string | Product external URL. Only for external products. | | | | `button_text` | string | Product external button text. Only for external products. | | | | `tax_status` | string | Tax status. Options: `taxable`, `shipping` and `none`. Default is `taxable`. | | | | `tax_class` | string | Tax class. | | | | `manage_stock` | boolean | Stock management at product level. Default is `false`. | | | | `stock_quantity` | integer | Stock quantity. | | | | `in_stock` | boolean | Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend. Default is `true`. | | | | `backorders` | string | If managing stock, this controls if backorders are allowed. Options: `no`, `notify` and `yes`. Default is `no`. | | | | `backorders_allowed` | boolean | Shows if backorders are allowed. `READ-ONLY` | | | | `backordered` | boolean | Shows if the product is on backordered. `READ-ONLY` | | | | `sold_individually` | boolean | Allow one item to be bought in a single order. Default is `false`. | | | | `weight` | string | Product weight. | | | | `dimensions` | object | Product dimensions. See [Product - Dimensions properties](#product---dimensions-properties) | | | | `shipping_required` | boolean | Shows if the product need to be shipped. `READ-ONLY` | | | | `shipping_taxable` | boolean | Shows whether or not the product shipping is taxable. `READ-ONLY` | | | | `shipping_class` | string | Shipping class slug. | | | | `shipping_class_id` | integer | Shipping class ID. `READ-ONLY` | | | | `reviews_allowed` | boolean | Allow reviews. Default is `true`. | | | | `average_rating` | string | Reviews average rating. `READ-ONLY` | | | | `rating_count` | integer | Amount of reviews that the product have. `READ-ONLY` | | | | `related_ids` | array | List of related products IDs. `READ-ONLY` | | | | `upsell_ids` | array | List of up-sell products IDs. | | | | `cross_sell_ids` | array | List of cross-sell products IDs. | | | | `parent_id` | integer | Product parent ID. | | | | `purchase_note` | string | Optional note to send the customer after purchase. | | | | `categories` | array | List of categories. See [Product - Categories properties](#product---categories-properties) | | | | `tags` | array | List of tags. See [Product - Tags properties](#product---tags-properties) | array | List of images. See [Product - Images properties](#product---images-properties) | | `attributes` | array | List of attributes. See [Product - Attributes properties](#product---attributes-properties) | | | | `default_attributes` | array | Defaults variation attributes. See [Product - Default attributes properties](#product---default-attributes-properties) | | | | `variations` | array | List of variations IDs. `READ-ONLY` | | | | `grouped_products` | array | List of grouped products ID. | | | | `menu_order` | integer | Menu order, used to custom sort products. | | | | `meta_data` | array | Meta data. See [Product - Meta data properties](#product---meta-data-properties) | | | ### Product - Downloads properties | Attribute | Type | Description | |-----------|--------|-------------| | `id` | string | File ID. | | `name` | string | File name. | | `file` | string | File URL. | ### Product - Dimensions properties | Attribute | Type | Description | |-----------|--------|-----------------| | `length` | string | Product length. | | `width` | string | Product width. | | `height` | string | Product height. | ### Product - Categories properties | Attribute | Type | Description | |-----------|---------|----------------------------------------------------------| | `id` | integer | Category ID. | | `name` | string | Category name. `READ-ONLY` | | `slug` | string | Category slug. `READ-ONLY` | ### Product - Tags properties | Attribute | Type | Description | |-----------|---------|-----------------------------------------------------| | `id` | integer | Tag ID. | | `name` | string | Tag name. `READ-ONLY` | | `slug` | string | Tag slug. `READ-ONLY` | ### Product - Images properties | Attribute | Type | Description | |---------------------|-----------|---------------------------------------------------------------------------------------------------------| | `id` | integer | Image ID. | | `date_created` | date-time | The date the image was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the image was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the image was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the image was last modified, as GMT. `READ-ONLY` | | `src` | string | Image URL. | | `name` | string | Image name. | | `alt` | string | Image alternative text. | | `position` | integer | Image position. 0 means that the image is featured. | ### Product - Attributes properties | Attribute | Type | Description | |-------------|---------|-------------------------------------------------------------------------------------------------------------------| | `id` | integer | Attribute ID. | | `name` | string | Attribute name. | | `position` | integer | Attribute position. | | `visible` | boolean | Define if the attribute is visible on the "Additional information" tab in the product's page. Default is `false`. | | `variation` | boolean | Define if the attribute can be used as variation. Default is `false`. | | `options` | array | List of available term names of the attribute. | ### Product - Default attributes properties | Attribute | Type | Description | |-----------|---------|-------------------------------| | `id` | integer | Attribute ID. | | `name` | string | Attribute name. | | `option` | string | Selected attribute term name. | ### Product - Meta data properties | Attribute | Type | Description | |-----------|---------|----------------------------------------------------| | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ## Create a product This API helps you to create a new product. ```http POST /wp-json/wc/v2/products ``` > Example of how to create a `simple` product: ```shell curl -X POST https://example.com/wp-json/wc/v2/products \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", "position": 1 } ] }' ``` ```javascript const data = { name: "Premium Quality", type: "simple", regular_price: "21.99", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", position: 1 } ] }; WooCommerce.post("products", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Premium Quality', 'type' => 'simple', 'regular_price' => '21.99', 'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', 'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'categories' => [ [ 'id' => 9 ], [ 'id' => 14 ] ], 'images' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg', 'position' => 0 ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg', 'position' => 1 ] ] ]; print_r($woocommerce->post('products', $data)); ?> ``` ```python data = { "name": "Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", "position": 1 } ] } print(wcapi.post("products", data).json()) ``` ```ruby data = { name: "Premium Quality", type: "simple", regular_price: "21.99", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", position: 1 } ] } woocommerce.post("products", data).parsed_response ``` ```json { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$21.99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 53, 40, 56, 479, 99 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 792, "date_created": "2017-03-23T14:01:13", "date_created_gmt": "2017-03-23T20:01:13", "date_modified": "2017-03-23T14:01:13", "date_modified_gmt": "2017-03-23T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "", "position": 0 }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products" } ] } } ```
> Example of how to create a `variable` product with global and non-global attributes: ```shell curl -X POST https://example.com/wp-json/wc/v2/products \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Ship Your Idea", "type": "variable", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg", "position": 1 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", "position": 2 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg", "position": 3 } ], "attributes": [ { "id": 6, "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "name": "Size", "position": 0, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "option": "Black" }, { "name": "Size", "option": "S" } ] }' ``` ```javascript const data = { name: "Ship Your Idea", type: "variable", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg", position: 1 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", position: 2 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg", position: 3 } ], attributes: [ { id: 6, position: 0, visible: true, variation: true, options: [ "Black", "Green" ] }, { name: "Size", position: 0, visible: false, variation: true, options: [ "S", "M" ] } ], default_attributes: [ { id: 6, option: "Black" }, { name: "Size", option: "S" } ] }; WooCommerce.post("products", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Ship Your Idea', 'type' => 'variable', 'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', 'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'categories' => [ [ 'id' => 9 ], [ 'id' => 14 ] ], 'images' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg', 'position' => 0 ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg', 'position' => 1 ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg', 'position' => 2 ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg', 'position' => 3 ] ], 'attributes' => [ [ 'id' => 6, 'position' => 0, 'visible' => false, 'variation' => true, 'options' => [ 'Black', 'Green' ] ], [ 'name' => 'Size', 'position' => 0, 'visible' => true, 'variation' => true, 'options' => [ 'S', 'M' ] ] ], 'default_attributes' => [ [ 'id' => 6, 'option' => 'Black' ], [ 'name' => 'Size', 'option' => 'S' ] ] ]; print_r($woocommerce->post('products', $data)); ?> ``` ```python data = { "name": "Ship Your Idea", "type": "variable", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg", "position": 1 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", "position": 2 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg", "position": 3 } ], "attributes": [ { "id": 6, "position": 0, "visible": False, "variation": True, "options": [ "Black", "Green" ] }, { "name": "Size", "position": 0, "visible": True, "variation": True, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "option": "Black" }, { "name": "Size", "option": "S" } ] } print(wcapi.post("products", data).json()) ``` ```ruby data = { name: "Ship Your Idea", type: "variable", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg", position: 1 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg", position: 2 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg", position: 3 } ], attributes: [ { id: 6, position: 0, visible: false, variation: true, options: [ "Black", "Green" ] }, { name: "Size", position: 0, visible: true, variation: true, options: [ "S", "M" ] } ], default_attributes: [ { id: 6, option: "Black" }, { name: "Size", option: "S" } ] } woocommerce.post("products", data).parsed_response ``` ```json { "id": 799, "name": "Ship Your Idea", "slug": "ship-your-idea-22", "permalink": "https://example.com/product/ship-your-idea-22/", "date_created": "2017-03-23T17:03:12", "date_created_gmt": "2017-03-23T20:03:12", "date_modified": "2017-03-23T17:03:12", "date_modified_gmt": "2017-03-23T20:03:12", "type": "variable", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "", "regular_price": "", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "", "on_sale": false, "purchasable": false, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 472, 387, 19, 53, 396 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 795, "date_created": "2017-03-23T14:03:08", "date_created_gmt": "2017-03-23T20:03:08", "date_modified": "2017-03-23T14:03:08", "date_modified_gmt": "2017-03-23T20:03:08", "src": "https://example.com/wp-content/uploads/2017/03/T_4_front-11.jpg", "name": "", "alt": "", "position": 0 }, { "id": 796, "date_created": "2017-03-23T14:03:09", "date_created_gmt": "2017-03-23T20:03:09", "date_modified": "2017-03-23T14:03:09", "date_modified_gmt": "2017-03-23T20:03:09", "src": "https://example.com/wp-content/uploads/2017/03/T_4_back-10.jpg", "name": "", "alt": "", "position": 1 }, { "id": 797, "date_created": "2017-03-23T14:03:10", "date_created_gmt": "2017-03-23T20:03:10", "date_modified": "2017-03-23T14:03:10", "date_modified_gmt": "2017-03-23T20:03:10", "src": "https://example.com/wp-content/uploads/2017/03/T_3_front-10.jpg", "name": "", "alt": "", "position": 2 }, { "id": 798, "date_created": "2017-03-23T14:03:11", "date_created_gmt": "2017-03-23T20:03:11", "date_modified": "2017-03-23T14:03:11", "date_modified_gmt": "2017-03-23T20:03:11", "src": "https://example.com/wp-content/uploads/2017/03/T_3_back-10.jpg", "name": "", "alt": "", "position": 3 } ], "attributes": [ { "id": 6, "name": "Color", "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "id": 0, "name": "Size", "position": 0, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "name": "Color", "option": "black" }, { "id": 0, "name": "Size", "option": "S" } ], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/799" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products" } ] } } ```
## Retrieve a product This API lets you retrieve and view a specific product by ID. ```http GET /wp-json/wc/v2/products/ ``` ```shell curl https://example.com/wp-json/wc/v2/products/794 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/794") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/794')); ?> ``` ```python print(wcapi.get("products/794").json()) ``` ```ruby woocommerce.get("products/794").parsed_response ``` ```json { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$21.99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 53, 40, 56, 479, 99 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 792, "date_created": "2017-03-23T14:01:13", "date_created_gmt": "2017-03-23T20:01:13", "date_modified": "2017-03-23T14:01:13", "date_modified_gmt": "2017-03-23T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "", "position": 0 }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products" } ] } } ```
## List all products This API helps you to view all the products. ```http GET /wp-json/wc/v2/products ``` ```shell curl https://example.com/wp-json/wc/v2/products \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products')); ?> ``` ```python print(wcapi.get("products").json()) ``` ```ruby woocommerce.get("products").parsed_response ``` ```json [ { "id": 799, "name": "Ship Your Idea", "slug": "ship-your-idea-22", "permalink": "https://example.com/product/ship-your-idea-22/", "date_created": "2017-03-23T17:03:12", "date_created_gmt": "2017-03-23T20:03:12", "date_modified": "2017-03-23T17:03:12", "date_modified_gmt": "2017-03-23T20:03:12", "type": "variable", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "", "regular_price": "", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "", "on_sale": false, "purchasable": false, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 31, 22, 369, 414, 56 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 795, "date_created": "2017-03-23T14:03:08", "date_created_gmt": "2017-03-23T20:03:08", "date_modified": "2017-03-23T14:03:08", "date_modified_gmt": "2017-03-23T20:03:08", "src": "https://example.com/wp-content/uploads/2017/03/T_4_front-11.jpg", "name": "", "alt": "", "position": 0 }, { "id": 796, "date_created": "2017-03-23T14:03:09", "date_created_gmt": "2017-03-23T20:03:09", "date_modified": "2017-03-23T14:03:09", "date_modified_gmt": "2017-03-23T20:03:09", "src": "https://example.com/wp-content/uploads/2017/03/T_4_back-10.jpg", "name": "", "alt": "", "position": 1 }, { "id": 797, "date_created": "2017-03-23T14:03:10", "date_created_gmt": "2017-03-23T20:03:10", "date_modified": "2017-03-23T14:03:10", "date_modified_gmt": "2017-03-23T20:03:10", "src": "https://example.com/wp-content/uploads/2017/03/T_3_front-10.jpg", "name": "", "alt": "", "position": 2 }, { "id": 798, "date_created": "2017-03-23T14:03:11", "date_created_gmt": "2017-03-23T20:03:11", "date_modified": "2017-03-23T14:03:11", "date_modified_gmt": "2017-03-23T20:03:11", "src": "https://example.com/wp-content/uploads/2017/03/T_3_back-10.jpg", "name": "", "alt": "", "position": 3 } ], "attributes": [ { "id": 6, "name": "Color", "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "id": 0, "name": "Size", "position": 0, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/799" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products" } ] } }, { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$21.99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 463, 47, 31, 387, 458 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 792, "date_created": "2017-03-23T14:01:13", "date_created_gmt": "2017-03-23T20:01:13", "date_modified": "2017-03-23T14:01:13", "date_modified_gmt": "2017-03-23T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "", "position": 0 }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [ { "id": 6, "name": "Color", "option": "black" }, { "id": 0, "name": "Size", "option": "S" } ], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products" } ] } } ] ```
#### Available parameters | Parameter | Type | Description | |------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `id`, `include`, `title` and `slug`. Default is `date`. | | `parent` | array | Limit result set to those of particular parent IDs. | | `parent_exclude` | array | Limit result set to all items except those of a particular parent ID. | | `slug` | string | Limit result set to products with a specific slug. | | `status` | string | Limit result set to products assigned a specific status. Options: `any`, `draft`, `pending`, `private` and `publish`. Default is `any`. | | `type` | string | Limit result set to products assigned a specific type. Options: `simple`, `grouped`, `external` and `variable`. | | `sku` | string | Limit result set to products with a specific SKU. | | `featured` | boolean | Limit result set to featured products. | | `category` | string | Limit result set to products assigned a specific category ID. | | `tag` | string | Limit result set to products assigned a specific tag ID. | | `shipping_class` | string | Limit result set to products assigned a specific shipping class ID. | | `attribute` | string | Limit result set to products with a specific attribute. | | `attribute_term` | string | Limit result set to products with a specific attribute term ID (required an assigned attribute). | | `tax_class` | string | Limit result set to products with a specific tax class. Default options: `standard`, `reduced-rate` and `zero-rate`. | | `in_stock` | boolean | Limit result set to products in stock or out of stock. | | `on_sale` | boolean | Limit result set to products on sale. | | `min_price` | string | Limit result set to products based on a minimum price. | | `max_price` | string | Limit result set to products based on a maximum price. | | `image_size` | string | Use a specific registered image size for the returned image `src` values. Falls back to the full size if the requested size is not registered. Default is `full`. | ## Update a product This API lets you make changes to a product. ```http PUT /wp-json/wc/v2/products/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/products/794 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "regular_price": "24.54" }' ``` ```javascript const data = { regular_price: "24.54" }; WooCommerce.put("products/794", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php '24.54' ]; print_r($woocommerce->put('products/794', $data)); ?> ``` ```python data = { "regular_price": "24.54" } print(wcapi.put("products/794", data).json()) ``` ```ruby data = { regular_price: "24.54" } woocommerce.put("products/794", data).parsed_response ``` ```json { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "24.54", "regular_price": "24.54", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$24.54", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 479, 387, 22, 463, 396 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 792, "date_created": "2017-03-23T14:01:13", "date_created_gmt": "2017-03-23T20:01:13", "date_modified": "2017-03-23T14:01:13", "date_modified_gmt": "2017-03-23T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "", "position": 0 }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products" } ] } } ```
## Delete a product This API helps you delete a product. ```http DELETE /wp-json/wc/v2/products/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/products/794?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("products/794", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('products/794', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/794", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/794", force: true).parsed_response ``` ```json { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "24.54", "regular_price": "24.54", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$24.54", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 479, 387, 22, 463, 396 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 792, "date_created": "2017-03-23T14:01:13", "date_created_gmt": "2017-03-23T20:01:13", "date_modified": "2017-03-23T14:01:13", "date_modified_gmt": "2017-03-23T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "", "position": 0 }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products" } ] } } ```
#### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------------------| | `force` | string | Use `true` whether to permanently delete the product, Default is `false`. | ## Batch update products This API helps you to batch create, update and delete multiple products. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/products/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/products/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Woo Single #1", "type": "simple", "regular_price": "21.99", "virtual": true, "downloadable": true, "downloads": [ { "name": "Woo Single", "file": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], "categories": [ { "id": 11 }, { "id": 13 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg", "position": 0 } ] }, { "name": "New Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", "position": 1 } ] } ], "update": [ { "id": 799, "default_attributes": [ { "id": 6, "name": "Color", "option": "Green" }, { "id": 0, "name": "Size", "option": "M" } ] } ], "delete": [ 794 ] }' ``` ```javascript const data = { create: [ { name: "Woo Single #1", type: "simple", regular_price: "21.99", virtual: true, downloadable: true, downloads: [ { name: "Woo Single", file: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], categories: [ { id: 11 }, { id: 13 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg", position: 0 } ] }, { name: "New Premium Quality", type: "simple", regular_price: "21.99", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", position: 1 } ] } ], update: [ { id: 799, default_attributes: [ { id: 6, name: "Color", option: "Green" }, { id: 0, name: "Size", option: "M" } ] } ], delete: [ 794 ] }; WooCommerce.post("products/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Woo Single #1', 'type' => 'simple', 'regular_price' => '21.99', 'virtual' => true, 'downloadable' => true, 'downloads' => [ [ 'name' => 'Woo Single', 'file' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg' ] ], 'categories' => [ [ 'id' => 11 ], [ 'id' => 13 ] ], 'images' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', 'position' => 0 ] ] ], [ 'name' => 'New Premium Quality', 'type' => 'simple', 'regular_price' => '21.99', 'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', 'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'categories' => [ [ 'id' => 9 ], [ 'id' => 14 ] ], 'images' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg', 'position' => 0 ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg', 'position' => 1 ] ] ] ], 'update' => [ [ 'id' => 799, 'default_attributes' => [ [ 'id' => 6, 'name' => 'Color', 'option' => 'Green' ], [ 'id' => 0, 'name' => 'Size', 'option' => 'M' ] ] ] ], 'delete' => [ 794 ] ]; print_r($woocommerce->post('products/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Woo Single #1", "type": "simple", "regular_price": "21.99", "virtual": True, "downloadable": True, "downloads": [ { "name": "Woo Single", "file": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], "categories": [ { "id": 11 }, { "id": 13 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg", "position": 0 } ] }, { "name": "New Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", "position": 0 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", "position": 1 } ] } ], "update": [ { "id": 799, "default_attributes": [ { "id": 6, "name": "Color", "option": "Green" }, { "id": 0, "name": "Size", "option": "M" } ] } ], "delete": [ 794 ] } print(wcapi.post("products/batch", data).json()) ``` ```ruby data = { create: [ { name: "Woo Single #1", type: "simple", regular_price: "21.99", virtual: true, downloadable: true, downloads: [ { name: "Woo Single", file: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], categories: [ { id: 11 }, { id: 13 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg", position: 0 } ] }, { name: "New Premium Quality", type: "simple", regular_price: "21.99", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg", position: 0 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", position: 1 } ] } ], update: [ { id: 799, default_attributes: [ { id: 6, name: "Color, option: "Green" }, { id: 0, name: "Size", option: "M" } ] } ], delete: [ 794 ] } woocommerce.post("products/batch", data).parsed_response ``` ```json { "create": [ { "id": 801, "name": "Woo Single #1", "slug": "woo-single-1-4", "permalink": "https://example.com/product/woo-single-1-4/", "date_created": "2017-03-23T17:35:43", "date_created_gmt": "2017-03-23T20:35:43", "date_modified": "2017-03-23T17:35:43", "date_modified_gmt": "2017-03-23T20:35:43", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "", "short_description": "", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$21.99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": true, "downloadable": true, "downloads": [ { "id": 0, "name": "Woo Single", "file": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": false, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 588, 87, 573, 96, 329 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 11, "name": "Music", "slug": "music" }, { "id": 13, "name": "Singles", "slug": "singles" } ], "tags": [], "images": [ { "id": 800, "date_created": "2017-03-23T14:35:43", "date_created_gmt": "2017-03-23T20:35:43", "date_modified": "2017-03-23T14:35:43", "date_modified_gmt": "2017-03-23T20:35:43", "src": "https://example.com/wp-content/uploads/2017/03/cd_4_angle.jpg", "name": "", "alt": "", "position": 0 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/801" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products" } ] } }, { "id": 804, "name": "New Premium Quality", "slug": "new-premium-quality", "permalink": "https://example.com/product/new-premium-quality/", "date_created": "2017-03-23T17:35:48", "date_created_gmt": "2017-03-23T20:35:48", "date_modified": "2017-03-23T17:35:48", "date_modified_gmt": "2017-03-23T20:35:48", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$21.99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 458, 56, 99, 34, 378 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 802, "date_created": "2017-03-23T14:35:47", "date_created_gmt": "2017-03-23T20:35:47", "date_modified": "2017-03-23T14:35:47", "date_modified_gmt": "2017-03-23T20:35:47", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-5.jpg", "name": "", "alt": "", "position": 0 }, { "id": 803, "date_created": "2017-03-23T14:35:48", "date_created_gmt": "2017-03-23T20:35:48", "date_modified": "2017-03-23T14:35:48", "date_modified_gmt": "2017-03-23T20:35:48", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-3.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/804" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products" } ] } } ], "update": [ { "id": 799, "name": "Ship Your Idea", "slug": "ship-your-idea-22", "permalink": "https://example.com/product/ship-your-idea-22/", "date_created": "2017-03-23T17:03:12", "date_created_gmt": "2017-03-23T20:03:12", "date_modified": "2017-03-23T17:03:12", "date_modified_gmt": "2017-03-23T20:03:12", "type": "variable", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "", "regular_price": "", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "", "on_sale": false, "purchasable": false, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 414, 40, 34, 463, 15 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 795, "date_created": "2017-03-23T14:03:08", "date_created_gmt": "2017-03-23T20:03:08", "date_modified": "2017-03-23T14:03:08", "date_modified_gmt": "2017-03-23T20:03:08", "src": "https://example.com/wp-content/uploads/2017/03/T_4_front-11.jpg", "name": "", "alt": "", "position": 0 }, { "id": 796, "date_created": "2017-03-23T14:03:09", "date_created_gmt": "2017-03-23T20:03:09", "date_modified": "2017-03-23T14:03:09", "date_modified_gmt": "2017-03-23T20:03:09", "src": "https://example.com/wp-content/uploads/2017/03/T_4_back-10.jpg", "name": "", "alt": "", "position": 1 }, { "id": 797, "date_created": "2017-03-23T14:03:10", "date_created_gmt": "2017-03-23T20:03:10", "date_modified": "2017-03-23T14:03:10", "date_modified_gmt": "2017-03-23T20:03:10", "src": "https://example.com/wp-content/uploads/2017/03/T_3_front-10.jpg", "name": "", "alt": "", "position": 2 }, { "id": 798, "date_created": "2017-03-23T14:03:11", "date_created_gmt": "2017-03-23T20:03:11", "date_modified": "2017-03-23T14:03:11", "date_modified_gmt": "2017-03-23T20:03:11", "src": "https://example.com/wp-content/uploads/2017/03/T_3_back-10.jpg", "name": "", "alt": "", "position": 3 } ], "attributes": [ { "id": 6, "name": "Color", "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "id": 0, "name": "Size", "position": 0, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "name": "Color", "option": "green" }, { "id": 0, "name": "Size", "option": "M" } ], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/799" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products" } ] } } ], "delete": [ { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "24.54", "regular_price": "24.54", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$24.54", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "in_stock": true, "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 369, 56, 378, 31, 22 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 792, "date_created": "2017-03-23T14:01:13", "date_created_gmt": "2017-03-23T20:01:13", "date_modified": "2017-03-23T14:01:13", "date_modified_gmt": "2017-03-23T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "", "position": 0 }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "", "position": 1 } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products" } ] } } ] } ```
## Retrieve product reviews This API lets you retrieve and view a specific product review by ID. ```http GET /wp-json/wc/v2/products//reviews/ ``` ```shell curl https://example.com/wp-json/wc/v2/products/22/reviews/5 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/products/22/reviews/5") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/22/reviews/5')); ?> ``` ```python print(wcapi.get("products/products/22/reviews/5").json()) ``` ```ruby woocommerce.get("products/products/22/reviews/5").parsed_response ``` ```json { "id": 5, "date_created": "2013-06-07T11:43:13", "date_created_gmt": "2013-06-07T11:43:13", "review": "Nice T-shirt, I got one in black. Goes with anything!", "rating": 4, "name": "James Koster", "email": "james@example.com", "verified": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/reviews/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } } ``` ## Product review properties | Attribute | Type | Description | |--------------------|-----------|--------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `review` | string | The content of the review. `MANDATORY` | | `date_created` | date-time | The date the review was created, in the site's timezone. | | `date_created_gmt` | date-time | The date the review was created, as GMT. | | `rating` | integer | Review rating (0 to 5). | | `name` | string | Reviewer name. `MANDATORY` | | `email` | string | Reviewer email. `MANDATORY` | | `verified` | boolean | Shows if the reviewer bought the product or not. `READ-ONLY` | ## List all product reviews This API lets you retrieve all reviews of a product. ```http GET /wp-json/wc/v2/products//reviews ``` ```shell curl https://example.com/wp-json/wc/v2/products/22/reviews \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("products/22/reviews") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('products/22/reviews')); ?> ``` ```python print(wcapi.get("products/22/reviews").json()) ``` ```ruby woocommerce.get("products/22/reviews").parsed_response ``` ```json [ { "id": 5, "date_created": "2013-06-07T11:43:13", "date_created_gmt": "2013-06-07T11:43:13", "review": "Nice T-shirt, I got one in black. Goes with anything!", "rating": 4, "name": "James Koster", "email": "james@example.com", "verified": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/reviews/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } }, { "id": 6, "date_created": "2013-06-07T11:55:15", "date_created_gmt": "2013-06-07T11:55:15", "review": "Very comfortable shirt, and I love the graphic!", "rating": 4, "name": "Cobus Bester", "email": "bester@example.com", "verified": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/reviews/6" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } }, { "id": 7, "date_created": "2013-06-07T13:02:14", "date_created_gmt": "2013-06-07T13:02:14", "review": "Great T-shirt quality, Great Design and Great Service.", "rating": 5, "name": "Stuart", "email": "stuart@example.com", "verified": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/products/22/reviews/7" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/products/22/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/products/22" } ] } } ] ``` --- ## Reports *Source: apis/rest-api/v2/reports.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Reports The reports API allows you to view all types of reports available. ## List all reports This API lets you retrieve and view a simple list of available reports. ```http GET /wp-json/wc/v2/reports ``` ```shell curl https://example.com/wp-json/wc/v2/reports \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("reports") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('reports')); ?> ``` ```python print(wcapi.get("reports").json()) ``` ```ruby woocommerce.get("reports").parsed_response ``` ```json [ { "slug": "sales", "description": "List of sales reports.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/reports/sales" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/reports" } ] } }, { "slug": "top_sellers", "description": "List of top sellers products.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/reports/top_sellers" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/reports" } ] } } ] ``` ## Retrieve sales report This API lets you retrieve and view a sales report. ```http GET /wp-json/wc/v2/reports/sales ``` ```shell curl https://example.com/wp-json/wc/v2/reports/sales?date_min=2016-05-03&date_max=2016-05-04 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("reports/sales", { date_min: "2016-05-03", date_max: "2016-05-04" }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php '2016-05-03', 'date_max' => '2016-05-04' ]; print_r($woocommerce->get('reports/sales', $query)); ?> ``` ```python print(wcapi.get("reports/sales?date_min=2016-05-03&date_max=2016-05-04").json()) ``` ```ruby query = { date_min: "2016-05-03", date_max: "2016-05-04" } woocommerce.get("reports/sales", query).parsed_response ``` ```json [ { "total_sales": "14.00", "net_sales": "4.00", "average_sales": "2.00", "total_orders": 3, "total_items": 6, "total_tax": "0.00", "total_shipping": "10.00", "total_refunds": 0, "total_discount": "0.00", "totals_grouped_by": "day", "totals": { "2016-05-03": { "sales": "14.00", "orders": 3, "items": 6, "tax": "0.00", "shipping": "10.00", "discount": "0.00", "customers": 0 }, "2016-05-04": { "sales": "0.00", "orders": 0, "items": 0, "tax": "0.00", "shipping": "0.00", "discount": "0.00", "customers": 0 } }, "total_customers": 0, "_links": { "about": [ { "href": "https://example.com/wp-json/wc/v2/reports" } ] } } ] ``` #### Sales report properties | Attribute | Type | Description | |---------------------|---------|-----------------------------------------------------------------------| | `total_sales` | string | Gross sales in the period. `READ-ONLY` | | `net_sales` | string | Net sales in the period. `READ-ONLY` | | `average_sales` | string | Average net daily sales. `READ-ONLY` | | `total_orders` | integer | Total of orders placed. `READ-ONLY` | | `total_items` | integer | Total of items purchased. `READ-ONLY` | | `total_tax` | string | Total charged for taxes. `READ-ONLY` | | `total_shipping` | string | Total charged for shipping. `READ-ONLY` | | `total_refunds` | number | Total of refunded orders. `READ-ONLY` | | `total_discount` | integer | Total of coupons used. `READ-ONLY` | | `totals_grouped_by` | string | Group type. `READ-ONLY` | | `totals` | array | Totals. `READ-ONLY` | #### Available parameters | Parameter | Type | Description | |------------|--------|-------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Default is `view`. Options: `view`. | | `period` | string | Report period. Default is today's date. Options: `week`, `month`, `last_month` and `year` | | `date_min` | string | Return sales for a specific start date, the date need to be in the YYYY-MM-DD format. | | `date_max` | string | Return sales for a specific end date, the date need to be in the YYYY-MM-DD format. | ## Retrieve top sellers report This API lets you retrieve and view a list of top sellers report. ```http GET /wp-json/wc/v2/reports/top_sellers ``` ```shell curl https://example.com/wp-json/wc/v2/reports/top_sellers?period=last_month \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("reports/top_sellers", { period: "last_month" }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'last_month' ]; print_r($woocommerce->get('reports/top_sellers', $query)); ?> ``` ```python print(wcapi.get("reports/top_sellers?period=last_month").json()) ``` ```ruby query = { period: "last_month" } woocommerce.get("reports/top_sellers", query).parsed_response ``` ```json [ { "title": "Happy Ninja", "product_id": 37, "quantity": 1, "_links": { "about": [ { "href": "https://example.com/wp-json/wc/v2/reports" } ], "product": [ { "href": "https://example.com/wp-json/wc/v2/products/37" } ] } }, { "title": "Woo Album #4", "product_id": 96, "quantity": 1, "_links": { "about": [ { "href": "https://example.com/wp-json/wc/v2/reports" } ], "product": [ { "href": "https://example.com/wp-json/wc/v2/products/96" } ] } } ] ``` #### Top sellers report properties | Attribute | Type | Description | |---------------------|---------|-----------------------------------------------------------------------| | `title` | string | Product title. `READ-ONLY` | | `product_id` | integer | Product ID. `READ-ONLY` | | `quantity` | integer | Total number of purchases. `READ-ONLY` | #### Available parameters | Parameter | Type | Description | |------------|--------|-------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Default is `view`. Options: `view`. | | `period` | string | Report period. Default is `week`. Options: `week`, `month`, `last_month` and `year` | | `date_min` | string | Return sales for a specific start date, the date need to be in the YYYY-MM-DD format. | | `date_max` | string | Return sales for a specific end date, the date need to be in the YYYY-MM-DD format. | --- ## Setting options *Source: apis/rest-api/v2/setting-options.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Setting options ## Setting option properties | Attribute | Type | Description | | ------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | string | A unique identifier for the setting. `READ-ONLY` | | `label` | string | A human readable label for the setting used in interfaces. `READ-ONLY` | | `description` | string | A human readable description for the setting used in interfaces. `READ-ONLY` | | `value` | mixed | Setting value. | | `default` | mixed | Default value for the setting. `READ-ONLY` | | `tip` | string | Additional help text shown to the user about the setting. `READ-ONLY` | | `placeholder` | string | Placeholder text to be displayed in text inputs. `READ-ONLY` | | `type` | string | Type of setting. Options: `text`, `email`, `number`, `color`, `password`, `textarea`, `select`, `multiselect`, `radio`, `image_width` and `checkbox`. `READ-ONLY` | | `options` | object | Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons. `READ-ONLY` | ## Retrieve an setting option This API lets you retrieve and view a specific setting option. ```http GET /wp-json/wc/v2/settings// ``` ```shell curl https://example.com/wp-json/wc/v2/settings/general/woocommerce_allowed_countries \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("settings/general/woocommerce_allowed_countries") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('settings/general/woocommerce_allowed_countries')); ?> ``` ```python print(wcapi.get("settings/general/woocommerce_allowed_countries").json()) ``` ```ruby woocommerce.get("settings/general/woocommerce_allowed_countries").parsed_response ``` ```json { "id": "woocommerce_allowed_countries", "label": "Selling location(s)", "description": "This option lets you limit which countries you are willing to sell to.", "type": "select", "default": "all", "options": { "all": "Sell to all countries", "all_except": "Sell to all countries, except for…", "specific": "Sell to specific countries" }, "tip": "This option lets you limit which countries you are willing to sell to.", "value": "all", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_allowed_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } } ``` ## List all setting options This API helps you to view all the setting options. ```http GET /wp-json/wc/v2/settings/ ``` ```shell curl https://example.com/wp-json/wc/v2/settings/general \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("settings/general") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('settings/general')); ?> ``` ```python print(wcapi.get("settings/general").json()) ``` ```ruby woocommerce.get("settings/general").parsed_response ``` ```json [ { "id": "woocommerce_allowed_countries", "label": "Selling location(s)", "description": "This option lets you limit which countries you are willing to sell to.", "type": "select", "default": "all", "options": { "all": "Sell to all countries", "all_except": "Sell to all countries, except for…", "specific": "Sell to specific countries" }, "tip": "This option lets you limit which countries you are willing to sell to.", "value": "all", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_allowed_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_all_except_countries", "label": "Sell to all countries, except for…", "description": "", "type": "multiselect", "default": "", "value": "", "options": { "AX": "Åland Islands", "AF": "Afghanistan", "AL": "Albania", "DZ": "Algeria", "AS": "American Samoa", "AD": "Andorra", "AO": "Angola", "AI": "Anguilla", "AQ": "Antarctica", "AG": "Antigua and Barbuda", "AR": "Argentina", "AM": "Armenia", "AW": "Aruba", "AU": "Australia", "AT": "Austria", "AZ": "Azerbaijan", "BS": "Bahamas", "BH": "Bahrain", "BD": "Bangladesh", "BB": "Barbados", "BY": "Belarus", "PW": "Belau", "BE": "Belgium", "BZ": "Belize", "BJ": "Benin", "BM": "Bermuda", "BT": "Bhutan", "BO": "Bolivia", "BQ": "Bonaire, Saint Eustatius and Saba", "BA": "Bosnia and Herzegovina", "BW": "Botswana", "BV": "Bouvet Island", "BR": "Brazil", "IO": "British Indian Ocean Territory", "VG": "British Virgin Islands", "BN": "Brunei", "BG": "Bulgaria", "BF": "Burkina Faso", "BI": "Burundi", "KH": "Cambodia", "CM": "Cameroon", "CA": "Canada", "CV": "Cape Verde", "KY": "Cayman Islands", "CF": "Central African Republic", "TD": "Chad", "CL": "Chile", "CN": "China", "CX": "Christmas Island", "CC": "Cocos (Keeling) Islands", "CO": "Colombia", "KM": "Comoros", "CG": "Congo (Brazzaville)", "CD": "Congo (Kinshasa)", "CK": "Cook Islands", "CR": "Costa Rica", "HR": "Croatia", "CU": "Cuba", "CW": "Curaçao", "CY": "Cyprus", "CZ": "Czech Republic", "DK": "Denmark", "DJ": "Djibouti", "DM": "Dominica", "DO": "Dominican Republic", "EC": "Ecuador", "EG": "Egypt", "SV": "El Salvador", "GQ": "Equatorial Guinea", "ER": "Eritrea", "EE": "Estonia", "ET": "Ethiopia", "FK": "Falkland Islands", "FO": "Faroe Islands", "FJ": "Fiji", "FI": "Finland", "FR": "France", "GF": "French Guiana", "PF": "French Polynesia", "TF": "French Southern Territories", "GA": "Gabon", "GM": "Gambia", "GE": "Georgia", "DE": "Germany", "GH": "Ghana", "GI": "Gibraltar", "GR": "Greece", "GL": "Greenland", "GD": "Grenada", "GP": "Guadeloupe", "GU": "Guam", "GT": "Guatemala", "GG": "Guernsey", "GN": "Guinea", "GW": "Guinea-Bissau", "GY": "Guyana", "HT": "Haiti", "HM": "Heard Island and McDonald Islands", "HN": "Honduras", "HK": "Hong Kong", "HU": "Hungary", "IS": "Iceland", "IN": "India", "ID": "Indonesia", "IR": "Iran", "IQ": "Iraq", "IE": "Ireland", "IM": "Isle of Man", "IL": "Israel", "IT": "Italy", "CI": "Ivory Coast", "JM": "Jamaica", "JP": "Japan", "JE": "Jersey", "JO": "Jordan", "KZ": "Kazakhstan", "KE": "Kenya", "KI": "Kiribati", "KW": "Kuwait", "KG": "Kyrgyzstan", "LA": "Laos", "LV": "Latvia", "LB": "Lebanon", "LS": "Lesotho", "LR": "Liberia", "LY": "Libya", "LI": "Liechtenstein", "LT": "Lithuania", "LU": "Luxembourg", "MO": "Macao S.A.R., China", "MK": "Macedonia", "MG": "Madagascar", "MW": "Malawi", "MY": "Malaysia", "MV": "Maldives", "ML": "Mali", "MT": "Malta", "MH": "Marshall Islands", "MQ": "Martinique", "MR": "Mauritania", "MU": "Mauritius", "YT": "Mayotte", "MX": "Mexico", "FM": "Micronesia", "MD": "Moldova", "MC": "Monaco", "MN": "Mongolia", "ME": "Montenegro", "MS": "Montserrat", "MA": "Morocco", "MZ": "Mozambique", "MM": "Myanmar", "NA": "Namibia", "NR": "Nauru", "NP": "Nepal", "NL": "Netherlands", "NC": "New Caledonia", "NZ": "New Zealand", "NI": "Nicaragua", "NE": "Niger", "NG": "Nigeria", "NU": "Niue", "NF": "Norfolk Island", "KP": "North Korea", "MP": "Northern Mariana Islands", "NO": "Norway", "OM": "Oman", "PK": "Pakistan", "PS": "Palestinian Territory", "PA": "Panama", "PG": "Papua New Guinea", "PY": "Paraguay", "PE": "Peru", "PH": "Philippines", "PN": "Pitcairn", "PL": "Poland", "PT": "Portugal", "PR": "Puerto Rico", "QA": "Qatar", "RE": "Reunion", "RO": "Romania", "RU": "Russia", "RW": "Rwanda", "ST": "São Tomé and Príncipe", "BL": "Saint Barthélemy", "SH": "Saint Helena", "KN": "Saint Kitts and Nevis", "LC": "Saint Lucia", "SX": "Saint Martin (Dutch part)", "MF": "Saint Martin (French part)", "PM": "Saint Pierre and Miquelon", "VC": "Saint Vincent and the Grenadines", "WS": "Samoa", "SM": "San Marino", "SA": "Saudi Arabia", "SN": "Senegal", "RS": "Serbia", "SC": "Seychelles", "SL": "Sierra Leone", "SG": "Singapore", "SK": "Slovakia", "SI": "Slovenia", "SB": "Solomon Islands", "SO": "Somalia", "ZA": "South Africa", "GS": "South Georgia/Sandwich Islands", "KR": "South Korea", "SS": "South Sudan", "ES": "Spain", "LK": "Sri Lanka", "SD": "Sudan", "SR": "Suriname", "SJ": "Svalbard and Jan Mayen", "SZ": "Swaziland", "SE": "Sweden", "CH": "Switzerland", "SY": "Syria", "TW": "Taiwan", "TJ": "Tajikistan", "TZ": "Tanzania", "TH": "Thailand", "TL": "Timor-Leste", "TG": "Togo", "TK": "Tokelau", "TO": "Tonga", "TT": "Trinidad and Tobago", "TN": "Tunisia", "TR": "Turkey", "TM": "Turkmenistan", "TC": "Turks and Caicos Islands", "TV": "Tuvalu", "UG": "Uganda", "UA": "Ukraine", "AE": "United Arab Emirates", "GB": "United Kingdom (UK)", "US": "United States (US)", "UM": "United States (US) Minor Outlying Islands", "VI": "United States (US) Virgin Islands", "UY": "Uruguay", "UZ": "Uzbekistan", "VU": "Vanuatu", "VA": "Vatican", "VE": "Venezuela", "VN": "Vietnam", "WF": "Wallis and Futuna", "EH": "Western Sahara", "YE": "Yemen", "ZM": "Zambia", "ZW": "Zimbabwe" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_all_except_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_specific_allowed_countries", "label": "Sell to specific countries", "description": "", "type": "multiselect", "default": "", "value": "", "options": { "AX": "Åland Islands", "AF": "Afghanistan", "AL": "Albania", "DZ": "Algeria", "AS": "American Samoa", "AD": "Andorra", "AO": "Angola", "AI": "Anguilla", "AQ": "Antarctica", "AG": "Antigua and Barbuda", "AR": "Argentina", "AM": "Armenia", "AW": "Aruba", "AU": "Australia", "AT": "Austria", "AZ": "Azerbaijan", "BS": "Bahamas", "BH": "Bahrain", "BD": "Bangladesh", "BB": "Barbados", "BY": "Belarus", "PW": "Belau", "BE": "Belgium", "BZ": "Belize", "BJ": "Benin", "BM": "Bermuda", "BT": "Bhutan", "BO": "Bolivia", "BQ": "Bonaire, Saint Eustatius and Saba", "BA": "Bosnia and Herzegovina", "BW": "Botswana", "BV": "Bouvet Island", "BR": "Brazil", "IO": "British Indian Ocean Territory", "VG": "British Virgin Islands", "BN": "Brunei", "BG": "Bulgaria", "BF": "Burkina Faso", "BI": "Burundi", "KH": "Cambodia", "CM": "Cameroon", "CA": "Canada", "CV": "Cape Verde", "KY": "Cayman Islands", "CF": "Central African Republic", "TD": "Chad", "CL": "Chile", "CN": "China", "CX": "Christmas Island", "CC": "Cocos (Keeling) Islands", "CO": "Colombia", "KM": "Comoros", "CG": "Congo (Brazzaville)", "CD": "Congo (Kinshasa)", "CK": "Cook Islands", "CR": "Costa Rica", "HR": "Croatia", "CU": "Cuba", "CW": "Curaçao", "CY": "Cyprus", "CZ": "Czech Republic", "DK": "Denmark", "DJ": "Djibouti", "DM": "Dominica", "DO": "Dominican Republic", "EC": "Ecuador", "EG": "Egypt", "SV": "El Salvador", "GQ": "Equatorial Guinea", "ER": "Eritrea", "EE": "Estonia", "ET": "Ethiopia", "FK": "Falkland Islands", "FO": "Faroe Islands", "FJ": "Fiji", "FI": "Finland", "FR": "France", "GF": "French Guiana", "PF": "French Polynesia", "TF": "French Southern Territories", "GA": "Gabon", "GM": "Gambia", "GE": "Georgia", "DE": "Germany", "GH": "Ghana", "GI": "Gibraltar", "GR": "Greece", "GL": "Greenland", "GD": "Grenada", "GP": "Guadeloupe", "GU": "Guam", "GT": "Guatemala", "GG": "Guernsey", "GN": "Guinea", "GW": "Guinea-Bissau", "GY": "Guyana", "HT": "Haiti", "HM": "Heard Island and McDonald Islands", "HN": "Honduras", "HK": "Hong Kong", "HU": "Hungary", "IS": "Iceland", "IN": "India", "ID": "Indonesia", "IR": "Iran", "IQ": "Iraq", "IE": "Ireland", "IM": "Isle of Man", "IL": "Israel", "IT": "Italy", "CI": "Ivory Coast", "JM": "Jamaica", "JP": "Japan", "JE": "Jersey", "JO": "Jordan", "KZ": "Kazakhstan", "KE": "Kenya", "KI": "Kiribati", "KW": "Kuwait", "KG": "Kyrgyzstan", "LA": "Laos", "LV": "Latvia", "LB": "Lebanon", "LS": "Lesotho", "LR": "Liberia", "LY": "Libya", "LI": "Liechtenstein", "LT": "Lithuania", "LU": "Luxembourg", "MO": "Macao S.A.R., China", "MK": "Macedonia", "MG": "Madagascar", "MW": "Malawi", "MY": "Malaysia", "MV": "Maldives", "ML": "Mali", "MT": "Malta", "MH": "Marshall Islands", "MQ": "Martinique", "MR": "Mauritania", "MU": "Mauritius", "YT": "Mayotte", "MX": "Mexico", "FM": "Micronesia", "MD": "Moldova", "MC": "Monaco", "MN": "Mongolia", "ME": "Montenegro", "MS": "Montserrat", "MA": "Morocco", "MZ": "Mozambique", "MM": "Myanmar", "NA": "Namibia", "NR": "Nauru", "NP": "Nepal", "NL": "Netherlands", "NC": "New Caledonia", "NZ": "New Zealand", "NI": "Nicaragua", "NE": "Niger", "NG": "Nigeria", "NU": "Niue", "NF": "Norfolk Island", "KP": "North Korea", "MP": "Northern Mariana Islands", "NO": "Norway", "OM": "Oman", "PK": "Pakistan", "PS": "Palestinian Territory", "PA": "Panama", "PG": "Papua New Guinea", "PY": "Paraguay", "PE": "Peru", "PH": "Philippines", "PN": "Pitcairn", "PL": "Poland", "PT": "Portugal", "PR": "Puerto Rico", "QA": "Qatar", "RE": "Reunion", "RO": "Romania", "RU": "Russia", "RW": "Rwanda", "ST": "São Tomé and Príncipe", "BL": "Saint Barthélemy", "SH": "Saint Helena", "KN": "Saint Kitts and Nevis", "LC": "Saint Lucia", "SX": "Saint Martin (Dutch part)", "MF": "Saint Martin (French part)", "PM": "Saint Pierre and Miquelon", "VC": "Saint Vincent and the Grenadines", "WS": "Samoa", "SM": "San Marino", "SA": "Saudi Arabia", "SN": "Senegal", "RS": "Serbia", "SC": "Seychelles", "SL": "Sierra Leone", "SG": "Singapore", "SK": "Slovakia", "SI": "Slovenia", "SB": "Solomon Islands", "SO": "Somalia", "ZA": "South Africa", "GS": "South Georgia/Sandwich Islands", "KR": "South Korea", "SS": "South Sudan", "ES": "Spain", "LK": "Sri Lanka", "SD": "Sudan", "SR": "Suriname", "SJ": "Svalbard and Jan Mayen", "SZ": "Swaziland", "SE": "Sweden", "CH": "Switzerland", "SY": "Syria", "TW": "Taiwan", "TJ": "Tajikistan", "TZ": "Tanzania", "TH": "Thailand", "TL": "Timor-Leste", "TG": "Togo", "TK": "Tokelau", "TO": "Tonga", "TT": "Trinidad and Tobago", "TN": "Tunisia", "TR": "Turkey", "TM": "Turkmenistan", "TC": "Turks and Caicos Islands", "TV": "Tuvalu", "UG": "Uganda", "UA": "Ukraine", "AE": "United Arab Emirates", "GB": "United Kingdom (UK)", "US": "United States (US)", "UM": "United States (US) Minor Outlying Islands", "VI": "United States (US) Virgin Islands", "UY": "Uruguay", "UZ": "Uzbekistan", "VU": "Vanuatu", "VA": "Vatican", "VE": "Venezuela", "VN": "Vietnam", "WF": "Wallis and Futuna", "EH": "Western Sahara", "YE": "Yemen", "ZM": "Zambia", "ZW": "Zimbabwe" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_specific_allowed_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_ship_to_countries", "label": "Shipping location(s)", "description": "Choose which countries you want to ship to, or choose to ship to all locations you sell to.", "type": "select", "default": "", "options": { "": "Ship to all countries you sell to", "all": "Ship to all countries", "specific": "Ship to specific countries only", "disabled": "Disable shipping & shipping calculations" }, "tip": "Choose which countries you want to ship to, or choose to ship to all locations you sell to.", "value": "", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_ship_to_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_specific_ship_to_countries", "label": "Ship to specific countries", "description": "", "type": "multiselect", "default": "", "value": "", "options": { "AX": "Åland Islands", "AF": "Afghanistan", "AL": "Albania", "DZ": "Algeria", "AS": "American Samoa", "AD": "Andorra", "AO": "Angola", "AI": "Anguilla", "AQ": "Antarctica", "AG": "Antigua and Barbuda", "AR": "Argentina", "AM": "Armenia", "AW": "Aruba", "AU": "Australia", "AT": "Austria", "AZ": "Azerbaijan", "BS": "Bahamas", "BH": "Bahrain", "BD": "Bangladesh", "BB": "Barbados", "BY": "Belarus", "PW": "Belau", "BE": "Belgium", "BZ": "Belize", "BJ": "Benin", "BM": "Bermuda", "BT": "Bhutan", "BO": "Bolivia", "BQ": "Bonaire, Saint Eustatius and Saba", "BA": "Bosnia and Herzegovina", "BW": "Botswana", "BV": "Bouvet Island", "BR": "Brazil", "IO": "British Indian Ocean Territory", "VG": "British Virgin Islands", "BN": "Brunei", "BG": "Bulgaria", "BF": "Burkina Faso", "BI": "Burundi", "KH": "Cambodia", "CM": "Cameroon", "CA": "Canada", "CV": "Cape Verde", "KY": "Cayman Islands", "CF": "Central African Republic", "TD": "Chad", "CL": "Chile", "CN": "China", "CX": "Christmas Island", "CC": "Cocos (Keeling) Islands", "CO": "Colombia", "KM": "Comoros", "CG": "Congo (Brazzaville)", "CD": "Congo (Kinshasa)", "CK": "Cook Islands", "CR": "Costa Rica", "HR": "Croatia", "CU": "Cuba", "CW": "Curaçao", "CY": "Cyprus", "CZ": "Czech Republic", "DK": "Denmark", "DJ": "Djibouti", "DM": "Dominica", "DO": "Dominican Republic", "EC": "Ecuador", "EG": "Egypt", "SV": "El Salvador", "GQ": "Equatorial Guinea", "ER": "Eritrea", "EE": "Estonia", "ET": "Ethiopia", "FK": "Falkland Islands", "FO": "Faroe Islands", "FJ": "Fiji", "FI": "Finland", "FR": "France", "GF": "French Guiana", "PF": "French Polynesia", "TF": "French Southern Territories", "GA": "Gabon", "GM": "Gambia", "GE": "Georgia", "DE": "Germany", "GH": "Ghana", "GI": "Gibraltar", "GR": "Greece", "GL": "Greenland", "GD": "Grenada", "GP": "Guadeloupe", "GU": "Guam", "GT": "Guatemala", "GG": "Guernsey", "GN": "Guinea", "GW": "Guinea-Bissau", "GY": "Guyana", "HT": "Haiti", "HM": "Heard Island and McDonald Islands", "HN": "Honduras", "HK": "Hong Kong", "HU": "Hungary", "IS": "Iceland", "IN": "India", "ID": "Indonesia", "IR": "Iran", "IQ": "Iraq", "IE": "Ireland", "IM": "Isle of Man", "IL": "Israel", "IT": "Italy", "CI": "Ivory Coast", "JM": "Jamaica", "JP": "Japan", "JE": "Jersey", "JO": "Jordan", "KZ": "Kazakhstan", "KE": "Kenya", "KI": "Kiribati", "KW": "Kuwait", "KG": "Kyrgyzstan", "LA": "Laos", "LV": "Latvia", "LB": "Lebanon", "LS": "Lesotho", "LR": "Liberia", "LY": "Libya", "LI": "Liechtenstein", "LT": "Lithuania", "LU": "Luxembourg", "MO": "Macao S.A.R., China", "MK": "Macedonia", "MG": "Madagascar", "MW": "Malawi", "MY": "Malaysia", "MV": "Maldives", "ML": "Mali", "MT": "Malta", "MH": "Marshall Islands", "MQ": "Martinique", "MR": "Mauritania", "MU": "Mauritius", "YT": "Mayotte", "MX": "Mexico", "FM": "Micronesia", "MD": "Moldova", "MC": "Monaco", "MN": "Mongolia", "ME": "Montenegro", "MS": "Montserrat", "MA": "Morocco", "MZ": "Mozambique", "MM": "Myanmar", "NA": "Namibia", "NR": "Nauru", "NP": "Nepal", "NL": "Netherlands", "NC": "New Caledonia", "NZ": "New Zealand", "NI": "Nicaragua", "NE": "Niger", "NG": "Nigeria", "NU": "Niue", "NF": "Norfolk Island", "KP": "North Korea", "MP": "Northern Mariana Islands", "NO": "Norway", "OM": "Oman", "PK": "Pakistan", "PS": "Palestinian Territory", "PA": "Panama", "PG": "Papua New Guinea", "PY": "Paraguay", "PE": "Peru", "PH": "Philippines", "PN": "Pitcairn", "PL": "Poland", "PT": "Portugal", "PR": "Puerto Rico", "QA": "Qatar", "RE": "Reunion", "RO": "Romania", "RU": "Russia", "RW": "Rwanda", "ST": "São Tomé and Príncipe", "BL": "Saint Barthélemy", "SH": "Saint Helena", "KN": "Saint Kitts and Nevis", "LC": "Saint Lucia", "SX": "Saint Martin (Dutch part)", "MF": "Saint Martin (French part)", "PM": "Saint Pierre and Miquelon", "VC": "Saint Vincent and the Grenadines", "WS": "Samoa", "SM": "San Marino", "SA": "Saudi Arabia", "SN": "Senegal", "RS": "Serbia", "SC": "Seychelles", "SL": "Sierra Leone", "SG": "Singapore", "SK": "Slovakia", "SI": "Slovenia", "SB": "Solomon Islands", "SO": "Somalia", "ZA": "South Africa", "GS": "South Georgia/Sandwich Islands", "KR": "South Korea", "SS": "South Sudan", "ES": "Spain", "LK": "Sri Lanka", "SD": "Sudan", "SR": "Suriname", "SJ": "Svalbard and Jan Mayen", "SZ": "Swaziland", "SE": "Sweden", "CH": "Switzerland", "SY": "Syria", "TW": "Taiwan", "TJ": "Tajikistan", "TZ": "Tanzania", "TH": "Thailand", "TL": "Timor-Leste", "TG": "Togo", "TK": "Tokelau", "TO": "Tonga", "TT": "Trinidad and Tobago", "TN": "Tunisia", "TR": "Turkey", "TM": "Turkmenistan", "TC": "Turks and Caicos Islands", "TV": "Tuvalu", "UG": "Uganda", "UA": "Ukraine", "AE": "United Arab Emirates", "GB": "United Kingdom (UK)", "US": "United States (US)", "UM": "United States (US) Minor Outlying Islands", "VI": "United States (US) Virgin Islands", "UY": "Uruguay", "UZ": "Uzbekistan", "VU": "Vanuatu", "VA": "Vatican", "VE": "Venezuela", "VN": "Vietnam", "WF": "Wallis and Futuna", "EH": "Western Sahara", "YE": "Yemen", "ZM": "Zambia", "ZW": "Zimbabwe" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_specific_ship_to_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_default_customer_address", "label": "Default customer location", "description": "", "type": "select", "default": "geolocation", "options": { "": "No location by default", "base": "Shop base address", "geolocation": "Geolocate", "geolocation_ajax": "Geolocate (with page caching support)" }, "tip": "This option determines a customers default location. The MaxMind GeoLite Database will be periodically downloaded to your wp-content directory if using geolocation.", "value": "geolocation", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_default_customer_address" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_calc_taxes", "label": "Enable taxes", "description": "Enable taxes and tax calculations", "type": "checkbox", "default": "no", "value": "yes", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_calc_taxes" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_demo_store", "label": "Store notice", "description": "Enable site-wide store notice text", "type": "checkbox", "default": "no", "value": "no", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_demo_store" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_demo_store_notice", "label": "Store notice text", "description": "", "type": "textarea", "default": "This is a demo store for testing purposes — no orders shall be fulfilled.", "value": "This is a demo store for testing purposes — no orders shall be fulfilled.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_demo_store_notice" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_currency", "label": "Currency", "description": "This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.", "type": "select", "default": "GBP", "options": { "AED": "United Arab Emirates dirham (د.إ)", "AFN": "Afghan afghani (؋)", "ALL": "Albanian lek (L)", "AMD": "Armenian dram (AMD)", "ANG": "Netherlands Antillean guilder (ƒ)", "AOA": "Angolan kwanza (Kz)", "ARS": "Argentine peso ($)", "AUD": "Australian dollar ($)", "AWG": "Aruban florin (ƒ)", "AZN": "Azerbaijani manat (AZN)", "BAM": "Bosnia and Herzegovina convertible mark (KM)", "BBD": "Barbadian dollar ($)", "BDT": "Bangladeshi taka (৳ )", "BGN": "Bulgarian lev (лв.)", "BHD": "Bahraini dinar (.د.ب)", "BIF": "Burundian franc (Fr)", "BMD": "Bermudian dollar ($)", "BND": "Brunei dollar ($)", "BOB": "Bolivian boliviano (Bs.)", "BRL": "Brazilian real (R$)", "BSD": "Bahamian dollar ($)", "BTC": "Bitcoin (฿)", "BTN": "Bhutanese ngultrum (Nu.)", "BWP": "Botswana pula (P)", "BYR": "Belarusian ruble (Br)", "BZD": "Belize dollar ($)", "CAD": "Canadian dollar ($)", "CDF": "Congolese franc (Fr)", "CHF": "Swiss franc (CHF)", "CLP": "Chilean peso ($)", "CNY": "Chinese yuan (¥)", "COP": "Colombian peso ($)", "CRC": "Costa Rican colón (₡)", "CUC": "Cuban convertible peso ($)", "CUP": "Cuban peso ($)", "CVE": "Cape Verdean escudo ($)", "CZK": "Czech koruna (Kč)", "DJF": "Djiboutian franc (Fr)", "DKK": "Danish krone (DKK)", "DOP": "Dominican peso (RD$)", "DZD": "Algerian dinar (د.ج)", "EGP": "Egyptian pound (EGP)", "ERN": "Eritrean nakfa (Nfk)", "ETB": "Ethiopian birr (Br)", "EUR": "Euro (€)", "FJD": "Fijian dollar ($)", "FKP": "Falkland Islands pound (£)", "GBP": "Pound sterling (£)", "GEL": "Georgian lari (ლ)", "GGP": "Guernsey pound (£)", "GHS": "Ghana cedi (₵)", "GIP": "Gibraltar pound (£)", "GMD": "Gambian dalasi (D)", "GNF": "Guinean franc (Fr)", "GTQ": "Guatemalan quetzal (Q)", "GYD": "Guyanese dollar ($)", "HKD": "Hong Kong dollar ($)", "HNL": "Honduran lempira (L)", "HRK": "Croatian kuna (Kn)", "HTG": "Haitian gourde (G)", "HUF": "Hungarian forint (Ft)", "IDR": "Indonesian rupiah (Rp)", "ILS": "Israeli new shekel (₪)", "IMP": "Manx pound (£)", "INR": "Indian rupee (₹)", "IQD": "Iraqi dinar (ع.د)", "IRR": "Iranian rial (﷼)", "IRT": "Iranian toman (تومان)", "ISK": "Icelandic króna (kr.)", "JEP": "Jersey pound (£)", "JMD": "Jamaican dollar ($)", "JOD": "Jordanian dinar (د.ا)", "JPY": "Japanese yen (¥)", "KES": "Kenyan shilling (KSh)", "KGS": "Kyrgyzstani som (сом)", "KHR": "Cambodian riel (៛)", "KMF": "Comorian franc (Fr)", "KPW": "North Korean won (₩)", "KRW": "South Korean won (₩)", "KWD": "Kuwaiti dinar (د.ك)", "KYD": "Cayman Islands dollar ($)", "KZT": "Kazakhstani tenge (KZT)", "LAK": "Lao kip (₭)", "LBP": "Lebanese pound (ل.ل)", "LKR": "Sri Lankan rupee (රු)", "LRD": "Liberian dollar ($)", "LSL": "Lesotho loti (L)", "LYD": "Libyan dinar (ل.د)", "MAD": "Moroccan dirham (د.م.)", "MDL": "Moldovan leu (MDL)", "MGA": "Malagasy ariary (Ar)", "MKD": "Macedonian denar (ден)", "MMK": "Burmese kyat (Ks)", "MNT": "Mongolian tögrög (₮)", "MOP": "Macanese pataca (P)", "MRO": "Mauritanian ouguiya (UM)", "MUR": "Mauritian rupee (₨)", "MVR": "Maldivian rufiyaa (.ރ)", "MWK": "Malawian kwacha (MK)", "MXN": "Mexican peso ($)", "MYR": "Malaysian ringgit (RM)", "MZN": "Mozambican metical (MT)", "NAD": "Namibian dollar ($)", "NGN": "Nigerian naira (₦)", "NIO": "Nicaraguan córdoba (C$)", "NOK": "Norwegian krone (kr)", "NPR": "Nepalese rupee (₨)", "NZD": "New Zealand dollar ($)", "OMR": "Omani rial (ر.ع.)", "PAB": "Panamanian balboa (B/.)", "PEN": "Peruvian nuevo sol (S/.)", "PGK": "Papua New Guinean kina (K)", "PHP": "Philippine peso (₱)", "PKR": "Pakistani rupee (₨)", "PLN": "Polish złoty (zł)", "PRB": "Transnistrian ruble (р.)", "PYG": "Paraguayan guaraní (₲)", "QAR": "Qatari riyal (ر.ق)", "RON": "Romanian leu (lei)", "RSD": "Serbian dinar (дин.)", "RUB": "Russian ruble (₽)", "RWF": "Rwandan franc (Fr)", "SAR": "Saudi riyal (ر.س)", "SBD": "Solomon Islands dollar ($)", "SCR": "Seychellois rupee (₨)", "SDG": "Sudanese pound (ج.س.)", "SEK": "Swedish krona (kr)", "SGD": "Singapore dollar ($)", "SHP": "Saint Helena pound (£)", "SLL": "Sierra Leonean leone (Le)", "SOS": "Somali shilling (Sh)", "SRD": "Surinamese dollar ($)", "SSP": "South Sudanese pound (£)", "STD": "São Tomé and Príncipe dobra (Db)", "SYP": "Syrian pound (ل.س)", "SZL": "Swazi lilangeni (L)", "THB": "Thai baht (฿)", "TJS": "Tajikistani somoni (ЅМ)", "TMT": "Turkmenistan manat (m)", "TND": "Tunisian dinar (د.ت)", "TOP": "Tongan paʻanga (T$)", "TRY": "Turkish lira (₺)", "TTD": "Trinidad and Tobago dollar ($)", "TWD": "New Taiwan dollar (NT$)", "TZS": "Tanzanian shilling (Sh)", "UAH": "Ukrainian hryvnia (₴)", "UGX": "Ugandan shilling (UGX)", "USD": "United States dollar ($)", "UYU": "Uruguayan peso ($)", "UZS": "Uzbekistani som (UZS)", "VEF": "Venezuelan bolívar (Bs F)", "VND": "Vietnamese đồng (₫)", "VUV": "Vanuatu vatu (Vt)", "WST": "Samoan tālā (T)", "XAF": "Central African CFA franc (Fr)", "XCD": "East Caribbean dollar ($)", "XOF": "West African CFA franc (Fr)", "XPF": "CFP franc (Fr)", "YER": "Yemeni rial (﷼)", "ZAR": "South African rand (R)", "ZMW": "Zambian kwacha (K)" }, "tip": "This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.", "value": "USD", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_currency" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_currency_pos", "label": "Currency position", "description": "This controls the position of the currency symbol.", "type": "select", "default": "left", "options": { "left": "Left ($99.99)", "right": "Right (99.99$)", "left_space": "Left with space ($ 99.99)", "right_space": "Right with space (99.99 $)" }, "tip": "This controls the position of the currency symbol.", "value": "left", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_currency_pos" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_price_thousand_sep", "label": "Thousand separator", "description": "This sets the thousand separator of displayed prices.", "type": "text", "default": ",", "tip": "This sets the thousand separator of displayed prices.", "value": ",", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_price_thousand_sep" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_price_decimal_sep", "label": "Decimal separator", "description": "This sets the decimal separator of displayed prices.", "type": "text", "default": ".", "tip": "This sets the decimal separator of displayed prices.", "value": ".", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_price_decimal_sep" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_price_num_decimals", "label": "Number of decimals", "description": "This sets the number of decimal points shown in displayed prices.", "type": "number", "default": "2", "tip": "This sets the number of decimal points shown in displayed prices.", "value": "2", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_price_num_decimals" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } } ] ``` ## Update a setting option This API lets you make changes to a setting option. ```http PUT /wp-json/wc/v2/settings// ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/settings/general/woocommerce_allowed_countries \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "value": "all_except" }' ``` ```javascript const data = { value: "all_except" }; WooCommerce.put("settings/general/woocommerce_allowed_countries", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'all_except' ]; print_r($woocommerce->put('settings/general/woocommerce_allowed_countries', $data)); ?> ``` ```python data = { "value": "all_except" } print(wcapi.put("settings/general/woocommerce_allowed_countries", data).json()) ``` ```ruby data = { value: "all_except" } woocommerce.put("settings/general/woocommerce_allowed_countries", data).parsed_response ``` ```json { "id": "woocommerce_allowed_countries", "label": "Selling location(s)", "description": "This option lets you limit which countries you are willing to sell to.", "type": "select", "default": "all", "options": { "all": "Sell to all countries", "all_except": "Sell to all countries, except for…", "specific": "Sell to specific countries" }, "tip": "This option lets you limit which countries you are willing to sell to.", "value": "all_except", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_allowed_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } } ``` ## Batch update setting options This API helps you to batch update multiple setting options. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/settings//batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/settings/general/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "update": [ { "id": "woocommerce_allowed_countries", "value": "all" }, { "id": "woocommerce_demo_store", "value": "yes" }, { "id": "woocommerce_currency", "value": "GBP" } ] }' ``` ```javascript const data = { create: [ { regular_price: "10.00", attributes: [ { id: 6, option: "Blue" } ] }, { regular_price: "10.00", attributes: [ { id: 6, option: "White" } ] } ], update: [ { id: 733, regular_price: "10.00" } ], delete: [ 732 ] }; WooCommerce.post("products/22/settings/general/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'regular_price' => '10.00', 'attributes' => [ [ 'id' => 6, 'option' => 'Blue' ] ] ], [ 'regular_price' => '10.00', 'attributes' => [ [ 'id' => 6, 'option' => 'White' ] ] ] ], 'update' => [ [ 'id' => 733, 'regular_price' => '10.00' ] ], 'delete' => [ 732 ] ]; print_r($woocommerce->post('products/22/settings/general/batch', $data)); ?> ``` ```python data = { "create": [ { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "Blue" } ] }, { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "White" } ] } ], "update": [ { "id": 733, "regular_price": "10.00" } ], "delete": [ 732 ] } print(wcapi.post("products/22/settings/general/batch", data).json()) ``` ```ruby data = { create: [ { regular_price: "10.00", attributes: [ { id: 6, option: "Blue" } ] }, { regular_price: "10.00", attributes: [ { id: 6, option: "White" } ] } ], update: [ { id: 733, regular_price: "10.00" } ], delete: [ 732 ] } woocommerce.post("products/22/settings/general/batch", data).parsed_response ``` ```json { "update": [ { "id": "woocommerce_allowed_countries", "label": "Selling location(s)", "description": "This option lets you limit which countries you are willing to sell to.", "type": "select", "default": "all", "options": { "all": "Sell to all countries", "all_except": "Sell to all countries, except for…", "specific": "Sell to specific countries" }, "tip": "This option lets you limit which countries you are willing to sell to.", "value": "all", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_allowed_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_demo_store", "label": "Store notice", "description": "Enable site-wide store notice text", "type": "checkbox", "default": "no", "value": "yes", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_demo_store" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "woocommerce_currency", "label": "Currency", "description": "This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.", "type": "select", "default": "GBP", "options": { "AED": "United Arab Emirates dirham (د.إ)", "AFN": "Afghan afghani (؋)", "ALL": "Albanian lek (L)", "AMD": "Armenian dram (AMD)", "ANG": "Netherlands Antillean guilder (ƒ)", "AOA": "Angolan kwanza (Kz)", "ARS": "Argentine peso ($)", "AUD": "Australian dollar ($)", "AWG": "Aruban florin (ƒ)", "AZN": "Azerbaijani manat (AZN)", "BAM": "Bosnia and Herzegovina convertible mark (KM)", "BBD": "Barbadian dollar ($)", "BDT": "Bangladeshi taka (৳ )", "BGN": "Bulgarian lev (лв.)", "BHD": "Bahraini dinar (.د.ب)", "BIF": "Burundian franc (Fr)", "BMD": "Bermudian dollar ($)", "BND": "Brunei dollar ($)", "BOB": "Bolivian boliviano (Bs.)", "BRL": "Brazilian real (R$)", "BSD": "Bahamian dollar ($)", "BTC": "Bitcoin (฿)", "BTN": "Bhutanese ngultrum (Nu.)", "BWP": "Botswana pula (P)", "BYR": "Belarusian ruble (Br)", "BZD": "Belize dollar ($)", "CAD": "Canadian dollar ($)", "CDF": "Congolese franc (Fr)", "CHF": "Swiss franc (CHF)", "CLP": "Chilean peso ($)", "CNY": "Chinese yuan (¥)", "COP": "Colombian peso ($)", "CRC": "Costa Rican colón (₡)", "CUC": "Cuban convertible peso ($)", "CUP": "Cuban peso ($)", "CVE": "Cape Verdean escudo ($)", "CZK": "Czech koruna (Kč)", "DJF": "Djiboutian franc (Fr)", "DKK": "Danish krone (DKK)", "DOP": "Dominican peso (RD$)", "DZD": "Algerian dinar (د.ج)", "EGP": "Egyptian pound (EGP)", "ERN": "Eritrean nakfa (Nfk)", "ETB": "Ethiopian birr (Br)", "EUR": "Euro (€)", "FJD": "Fijian dollar ($)", "FKP": "Falkland Islands pound (£)", "GBP": "Pound sterling (£)", "GEL": "Georgian lari (ლ)", "GGP": "Guernsey pound (£)", "GHS": "Ghana cedi (₵)", "GIP": "Gibraltar pound (£)", "GMD": "Gambian dalasi (D)", "GNF": "Guinean franc (Fr)", "GTQ": "Guatemalan quetzal (Q)", "GYD": "Guyanese dollar ($)", "HKD": "Hong Kong dollar ($)", "HNL": "Honduran lempira (L)", "HRK": "Croatian kuna (Kn)", "HTG": "Haitian gourde (G)", "HUF": "Hungarian forint (Ft)", "IDR": "Indonesian rupiah (Rp)", "ILS": "Israeli new shekel (₪)", "IMP": "Manx pound (£)", "INR": "Indian rupee (₹)", "IQD": "Iraqi dinar (ع.د)", "IRR": "Iranian rial (﷼)", "IRT": "Iranian toman (تومان)", "ISK": "Icelandic króna (kr.)", "JEP": "Jersey pound (£)", "JMD": "Jamaican dollar ($)", "JOD": "Jordanian dinar (د.ا)", "JPY": "Japanese yen (¥)", "KES": "Kenyan shilling (KSh)", "KGS": "Kyrgyzstani som (сом)", "KHR": "Cambodian riel (៛)", "KMF": "Comorian franc (Fr)", "KPW": "North Korean won (₩)", "KRW": "South Korean won (₩)", "KWD": "Kuwaiti dinar (د.ك)", "KYD": "Cayman Islands dollar ($)", "KZT": "Kazakhstani tenge (KZT)", "LAK": "Lao kip (₭)", "LBP": "Lebanese pound (ل.ل)", "LKR": "Sri Lankan rupee (රු)", "LRD": "Liberian dollar ($)", "LSL": "Lesotho loti (L)", "LYD": "Libyan dinar (ل.د)", "MAD": "Moroccan dirham (د.م.)", "MDL": "Moldovan leu (MDL)", "MGA": "Malagasy ariary (Ar)", "MKD": "Macedonian denar (ден)", "MMK": "Burmese kyat (Ks)", "MNT": "Mongolian tögrög (₮)", "MOP": "Macanese pataca (P)", "MRO": "Mauritanian ouguiya (UM)", "MUR": "Mauritian rupee (₨)", "MVR": "Maldivian rufiyaa (.ރ)", "MWK": "Malawian kwacha (MK)", "MXN": "Mexican peso ($)", "MYR": "Malaysian ringgit (RM)", "MZN": "Mozambican metical (MT)", "NAD": "Namibian dollar ($)", "NGN": "Nigerian naira (₦)", "NIO": "Nicaraguan córdoba (C$)", "NOK": "Norwegian krone (kr)", "NPR": "Nepalese rupee (₨)", "NZD": "New Zealand dollar ($)", "OMR": "Omani rial (ر.ع.)", "PAB": "Panamanian balboa (B/.)", "PEN": "Peruvian nuevo sol (S/.)", "PGK": "Papua New Guinean kina (K)", "PHP": "Philippine peso (₱)", "PKR": "Pakistani rupee (₨)", "PLN": "Polish złoty (zł)", "PRB": "Transnistrian ruble (р.)", "PYG": "Paraguayan guaraní (₲)", "QAR": "Qatari riyal (ر.ق)", "RON": "Romanian leu (lei)", "RSD": "Serbian dinar (дин.)", "RUB": "Russian ruble (₽)", "RWF": "Rwandan franc (Fr)", "SAR": "Saudi riyal (ر.س)", "SBD": "Solomon Islands dollar ($)", "SCR": "Seychellois rupee (₨)", "SDG": "Sudanese pound (ج.س.)", "SEK": "Swedish krona (kr)", "SGD": "Singapore dollar ($)", "SHP": "Saint Helena pound (£)", "SLL": "Sierra Leonean leone (Le)", "SOS": "Somali shilling (Sh)", "SRD": "Surinamese dollar ($)", "SSP": "South Sudanese pound (£)", "STD": "São Tomé and Príncipe dobra (Db)", "SYP": "Syrian pound (ل.س)", "SZL": "Swazi lilangeni (L)", "THB": "Thai baht (฿)", "TJS": "Tajikistani somoni (ЅМ)", "TMT": "Turkmenistan manat (m)", "TND": "Tunisian dinar (د.ت)", "TOP": "Tongan paʻanga (T$)", "TRY": "Turkish lira (₺)", "TTD": "Trinidad and Tobago dollar ($)", "TWD": "New Taiwan dollar (NT$)", "TZS": "Tanzanian shilling (Sh)", "UAH": "Ukrainian hryvnia (₴)", "UGX": "Ugandan shilling (UGX)", "USD": "United States dollar ($)", "UYU": "Uruguayan peso ($)", "UZS": "Uzbekistani som (UZS)", "VEF": "Venezuelan bolívar (Bs F)", "VND": "Vietnamese đồng (₫)", "VUV": "Vanuatu vatu (Vt)", "WST": "Samoan tālā (T)", "XAF": "Central African CFA franc (Fr)", "XCD": "East Caribbean dollar ($)", "XOF": "West African CFA franc (Fr)", "XPF": "CFP franc (Fr)", "YER": "Yemeni rial (﷼)", "ZAR": "South African rand (R)", "ZMW": "Zambian kwacha (K)" }, "tip": "This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.", "value": "GBP", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/settings/general/woocommerce_currency" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } } ] } ``` --- ## Settings *Source: apis/rest-api/v2/settings.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Settings The settings API allows you to view all groups of settings available. ## Setting group properties | Attribute | Type | Description | | ------------- | ------ | ---------------------------------------------------------------------------------------------------------- | | `id` | string | A unique identifier that can be used to link settings together. `READ-ONLY` | | `label` | string | A human readable label for the setting used in interfaces. `READ-ONLY` | | `description` | string | A human readable description for the setting used in interfaces. `READ-ONLY` | | `parent_id` | string | ID of parent grouping. `READ-ONLY` | | `sub_groups` | string | IDs for settings sub groups. `READ-ONLY` | ## List all settings groups This API helps you to view all the settings groups. ```http GET /wp-json/wc/v2/settings ``` ```shell curl https://example.com/wp-json/wc/v2/settings \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("settings") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('settings')); ?> ``` ```python print(wcapi.get("settings").json()) ``` ```ruby woocommerce.get("settings").parsed_response ``` ```json [ { "id": "general", "label": "General", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/general" } ] } }, { "id": "products", "label": "Products", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/products" } ] } }, { "id": "tax", "label": "Tax", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/tax" } ] } }, { "id": "shipping", "label": "Shipping", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/shipping" } ] } }, { "id": "checkout", "label": "Checkout", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/checkout" } ] } }, { "id": "account", "label": "Accounts", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/account" } ] } }, { "id": "email", "label": "Emails", "description": "", "parent_id": "", "sub_groups": [ "email_new_order", "email_cancelled_order", "email_failed_order", "email_customer_on_hold_order", "email_customer_processing_order", "email_customer_completed_order", "email_customer_refunded_order", "email_customer_invoice", "email_customer_note", "email_customer_reset_password", "email_customer_new_account" ], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email" } ] } }, { "id": "integration", "label": "Integration", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/integration" } ] } }, { "id": "api", "label": "API", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/api" } ] } }, { "id": "email_new_order", "label": "New order", "description": "New order emails are sent to chosen recipient(s) when a new order is received.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email_new_order" } ] } }, { "id": "email_cancelled_order", "label": "Cancelled order", "description": "Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously processing or on-hold).", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email_cancelled_order" } ] } }, { "id": "email_failed_order", "label": "Failed order", "description": "Failed order emails are sent to chosen recipient(s) when orders have been marked failed (if they were previously processing or on-hold).", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email_failed_order" } ] } }, { "id": "email_customer_on_hold_order", "label": "Order on-hold", "description": "This is an order notification sent to customers containing order details after an order is placed on-hold.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email_customer_on_hold_order" } ] } }, { "id": "email_customer_processing_order", "label": "Processing order", "description": "This is an order notification sent to customers containing order details after payment.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email_customer_processing_order" } ] } }, { "id": "email_customer_completed_order", "label": "Completed order", "description": "Order complete emails are sent to customers when their orders are marked completed and usually indicate that their orders have been shipped.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email_customer_completed_order" } ] } }, { "id": "email_customer_refunded_order", "label": "Refunded order", "description": "Order refunded emails are sent to customers when their orders are marked refunded.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email_customer_refunded_order" } ] } }, { "id": "email_customer_invoice", "label": "Customer invoice", "description": "Customer invoice emails can be sent to customers containing their order information and payment links.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email_customer_invoice" } ] } }, { "id": "email_customer_note", "label": "Customer note", "description": "Customer note emails are sent when you add a note to an order.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email_customer_note" } ] } }, { "id": "email_customer_reset_password", "label": "Reset password", "description": "Customer \"reset password\" emails are sent when customers reset their passwords.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email_customer_reset_password" } ] } }, { "id": "email_customer_new_account", "label": "New account", "description": "Customer \"new account\" emails are sent to the customer when a customer signs up via checkout or account pages.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v2/settings/email_customer_new_account" } ] } } ] ``` --- ## Shipping methods *Source: apis/rest-api/v2/shipping-methods.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Shipping methods The shipping methods API allows you to view individual shipping methods. ## Shipping method properties | Attribute | Type | Description | | ------------- | ------ | ---------------------------------------------------------------------- | | `id` | string | Method ID. `READ-ONLY` | | `title` | string | Shipping method title. `READ-ONLY` | | `description` | string | Shipping method description. `READ-ONLY` | ## Retrieve a shipping method This API lets you retrieve and view a specific shipping method. ```http GET /wp-json/wc/v2/shipping_methods/ ``` ```shell curl https://example.com/wp-json/wc/v2/shipping_methods/flat_rate \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("shipping_methods/flat_rate") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('shipping_methods/flat_rate')); ?> ``` ```python print(wcapi.get("shipping_methods/flat_rate").json()) ``` ```ruby woocommerce.get("shipping_methods/flat_rate").parsed_response ``` ```json { "id": "flat_rate", "title": "Flat rate", "description": "Lets you charge a fixed rate for shipping.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping_methods/flat_rate" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping_methods" } ] } } ``` ## List all shipping methods This API helps you to view all the shipping methods. ```http GET /wp-json/wc/v2/shipping_methods ``` ```shell curl https://example.com/wp-json/wc/v2/shipping_methods \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("shipping_methods") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('shipping_methods')); ?> ``` ```python print(wcapi.get("shipping_methods").json()) ``` ```ruby woocommerce.get("shipping_methods").parsed_response ``` ```json [ { "id": "flat_rate", "title": "Flat rate", "description": "Lets you charge a fixed rate for shipping.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping_methods/flat_rate" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping_methods" } ] } }, { "id": "free_shipping", "title": "Free shipping", "description": "Free shipping is a special method which can be triggered with coupons and minimum spends.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping_methods/free_shipping" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping_methods" } ] } }, { "id": "local_pickup", "title": "Local pickup", "description": "Allow customers to pick up orders themselves. By default, when using local pickup store base taxes will apply regardless of customer address.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping_methods/local_pickup" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping_methods" } ] } } ] ``` --- ## Shipping zone locations *Source: apis/rest-api/v2/shipping-zone-locations.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Shipping zone locations The shipping zone locations API allows you to view and batch update locations of a shipping zone. ## Shipping location properties | Attribute | Type | Description | | --------- | ------ | ----------------------------------------------------------------------------------------------------------- | | `code` | string | Shipping zone location code. | | `type` | string | Shipping zone location type. Options: `postcode`, `state`, `country` and `continent`. Default is `country`. | ## List all locations of a shipping zone This API helps you to view all the locations of a shipping zone. ```http GET /wp-json/wc/v2/shipping/zones//locations ``` ```shell curl https://example.com/wp-json/wc/v2/shipping/zones/5/locations \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("shipping/zones/5/locations") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('shipping/zones/5/locations')); ?> ``` ```python print(wcapi.get("shipping/zones/5/locations").json()) ``` ```ruby woocommerce.get("shipping/zones/5/locations").parsed_response ``` ```json [ { "code": "BR", "type": "country", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ] } } ] ``` ## Update a locations of a shipping zone This API lets you make changes to locations of a shipping zone. ```http PUT /wp-json/wc/v2/shipping/zones//locations ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/shipping/zones/5/locations \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '[ { "code": "BR:SP", "type": "state" }, { "code": "BR:RJ", "type": "state" } ]' ``` ```javascript var data = [ { code: 'BR:SP', type: 'state' }, { code: 'BR:RJ', type: 'state' } ]; WooCommerce.put("shipping/zones/5/locations", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'BR:SP', 'type' => 'state' ], [ 'code' => 'BR:RJ', 'type' => 'state' ] ]; print_r($woocommerce->put('shipping/zones/5/locations', $data)); ?> ``` ```python data = [ { "code": "BR:SP", "type": "state" }, { "code": "BR:RJ", "type": "state" } ] print(wcapi.put("shipping/zones/5/locations", data).json()) ``` ```ruby data = [ { code: "BR:SP", type: "state" }, { code: "BR:RJ", type: "state" } ] woocommerce.put("shipping/zones/5/locations", data).parsed_response ``` ```json [ { "code": "BR:SP", "type": "state", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ] } }, { "code": "BR:RJ", "type": "state", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ] } } ] ``` --- ## Shipping zone methods *Source: apis/rest-api/v2/shipping-zone-methods.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Shipping zone methods The shipping zone methods API allows you to create, view, update, and delete individual methods of a shipping zone. ## Shipping method properties | Attribute | Type | Description | | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------- | | `instance_id` | integer | Shipping method instance ID. `READ-ONLY` | | `title` | string | Shipping method customer facing title. `READ-ONLY` | | `order` | integer | Shipping method sort order. | | `enabled` | boolean | Shipping method enabled status. | | `method_id` | string | Shipping method ID. `READ-ONLY` `MANDATORY` | | `method_title` | string | Shipping method title. `READ-ONLY` | | `method_description` | string | Shipping method description. `READ-ONLY` | | `settings` | object | Shipping method settings. See [Shipping method - Settings properties](#shipping-method---settings-properties) | ### Shipping method - Settings properties | Attribute | Type | Description | | ------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | string | A unique identifier for the setting. `READ-ONLY` | | `label` | string | A human readable label for the setting used in interfaces. `READ-ONLY` | | `description` | string | A human readable description for the setting used in interfaces. `READ-ONLY` | | `type` | string | Type of setting. Options: `text`, `email`, `number`, `color`, `password`, `textarea`, `select`, `multiselect`, `radio`, `image_width` and `checkbox`. `READ-ONLY` | | `value` | string | Setting value. | | `default` | string | Default value for the setting. `READ-ONLY` | | `tip` | string | Additional help text shown to the user about the setting. `READ-ONLY` | | `placeholder` | string | Placeholder text to be displayed in text inputs. `READ-ONLY` | ## Include a shipping method to a shipping zone This API helps you to create a new shipping method to a shipping zone. ```http POST /wp-json/wc/v2/shipping/zones//methods ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/shipping/zones/5/methods \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "method_id": "flat_rate" }' ``` ```javascript const data = { method_id: "flat_rate" }; WooCommerce.post("shipping/zones/5/methods", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'flat_rate' ]; print_r($woocommerce->post('shipping/zones/5/methods', $data)); ?> ``` ```python data = { "method_id": "flat_rate" } print(wcapi.post("shipping/zones/5/methods", data).json()) ``` ```ruby data = { method_id: "flat_rate" } woocommerce.post("shipping/zones/5/methods", data).parsed_response ``` ```json { "instance_id": 26, "title": "Flat rate", "order": 1, "enabled": true, "method_id": "flat_rate", "method_title": "Flat rate", "method_description": "

Lets you charge a fixed rate for shipping.

\n", "settings": { "title": { "id": "title", "label": "Method title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Flat rate", "default": "Flat rate", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "tax_status": { "id": "tax_status", "label": "Tax status", "description": "", "type": "select", "value": "taxable", "default": "taxable", "tip": "", "placeholder": "", "options": { "taxable": "Taxable", "none": "None" } }, "cost": { "id": "cost", "label": "Cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "0", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "" }, "class_costs": { "id": "class_costs", "label": "Shipping class costs", "description": "These costs can optionally be added based on the product shipping class.", "type": "title", "value": "", "default": "", "tip": "These costs can optionally be added based on the product shipping class.", "placeholder": "" }, "class_cost_92": { "id": "class_cost_92", "label": "\"Express\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "class_cost_91": { "id": "class_cost_91", "label": "\"Priority\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "no_class_cost": { "id": "no_class_cost", "label": "No shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "type": { "id": "type", "label": "Calculation type", "description": "", "type": "select", "value": "class", "default": "class", "tip": "", "placeholder": "", "options": { "class": "Per class: Charge shipping for each shipping class individually", "order": "Per order: Charge shipping for the most expensive shipping class" } } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ] } } ```
## Retrieve a shipping method from a shipping zone This API lets you retrieve and view a specific shipping method from a shipping zone by ID. ```http GET /wp-json/wc/v2/shipping/zones//methods/ ``` ```shell curl https://example.com/wp-json/wc/v2/shipping/zones/5/methods/26 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("shipping/zones/5/methods/26") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('shipping/zones/5/methods/26')); ?> ``` ```python print(wcapi.get("shipping/zones/5/methods/26").json()) ``` ```ruby woocommerce.get("shipping/zones/5/methods/26").parsed_response ``` ```json { "instance_id": 26, "title": "Flat rate", "order": 1, "enabled": true, "method_id": "flat_rate", "method_title": "Flat rate", "method_description": "

Lets you charge a fixed rate for shipping.

\n", "settings": { "title": { "id": "title", "label": "Method title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Flat rate", "default": "Flat rate", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "tax_status": { "id": "tax_status", "label": "Tax status", "description": "", "type": "select", "value": "taxable", "default": "taxable", "tip": "", "placeholder": "", "options": { "taxable": "Taxable", "none": "None" } }, "cost": { "id": "cost", "label": "Cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "0", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "" }, "class_costs": { "id": "class_costs", "label": "Shipping class costs", "description": "These costs can optionally be added based on the product shipping class.", "type": "title", "value": "", "default": "", "tip": "These costs can optionally be added based on the product shipping class.", "placeholder": "" }, "class_cost_92": { "id": "class_cost_92", "label": "\"Express\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "class_cost_91": { "id": "class_cost_91", "label": "\"Priority\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "no_class_cost": { "id": "no_class_cost", "label": "No shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "type": { "id": "type", "label": "Calculation type", "description": "", "type": "select", "value": "class", "default": "class", "tip": "", "placeholder": "", "options": { "class": "Per class: Charge shipping for each shipping class individually", "order": "Per order: Charge shipping for the most expensive shipping class" } } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ] } } ```
## List all shipping methods from a shipping zone This API helps you to view all the shipping methods from a shipping zone. ```http GET /wp-json/wc/v2/shipping/zones//methods ``` ```shell curl https://example.com/wp-json/wc/v2/shipping/zones/5/methods \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("shipping/zones/5/methods") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('shipping/zones/5/methods')); ?> ``` ```python print(wcapi.get("shipping/zones/5/methods").json()) ``` ```ruby woocommerce.get("shipping/zones/5/methods").parsed_response ``` ```json [ { "instance_id": 26, "title": "Flat rate", "order": 1, "enabled": true, "method_id": "flat_rate", "method_title": "Flat rate", "method_description": "

Lets you charge a fixed rate for shipping.

\n", "settings": { "title": { "id": "title", "label": "Method title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Flat rate", "default": "Flat rate", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "tax_status": { "id": "tax_status", "label": "Tax status", "description": "", "type": "select", "value": "taxable", "default": "taxable", "tip": "", "placeholder": "", "options": { "taxable": "Taxable", "none": "None" } }, "cost": { "id": "cost", "label": "Cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "0", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "" }, "class_costs": { "id": "class_costs", "label": "Shipping class costs", "description": "These costs can optionally be added based on the product shipping class.", "type": "title", "value": "", "default": "", "tip": "These costs can optionally be added based on the product shipping class.", "placeholder": "" }, "class_cost_92": { "id": "class_cost_92", "label": "\"Express\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "class_cost_91": { "id": "class_cost_91", "label": "\"Priority\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "no_class_cost": { "id": "no_class_cost", "label": "No shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "type": { "id": "type", "label": "Calculation type", "description": "", "type": "select", "value": "class", "default": "class", "tip": "", "placeholder": "", "options": { "class": "Per class: Charge shipping for each shipping class individually", "order": "Per order: Charge shipping for the most expensive shipping class" } } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ] } }, { "instance_id": 27, "title": "Free shipping", "order": 2, "enabled": true, "method_id": "free_shipping", "method_title": "Free shipping", "method_description": "

Free shipping is a special method which can be triggered with coupons and minimum spends.

\n", "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Free shipping", "default": "Free shipping", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "requires": { "id": "requires", "label": "Free shipping requires...", "description": "", "type": "select", "value": "", "default": "", "tip": "", "placeholder": "", "options": { "": "N/A", "coupon": "A valid free shipping coupon", "min_amount": "A minimum order amount", "either": "A minimum order amount OR a coupon", "both": "A minimum order amount AND a coupon" } }, "min_amount": { "id": "min_amount", "label": "Minimum order amount", "description": "Users will need to spend this amount to get free shipping (if enabled above).", "type": "price", "value": "0", "default": "", "tip": "Users will need to spend this amount to get free shipping (if enabled above).", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods/27" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ] } } ] ```
## Update a shipping method of a shipping zone This API lets you make changes to a shipping method of a shipping zone. ```http PUT /wp-json/wc/v2/shipping/zones//methods/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/shipping/zones/5/methods/26 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "settings": { "cost": "20.00" } }' ``` ```javascript const data = { settings: { cost: "20.00" } }; WooCommerce.put("shipping/zones/5/methods/26", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ 'cost' => '20.00' ] ]; print_r($woocommerce->put('shipping/zones/5/methods/26', $data)); ?> ``` ```python data = { "regular_price": { "cost": "20.00" } } print(wcapi.put("shipping/zones/5/methods/26", data).json()) ``` ```ruby data = { regular_price: { "cost": "20.00" } } woocommerce.put("shipping/zones/5/methods/26", data).parsed_response ``` ```json { "instance_id": 26, "title": "Flat rate", "order": 1, "enabled": true, "method_id": "flat_rate", "method_title": "Flat rate", "method_description": "

Lets you charge a fixed rate for shipping.

\n", "settings": { "title": { "id": "title", "label": "Method title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Flat rate", "default": "Flat rate", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "tax_status": { "id": "tax_status", "label": "Tax status", "description": "", "type": "select", "value": "taxable", "default": "taxable", "tip": "", "placeholder": "", "options": { "taxable": "Taxable", "none": "None" } }, "cost": { "id": "cost", "label": "Cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "20.00", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "" }, "class_costs": { "id": "class_costs", "label": "Shipping class costs", "description": "These costs can optionally be added based on the product shipping class.", "type": "title", "value": "", "default": "", "tip": "These costs can optionally be added based on the product shipping class.", "placeholder": "" }, "class_cost_92": { "id": "class_cost_92", "label": "\"Express\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "class_cost_91": { "id": "class_cost_91", "label": "\"Priority\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "no_class_cost": { "id": "no_class_cost", "label": "No shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "type": { "id": "type", "label": "Calculation type", "description": "", "type": "select", "value": "class", "default": "class", "tip": "", "placeholder": "", "options": { "class": "Per class: Charge shipping for each shipping class individually", "order": "Per order: Charge shipping for the most expensive shipping class" } } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ] } } ```
## Delete a shipping method from a shipping zone This API helps you delete a shipping method from a shipping zone. ```http DELETE /wp-json/wc/v2/shipping/zones//methods/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/shipping/zones/5/methods/26?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("shipping/zones/5/methods/26", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('shipping/zones/5/methods/26', ['force' => true])); ?> ``` ```python print(wcapi.delete("shipping/zones/5/methods/26", params={"force": True}).json()) ``` ```ruby woocommerce.delete("shipping/zones/5/methods/26", force: true).parsed_response ``` ```json { "instance_id": 26, "title": "Flat rate", "order": 1, "enabled": true, "method_id": "flat_rate", "method_title": "Flat rate", "method_description": "

Lets you charge a fixed rate for shipping.

\n", "settings": { "title": { "id": "title", "label": "Method title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Flat rate", "default": "Flat rate", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "tax_status": { "id": "tax_status", "label": "Tax status", "description": "", "type": "select", "value": "taxable", "default": "taxable", "tip": "", "placeholder": "", "options": { "taxable": "Taxable", "none": "None" } }, "cost": { "id": "cost", "label": "Cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "20.00", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "" }, "class_costs": { "id": "class_costs", "label": "Shipping class costs", "description": "These costs can optionally be added based on the product shipping class.", "type": "title", "value": "", "default": "", "tip": "These costs can optionally be added based on the product shipping class.", "placeholder": "" }, "class_cost_92": { "id": "class_cost_92", "label": "\"Express\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "class_cost_91": { "id": "class_cost_91", "label": "\"Priority\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "no_class_cost": { "id": "no_class_cost", "label": "No shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "type": { "id": "type", "label": "Calculation type", "description": "", "type": "select", "value": "class", "default": "class", "tip": "", "placeholder": "", "options": { "class": "Per class: Charge shipping for each shipping class individually", "order": "Per order: Charge shipping for the most expensive shipping class" } } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ] } } ```
#### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | --- ## Shipping zones *Source: apis/rest-api/v2/shipping-zones.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Shipping zones The shipping zones API allows you to create, view, update, and delete individual shipping zones. ## Shipping zone properties | Attribute | Type | Description | | --------- | ------- | ----------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Shipping zone name. `MANDATORY` | | `order` | integer | Shipping zone order. | ## Create a shipping zone This API helps you to create a new shipping zone. ```http POST /wp-json/wc/v2/shipping/zones ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/shipping/zones \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Brazil" }' ``` ```javascript const data = { name: "Brazil" }; WooCommerce.post("shipping/zones", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Brazil' ]; print_r($woocommerce->post('shipping/zones', $data)); ?> ``` ```python data = { "name": "Brazil" } print(wcapi.post("shipping/zones", data).json()) ``` ```ruby data = { name: "Brazil" } woocommerce.post("shipping/zones", data).parsed_response ``` ```json { "id": 5, "name": "Brazil", "order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations" } ] } } ``` ## Retrieve a shipping zone This API lets you retrieve and view a specific shipping zone by ID. ```http GET /wp-json/wc/v2/shipping/zones/ ``` ```shell curl https://example.com/wp-json/wc/v2/shipping/zones/5 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("shipping/zones/5") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('shipping/zones/5')); ?> ``` ```python print(wcapi.get("shipping/zones/5").json()) ``` ```ruby woocommerce.get("shipping/zones/5").parsed_response ``` ```json { "id": 5, "name": "Brazil", "order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations" } ] } } ``` ## List all shipping zones This API helps you to view all the shipping zones. ```http GET /wp-json/wc/v2/shipping/zones ``` ```shell curl https://example.com/wp-json/wc/v2/shipping/zones \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("shipping/zones") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('shipping/zones')); ?> ``` ```python print(wcapi.get("shipping/zones").json()) ``` ```ruby woocommerce.get("shipping/zones").parsed_response ``` ```json [ { "id": 0, "name": "Rest of the World", "order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/0" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/0/locations" } ] } }, { "id": 5, "name": "Brazil", "order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations" } ] } } ] ``` ## Update a shipping zone This API lets you make changes to a shipping zone. ```http PUT /wp-json/wc/v2/shipping/zones/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/shipping/zones/5 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "order": 1 }' ``` ```javascript const data = { order: 1 }; WooCommerce.put("shipping/zones/5", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 1 ]; print_r($woocommerce->put('shipping/zones/5', $data)); ?> ``` ```python data = { "order": 1 } print(wcapi.put("shipping/zones/5", data).json()) ``` ```ruby data = { order: 1 } woocommerce.put("shipping/zones/5", data).parsed_response ``` ```json { "id": 5, "name": "Brazil", "order": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations" } ] } } ``` ## Delete a shipping zone This API helps you delete a shipping zone. ```http DELETE /wp-json/wc/v2/shipping/zones/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/shipping/zones/5?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("shipping/zones/5", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('shipping/zones/5', ['force' => true])); ?> ``` ```python print(wcapi.delete("shipping/zones/5", params={"force": True}).json()) ``` ```ruby woocommerce.delete("shipping/zones/5", force: true).parsed_response ``` ```json { "id": 5, "name": "Brazil", "order": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v2/shipping/zones/5/locations" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | --- ## System status tools *Source: apis/rest-api/v2/system-status-tools.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # System status tools The system status tools API allows you to view and run tools from system status. ## System status tool properties | Attribute | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------- | | `id` | string | A unique identifier for the tool. `READ-ONLY` | | `name` | string | Tool name. `READ-ONLY` | | `action` | string | What running the tool will do. `READ-ONLY` | | `description` | string | Tool description. `READ-ONLY` | | `success` | boolean | Did the tool run successfully? `READ-ONLY` `WRITE-ONLY` | | `message` | string | Tool return message. `READ-ONLY` `WRITE-ONLY` | | `confirm` | boolean | Confirm execution of the tool. Default is `false`. `WRITE-ONLY` | ## Retrieve a tool from system status This API lets you retrieve and view a specific tool from system status by ID. ```http GET /wp-json/wc/v2/system_status/tools/ ``` ```shell curl https://example.com/wp-json/wc/v2/system_status/tools/clear_transients \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("system_status/tools/clear_transients") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('system_status/tools/clear_transients')); ?> ``` ```python print(wcapi.get("system_status/tools/clear_transients").json()) ``` ```ruby woocommerce.get("system_status/tools/clear_transients").parsed_response ``` ```json { "id": "clear_transients", "name": "WC transients", "action": "Clear transients", "description": "This tool will clear the product/shop transients cache.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/clear_transients" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } } ``` ## List all tools from system status This API helps you to view all tools from system status. ```http GET /wp-json/wc/v2/system_status/tools ``` ```shell curl https://example.com/wp-json/wc/v2/system_status/tools \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("system_status/tools") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('system_status/tools')); ?> ``` ```python print(wcapi.get("system_status/tools").json()) ``` ```ruby woocommerce.get("system_status/tools").parsed_response ``` ```json [ { "id": "clear_transients", "name": "WC transients", "action": "Clear transients", "description": "This tool will clear the product/shop transients cache.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/clear_transients" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "clear_expired_transients", "name": "Expired transients", "action": "Clear expired transients", "description": "This tool will clear ALL expired transients from WordPress.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/clear_expired_transients" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "delete_orphaned_variations", "name": "Orphaned variations", "action": "Delete orphaned variations", "description": "This tool will delete all variations which have no parent.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/delete_orphaned_variations" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "clear_expired_download_permissions", "name": "Used-up download permissions", "action": "Clean up download permissions", "description": "This tool will delete expired download permissions and permissions with 0 remaining downloads.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/clear_expired_download_permissions" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "regenerate_product_lookup_tables", "name": "Product lookup tables", "action": "Regenerate", "description": "This tool will regenerate product lookup table data. This process may take a while.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/regenerate_product_lookup_tables" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "repair_coupons_lookup_table", "name": "Coupons lookup table", "action": "Repair", "description": "This tool will repair the coupons lookup table data with missing discount amounts. This process may take a while.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/repair_coupons_lookup_table" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "recount_terms", "name": "Term counts", "action": "Recount terms", "description": "This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/recount_terms" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "reset_roles", "name": "Capabilities", "action": "Reset capabilities", "description": "This tool will reset the admin, customer and shop_manager roles to default. Use this if your users cannot access all of the WooCommerce admin pages.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/reset_roles" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "clear_sessions", "name": "Customer sessions", "action": "Clear all sessions", "description": "Note: This tool will delete all customer session data from the database, including any current live carts.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/clear_sessions" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "clear_template_cache", "name": "Clear template cache", "action": "Clear", "description": "Note: This tool will empty the template cache.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/clear_template_cache" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "clear_system_status_theme_info_cache", "name": "Clear system status theme info cache", "action": "Clear", "description": "Note: This tool will empty the system status theme info cache.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/clear_system_status_theme_info_cache" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "install_pages", "name": "Install WooCommerce pages", "action": "Install pages", "description": "Note: This tool will install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/install_pages" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "delete_taxes", "name": "Delete all WooCommerce tax rates", "action": "Delete ALL tax rates", "description": "Note: This option will delete ALL of your tax rates, use with caution.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/delete_taxes" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "regenerate_thumbnails", "name": "Regenerate shop thumbnails", "action": "Regenerate", "description": "This will regenerate all shop thumbnails to match your theme and/or image settings.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/regenerate_thumbnails" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "db_update_routine", "name": "Update database", "action": "Update database", "description": "Note: This tool will update your WooCommerce database to the latest version. Please ensure you make sufficient backups before proceeding.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/db_update_routine" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "recreate_order_address_fts_index", "name": "Re-create Order Address FTS index", "action": "Recreate index", "description": "This tool will recreate the full text search index for order addresses. If the index does not exist, it will try to create it.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/recreate_order_address_fts_index" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } }, { "id": "verify_db_tables", "name": "Verify base database tables", "action": "Verify database", "description": "Verify if all base database tables are present.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/verify_db_tables" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } } ] ``` ## Run a tool from system status This API lets you run a tool from system status. ```http PUT /wp-json/wc/v2/system_status/tools/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/system_status/tools/clear_transients \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "confirm": true }' ``` ```javascript const data = { confirm: true }; WooCommerce.put("system_status/tools/clear_transients", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php true ]; print_r($woocommerce->put('system_status/tools/clear_transients', $data)); ?> ``` ```python data = { "confirm": True } print(wcapi.put("system_status/tools/clear_transients", data).json()) ``` ```ruby data = { confirm: true } woocommerce.put("system_status/tools/clear_transients", data).parsed_response ``` ```json { "id": "clear_transients", "name": "WC transients", "action": "Clear transients", "description": "This tool will clear the product/shop transients cache.", "success": true, "message": "Product transients cleared", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools/clear_transients" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/system_status/tools" } ] } } ``` --- ## System status *Source: apis/rest-api/v2/system-status.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # System status The system status API allows you to view all system status items. ## System status properties | Attribute | Type | Description | | ---------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------ | | `environment` | object | Environment. See [System status - Environment properties](#system-status---environment-properties) `READ-ONLY` | | `database` | object | Database. See [System status - Database properties](#system-status---database-properties) `READ-ONLY` | | `active_plugins` | array | Active plugins. `READ-ONLY` | | `theme` | object | Theme. See [System status - Theme properties](#system-status---theme-properties) `READ-ONLY` | | `settings` | object | Settings. See [System status - Settings properties](#system-status---settings-properties) `READ-ONLY` | | `security` | object | Security. See [System status - Security properties](#system-status---security-properties) `READ-ONLY` | | `pages` | array | WooCommerce pages. `READ-ONLY` | ### System status - Environment properties | Attribute | Type | Description | | --------------------------- | ------- | -------------------------------------------------------------------------- | | `home_url` | string | Home URL. `READ-ONLY` | | `site_url` | string | Site URL. `READ-ONLY` | | `wc_version` | string | WooCommerce version. `READ-ONLY` | | `log_directory` | string | Log directory. `READ-ONLY` | | `log_directory_writable` | boolean | Is log directory writable? `READ-ONLY` | | `wp_version` | string | WordPress version. `READ-ONLY` | | `wp_multisite` | boolean | Is WordPress multisite? `READ-ONLY` | | `wp_memory_limit` | integer | WordPress memory limit. `READ-ONLY` | | `wp_debug_mode` | boolean | Is WordPress debug mode active? `READ-ONLY` | | `wp_cron` | boolean | Are WordPress cron jobs enabled? `READ-ONLY` | | `wp_environment_type` | string | WordPress environment type. `READ-ONLY` | | `language` | string | WordPress language. `READ-ONLY` | | `server_info` | string | Server info. `READ-ONLY` | | `php_version` | string | PHP version. `READ-ONLY` | | `php_post_max_size` | integer | PHP post max size. `READ-ONLY` | | `php_max_execution_time` | integer | PHP max execution time. `READ-ONLY` | | `php_max_input_vars` | integer | PHP max input vars. `READ-ONLY` | | `curl_version` | string | cURL version. `READ-ONLY` | | `suhosin_installed` | boolean | Is SUHOSIN installed? `READ-ONLY` | | `max_upload_size` | integer | Max upload size. `READ-ONLY` | | `mysql_version` | string | MySQL version. `READ-ONLY` | | `default_timezone` | string | Default timezone. `READ-ONLY` | | `fsockopen_or_curl_enabled` | boolean | Is fsockopen/cURL enabled? `READ-ONLY` | | `soapclient_enabled` | boolean | Is SoapClient class enabled? `READ-ONLY` | | `domdocument_enabled` | boolean | Is DomDocument class enabled? `READ-ONLY` | | `gzip_enabled` | boolean | Is GZip enabled? `READ-ONLY` | | `mbstring_enabled` | boolean | Is mbstring enabled? `READ-ONLY` | | `remote_post_successful` | boolean | Remote POST successful? `READ-ONLY` | | `remote_post_response` | string | Remote POST response. `READ-ONLY` | | `remote_get_successful` | boolean | Remote GET successful? `READ-ONLY` | | `remote_get_response` | string | Remote GET response. `READ-ONLY` | ### System status - Database properties | Attribute | Type | Description | | ------------------------ | ------ | ----------------------------------------------------------------- | | `wc_database_version` | string | WC database version. `READ-ONLY` | | `database_prefix` | string | Database prefix. `READ-ONLY` | | `maxmind_geoip_database` | string | MaxMind GeoIP database. `READ-ONLY` | | `database_tables` | array | Database tables. `READ-ONLY` | ### System status - Theme properties | Attribute | Type | Description | | ------------------------- | ------- | ------------------------------------------------------------------------------------- | | `name` | string | Theme name. `READ-ONLY` | | `version` | string | Theme version. `READ-ONLY` | | `version_latest` | string | Latest version of theme. `READ-ONLY` | | `author_url` | string | Theme author URL. `READ-ONLY` | | `is_child_theme` | boolean | Is this theme a child theme? `READ-ONLY` | | `has_woocommerce_support` | boolean | Does the theme declare WooCommerce support? `READ-ONLY` | | `has_woocommerce_file` | boolean | Does the theme have a woocommerce.php file? `READ-ONLY` | | `has_outdated_templates` | boolean | Does this theme have outdated templates? `READ-ONLY` | | `overrides` | array | Template overrides. `READ-ONLY` | | `parent_name` | string | Parent theme name. `READ-ONLY` | | `parent_version` | string | Parent theme version. `READ-ONLY` | | `parent_author_url` | string | Parent theme author URL. `READ-ONLY` | ### System status - Settings properties | Attribute | Type | Description | | --------------------- | ------- | ------------------------------------------------------------------------------------ | | `api_enabled` | boolean | REST API enabled? `READ-ONLY` | | `force_ssl` | boolean | SSL forced? `READ-ONLY` | | `currency` | string | Currency. `READ-ONLY` | | `currency_symbol` | string | Currency symbol. `READ-ONLY` | | `currency_position` | string | Currency position. `READ-ONLY` | | `thousand_separator` | string | Thousand separator. `READ-ONLY` | | `decimal_separator` | string | Decimal separator. `READ-ONLY` | | `number_of_decimals` | integer | Number of decimals. `READ-ONLY` | | `geolocation_enabled` | boolean | Geolocation enabled? `READ-ONLY` | | `taxonomies` | array | Taxonomy terms for product/order statuses. `READ-ONLY` | ### System status - Security properties | Attribute | Type | Description | | ------------------- | ------- | --------------------------------------------------------------------------------- | | `secure_connection` | boolean | Is the connection to your store secure? `READ-ONLY` | | `hide_errors` | boolean | Hide errors from visitors? `READ-ONLY` | ## List all system status items This API helps you to view all the system status items. ```http GET /wp-json/wc/v2/system_status ``` ```shell curl https://example.com/wp-json/wc/v2/system_status \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("system_status") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('system_status')); ?> ``` ```python print(wcapi.get("system_status").json()) ``` ```ruby woocommerce.get("system_status").parsed_response ``` ```json { "environment": { "home_url": "http://example.com", "site_url": "http://example.com", "version": "3.0.0", "log_directory": "/var/www/woocommerce/wp-content/uploads/wc-logs/", "log_directory_writable": true, "wp_version": "4.7.3", "wp_multisite": false, "wp_memory_limit": 134217728, "wp_debug_mode": true, "wp_cron": true, "wp_environment_type": "production", "language": "en_US", "server_info": "Apache/2.4.18 (Ubuntu)", "php_version": "7.1.3-2+deb.sury.org~yakkety+1", "php_post_max_size": 8388608, "php_max_execution_time": 30, "php_max_input_vars": 1000, "curl_version": "7.50.1, OpenSSL/1.0.2g", "suhosin_installed": false, "max_upload_size": 2097152, "mysql_version": "5.7.17", "default_timezone": "UTC", "fsockopen_or_curl_enabled": true, "soapclient_enabled": true, "domdocument_enabled": true, "gzip_enabled": true, "mbstring_enabled": true, "remote_post_successful": true, "remote_post_response": "200", "remote_get_successful": true, "remote_get_response": "200" }, "database": { "wc_database_version": "3.0.0", "database_prefix": "wp_", "maxmind_geoip_database": "/var/www/woocommerce/wp-content/uploads/GeoIP.dat", "database_tables": { "woocommerce_sessions": true, "woocommerce_api_keys": true, "woocommerce_attribute_taxonomies": true, "woocommerce_downloadable_product_permissions": true, "woocommerce_order_items": true, "woocommerce_order_itemmeta": true, "woocommerce_tax_rates": true, "woocommerce_tax_rate_locations": true, "woocommerce_shipping_zones": true, "woocommerce_shipping_zone_locations": true, "woocommerce_shipping_zone_methods": true, "woocommerce_payment_tokens": true, "woocommerce_payment_tokenmeta": true } }, "active_plugins": [ { "plugin": "woocommerce/woocommerce.php", "name": "WooCommerce", "version": "3.0.0-rc.1", "version_latest": "2.6.14", "url": "https://woocommerce.com/", "author_name": "Automattic", "author_url": "https://woocommerce.com", "network_activated": false } ], "theme": { "name": "Twenty Sixteen", "version": "1.3", "version_latest": "1.3", "author_url": "https://wordpress.org/", "is_child_theme": false, "has_woocommerce_support": true, "has_woocommerce_file": false, "has_outdated_templates": false, "overrides": [], "parent_name": "", "parent_version": "", "parent_version_latest": "", "parent_author_url": "" }, "settings": { "api_enabled": true, "force_ssl": false, "currency": "USD", "currency_symbol": "$", "currency_position": "left", "thousand_separator": ",", "decimal_separator": ".", "number_of_decimals": 2, "geolocation_enabled": false, "taxonomies": { "external": "external", "grouped": "grouped", "simple": "simple", "variable": "variable" } }, "security": { "secure_connection": true, "hide_errors": true }, "pages": [ { "page_name": "Shop base", "page_id": "4", "page_set": true, "page_exists": true, "page_visible": true, "shortcode": "", "shortcode_required": false, "shortcode_present": false }, { "page_name": "Cart", "page_id": "5", "page_set": true, "page_exists": true, "page_visible": true, "shortcode": "[woocommerce_cart]", "shortcode_required": true, "shortcode_present": true }, { "page_name": "Checkout", "page_id": "6", "page_set": true, "page_exists": true, "page_visible": true, "shortcode": "[woocommerce_checkout]", "shortcode_required": true, "shortcode_present": true }, { "page_name": "My account", "page_id": "7", "page_set": true, "page_exists": true, "page_visible": true, "shortcode": "[woocommerce_my_account]", "shortcode_required": true, "shortcode_present": true } ] } ``` --- ## Tax classes *Source: apis/rest-api/v2/tax-classes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Tax classes The tax classes API allows you to create, view, and delete individual tax classes. ## Tax class properties | Attribute | Type | Description | |-----------|--------|-------------------------------------------------------------------------------| | `slug` | string | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Tax class name. `REQUIRED` | ## Create a tax class This API helps you to create a new tax class. ```http POST /wp-json/wc/v2/taxes/classes ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/taxes/classes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Zero Rate" }' ``` ```javascript const data = { name: "Zero Rate" }; WooCommerce.post("taxes/classes", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Zero Rate' ]; print_r($woocommerce->post('taxes/classes', $data)); ?> ``` ```python data = { "name": "Zero Rate" } print(wcapi.post("taxes/classes", data).json()) ``` ```ruby data = { name: "Zero Rate" } woocommerce.post("taxes/classes", data).parsed_response ``` ```json { "slug": "zero-rate", "name": "Zero Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes/classes" } ] } } ``` ## List all tax classes This API helps you to view all tax classes. ```http GET /wp-json/wc/v2/taxes/classes ``` ```shell curl https://example.com/wp-json/wc/v2/taxes/classes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("taxes/classes") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('taxes/classes')); ?> ``` ```python print(wcapi.get("taxes/classes").json()) ``` ```ruby woocommerce.get("taxes/classes").parsed_response ``` ```json [ { "slug": "standard", "name": "Standard Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes/classes" } ] } }, { "slug": "reduced-rate", "name": "Reduced Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes/classes" } ] } }, { "slug": "zero-rate", "name": "Zero Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes/classes" } ] } } ] ``` ## Delete a tax class This API helps you delete a tax class. :::warning This also will delete all tax rates from the selected class. ::: ```http DELETE /wp-json/wc/v2/taxes/classes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/taxes/classes/zero-rate?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("taxes/classes/zero-rate", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('taxes/classes/zero-rate', ['force' => true])); ?> ``` ```python print(wcapi.delete("taxes/classes/zero-rate", params={"force": True}).json()) ``` ```ruby woocommerce.delete("taxes/classes/zero-rate", force: true).parsed_response ``` ```json { "slug": "zero-rate", "name": "Zero Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes/classes" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, since this resource does not support trashing. | --- ## Tax rates *Source: apis/rest-api/v2/taxes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Tax rates The taxes API allows you to create, view, update, and delete individual tax rates, or a batch of tax rates. ## Tax rate properties | Attribute | Type | Description | |------------|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `country` | string | Country ISO 3166 code. See [ISO 3166 Codes (Countries)](http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html) for more details | | `state` | string | State code. | | `postcode` | string | Postcode/ZIP. | | `city` | string | City name. | | `rate` | string | Tax rate. | | `name` | string | Tax rate name. | | `priority` | integer | Tax priority. Only 1 matching rate per priority will be used. To define multiple tax rates for a single area you need to specify a different priority per rate. Default is `1`. | | `compound` | boolean | Whether or not this is a compound rate. Compound tax rates are applied on top of other tax rates. Default is `false`. | | `shipping` | boolean | Whether or not this tax rate also gets applied to shipping. Default is `true`. | | `order` | integer | Indicates the order that will appear in queries. | | `class` | string | Tax class. Default is `standard`. | ## Create a tax rate This API helps you to create a new tax rate. ```http POST /wp-json/wc/v2/taxes ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/taxes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "country": "US", "state": "AL", "rate": "4", "name": "State Tax", "shipping": false }' ``` ```javascript const data = { country: "US", state: "AL", rate: "4", name: "State Tax", shipping: false }; WooCommerce.post("taxes", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'US', 'state' => 'AL', 'rate' => '4', 'name' => 'State Tax', 'shipping' => false ]; print_r($woocommerce->post('taxes', $data)); ?> ``` ```python data = { "country": "US", "state": "AL", "rate": "4", "name": "State Tax", "shipping": False } print(wcapi.post("taxes", data).json()) ``` ```ruby data = { country: "US", state: "AL", rate: "4", name: "State Tax", shipping: false } woocommerce.post("taxes", data).parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } } ``` ## Retrieve a tax rate This API lets you retrieve and view a specific tax rate by ID. ```http GET /wp-json/wc/v2/taxes/ ``` ```shell curl https://example.com/wp-json/wc/v2/taxes/72 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("taxes/72") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('taxes/72')); ?> ``` ```python print(wcapi.get("taxes/72").json()) ``` ```ruby woocommerce.get("taxes/72").parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } } ``` ## List all tax rates This API helps you to view all the tax rates. ```http GET /wp-json/wc/v2/taxes ``` ```shell curl https://example.com/wp-json/wc/v2/taxes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("taxes") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('taxes')); ?> ``` ```python print(wcapi.get("taxes").json()) ``` ```ruby woocommerce.get("taxes").parsed_response ``` ```json [ { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 73, "country": "US", "state": "AZ", "postcode": "", "city": "", "rate": "5.6000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 2, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/73" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 74, "country": "US", "state": "AR", "postcode": "", "city": "", "rate": "6.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 3, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/74" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 75, "country": "US", "state": "CA", "postcode": "", "city": "", "rate": "7.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 4, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/75" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 76, "country": "US", "state": "CO", "postcode": "", "city": "", "rate": "2.9000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 5, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/76" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 77, "country": "US", "state": "CT", "postcode": "", "city": "", "rate": "6.3500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 6, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/77" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 78, "country": "US", "state": "DC", "postcode": "", "city": "", "rate": "5.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 7, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/78" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 79, "country": "US", "state": "FL", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 8, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/79" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 80, "country": "US", "state": "GA", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 9, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/80" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 81, "country": "US", "state": "GU", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 10, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/81" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | |------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------| | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `name`. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. | | `class` | string | Sort by tax class. | ## Update a tax rate This API lets you make changes to a tax rate. ```http PUT /wp-json/wc/v2/taxes/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/taxes/72 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "US Tax" }' ``` ```javascript const data = { name: "US Tax" }; WooCommerce.put("taxes/72", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'US Tax' ]; print_r($woocommerce->put('taxes/72', $data)); ?> ``` ```python data = { "name": "US Tax" } print(wcapi.put("taxes/72", data).json()) ``` ```ruby data = { name: "US Tax" } woocommerce.put("taxes/72", data).parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "US Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } } ``` ## Delete a tax rate This API helps you delete a tax rate. ```http DELETE /wp-json/wc/v2/taxes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/taxes/72?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("taxes/72", { force: true }) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('taxes/72', ['force' => true])); ?> ``` ```python print(wcapi.delete("taxes/72", params={"force": True}).json()) ``` ```ruby woocommerce.delete("taxes/72", force: true).parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "US Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|---------------------------------------------------------------| | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update tax rates This API helps you to batch create, update and delete multiple tax rates. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/taxes/batch ``` > Example batch creating all US taxes: ```shell curl -X POST https://example.com/wp-json/wc/v2/taxes/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "country": "US", "state": "AL", "rate": "4.0000", "name": "State Tax", "shipping": false, "order": 1 }, { "country": "US", "state": "AZ", "rate": "5.6000", "name": "State Tax", "shipping": false, "order": 2 }, { "country": "US", "state": "AR", "rate": "6.5000", "name": "State Tax", "shipping": true, "order": 3 }, { "country": "US", "state": "CA", "rate": "7.5000", "name": "State Tax", "shipping": false, "order": 4 }, { "country": "US", "state": "CO", "rate": "2.9000", "name": "State Tax", "shipping": false, "order": 5 }, { "country": "US", "state": "CT", "rate": "6.3500", "name": "State Tax", "shipping": true, "order": 6 }, { "country": "US", "state": "DC", "rate": "5.7500", "name": "State Tax", "shipping": true, "order": 7 }, { "country": "US", "state": "FL", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 8 }, { "country": "US", "state": "GA", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 9 }, { "country": "US", "state": "GU", "rate": "4.0000", "name": "State Tax", "shipping": false, "order": 10 }, { "country": "US", "state": "HI", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 11 }, { "country": "US", "state": "ID", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 12 }, { "country": "US", "state": "IL", "rate": "6.2500", "name": "State Tax", "shipping": false, "order": 13 }, { "country": "US", "state": "IN", "rate": "7.0000", "name": "State Tax", "shipping": false, "order": 14 }, { "country": "US", "state": "IA", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 15 }, { "country": "US", "state": "KS", "rate": "6.1500", "name": "State Tax", "shipping": true, "order": 16 }, { "country": "US", "state": "KY", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 17 }, { "country": "US", "state": "LA", "rate": "4.0000", "name": "State Tax", "shipping": false, "order": 18 }, { "country": "US", "state": "ME", "rate": "5.5000", "name": "State Tax", "shipping": false, "order": 19 }, { "country": "US", "state": "MD", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 20 }, { "country": "US", "state": "MA", "rate": "6.2500", "name": "State Tax", "shipping": false, "order": 21 }, { "country": "US", "state": "MI", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 22 }, { "country": "US", "state": "MN", "rate": "6.8750", "name": "State Tax", "shipping": true, "order": 23 }, { "country": "US", "state": "MS", "rate": "7.0000", "name": "State Tax", "shipping": true, "order": 24 }, { "country": "US", "state": "MO", "rate": "4.2250", "name": "State Tax", "shipping": false, "order": 25 }, { "country": "US", "state": "NE", "rate": "5.5000", "name": "State Tax", "shipping": true, "order": 26 }, { "country": "US", "state": "NV", "rate": "6.8500", "name": "State Tax", "shipping": false, "order": 27 }, { "country": "US", "state": "NJ", "rate": "7.0000", "name": "State Tax", "shipping": true, "order": 28 }, { "country": "US", "state": "NM", "rate": "5.1250", "name": "State Tax", "shipping": true, "order": 29 }, { "country": "US", "state": "NY", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 30 }, { "country": "US", "state": "NC", "rate": "4.7500", "name": "State Tax", "shipping": true, "order": 31 }, { "country": "US", "state": "ND", "rate": "5.0000", "name": "State Tax", "shipping": true, "order": 32 }, { "country": "US", "state": "OH", "rate": "5.7500", "name": "State Tax", "shipping": true, "order": 33 }, { "country": "US", "state": "OK", "rate": "4.5000", "name": "State Tax", "shipping": false, "order": 34 }, { "country": "US", "state": "PA", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 35 }, { "country": "US", "state": "PR", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 36 }, { "country": "US", "state": "RI", "rate": "7.0000", "name": "State Tax", "shipping": false, "order": 37 }, { "country": "US", "state": "SC", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 38 }, { "country": "US", "state": "SD", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 39 }, { "country": "US", "state": "TN", "rate": "7.0000", "name": "State Tax", "shipping": true, "order": 40 }, { "country": "US", "state": "TX", "rate": "6.2500", "name": "State Tax", "shipping": true, "order": 41 }, { "country": "US", "state": "UT", "rate": "5.9500", "name": "State Tax", "shipping": false, "order": 42 }, { "country": "US", "state": "VT", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 43 }, { "country": "US", "state": "VA", "rate": "5.3000", "name": "State Tax", "shipping": false, "order": 44 }, { "country": "US", "state": "WA", "rate": "6.5000", "name": "State Tax", "shipping": true, "order": 45 }, { "country": "US", "state": "WV", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 46 }, { "country": "US", "state": "WI", "rate": "5.0000", "name": "State Tax", "shipping": true, "order": 47 }, { "country": "US", "state": "WY", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 48 } ] }' ``` ```javascript const data = { create: [ { country: "US", state: "AL", rate: "4.0000", name: "State Tax", shipping: false, order: 1 }, { country: "US", state: "AZ", rate: "5.6000", name: "State Tax", shipping: false, order: 2 }, { country: "US", state: "AR", rate: "6.5000", name: "State Tax", shipping: true, order: 3 }, { country: "US", state: "CA", rate: "7.5000", name: "State Tax", shipping: false, order: 4 }, { country: "US", state: "CO", rate: "2.9000", name: "State Tax", shipping: false, order: 5 }, { country: "US", state: "CT", rate: "6.3500", name: "State Tax", shipping: true, order: 6 }, { country: "US", state: "DC", rate: "5.7500", name: "State Tax", shipping: true, order: 7 }, { country: "US", state: "FL", rate: "6.0000", name: "State Tax", shipping: true, order: 8 }, { country: "US", state: "GA", rate: "4.0000", name: "State Tax", shipping: true, order: 9 }, { country: "US", state: "GU", rate: "4.0000", name: "State Tax", shipping: false, order: 10 }, { country: "US", state: "HI", rate: "4.0000", name: "State Tax", shipping: true, order: 11 }, { country: "US", state: "ID", rate: "6.0000", name: "State Tax", shipping: false, order: 12 }, { country: "US", state: "IL", rate: "6.2500", name: "State Tax", shipping: false, order: 13 }, { country: "US", state: "IN", rate: "7.0000", name: "State Tax", shipping: false, order: 14 }, { country: "US", state: "IA", rate: "6.0000", name: "State Tax", shipping: false, order: 15 }, { country: "US", state: "KS", rate: "6.1500", name: "State Tax", shipping: true, order: 16 }, { country: "US", state: "KY", rate: "6.0000", name: "State Tax", shipping: true, order: 17 }, { country: "US", state: "LA", rate: "4.0000", name: "State Tax", shipping: false, order: 18 }, { country: "US", state: "ME", rate: "5.5000", name: "State Tax", shipping: false, order: 19 }, { country: "US", state: "MD", rate: "6.0000", name: "State Tax", shipping: false, order: 20 }, { country: "US", state: "MA", rate: "6.2500", name: "State Tax", shipping: false, order: 21 }, { country: "US", state: "MI", rate: "6.0000", name: "State Tax", shipping: true, order: 22 }, { country: "US", state: "MN", rate: "6.8750", name: "State Tax", shipping: true, order: 23 }, { country: "US", state: "MS", rate: "7.0000", name: "State Tax", shipping: true, order: 24 }, { country: "US", state: "MO", rate: "4.2250", name: "State Tax", shipping: false, order: 25 }, { country: "US", state: "NE", rate: "5.5000", name: "State Tax", shipping: true, order: 26 }, { country: "US", state: "NV", rate: "6.8500", name: "State Tax", shipping: false, order: 27 }, { country: "US", state: "NJ", rate: "7.0000", name: "State Tax", shipping: true, order: 28 }, { country: "US", state: "NM", rate: "5.1250", name: "State Tax", shipping: true, order: 29 }, { country: "US", state: "NY", rate: "4.0000", name: "State Tax", shipping: true, order: 30 }, { country: "US", state: "NC", rate: "4.7500", name: "State Tax", shipping: true, order: 31 }, { country: "US", state: "ND", rate: "5.0000", name: "State Tax", shipping: true, order: 32 }, { country: "US", state: "OH", rate: "5.7500", name: "State Tax", shipping: true, order: 33 }, { country: "US", state: "OK", rate: "4.5000", name: "State Tax", shipping: false, order: 34 }, { country: "US", state: "PA", rate: "6.0000", name: "State Tax", shipping: true, order: 35 }, { country: "US", state: "PR", rate: "6.0000", name: "State Tax", shipping: false, order: 36 }, { country: "US", state: "RI", rate: "7.0000", name: "State Tax", shipping: false, order: 37 }, { country: "US", state: "SC", rate: "6.0000", name: "State Tax", shipping: true, order: 38 }, { country: "US", state: "SD", rate: "4.0000", name: "State Tax", shipping: true, order: 39 }, { country: "US", state: "TN", rate: "7.0000", name: "State Tax", shipping: true, order: 40 }, { country: "US", state: "TX", rate: "6.2500", name: "State Tax", shipping: true, order: 41 }, { country: "US", state: "UT", rate: "5.9500", name: "State Tax", shipping: false, order: 42 }, { country: "US", state: "VT", rate: "6.0000", name: "State Tax", shipping: true, order: 43 }, { country: "US", state: "VA", rate: "5.3000", name: "State Tax", shipping: false, order: 44 }, { country: "US", state: "WA", rate: "6.5000", name: "State Tax", shipping: true, order: 45 }, { country: "US", state: "WV", rate: "6.0000", name: "State Tax", shipping: true, order: 46 }, { country: "US", state: "WI", rate: "5.0000", name: "State Tax", shipping: true, order: 47 }, { country: "US", state: "WY", rate: "4.0000", name: "State Tax", shipping: true, order: 48 } ] }; WooCommerce.post("taxes/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'country' => 'US', 'state' => 'AL', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 1 ], [ 'country' => 'US', 'state' => 'AZ', 'rate' => '5.6000', 'name' => 'State Tax', 'shipping' => false, 'order' => 2 ], [ 'country' => 'US', 'state' => 'AR', 'rate' => '6.5000', 'name' => 'State Tax', 'shipping' => true, 'order' => 3 ], [ 'country' => 'US', 'state' => 'CA', 'rate' => '7.5000', 'name' => 'State Tax', 'shipping' => false, 'order' => 4 ], [ 'country' => 'US', 'state' => 'CO', 'rate' => '2.9000', 'name' => 'State Tax', 'shipping' => false, 'order' => 5 ], [ 'country' => 'US', 'state' => 'CT', 'rate' => '6.3500', 'name' => 'State Tax', 'shipping' => true, 'order' => 6 ], [ 'country' => 'US', 'state' => 'DC', 'rate' => '5.7500', 'name' => 'State Tax', 'shipping' => true, 'order' => 7 ], [ 'country' => 'US', 'state' => 'FL', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 8 ], [ 'country' => 'US', 'state' => 'GA', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 9 ], [ 'country' => 'US', 'state' => 'GU', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 10 ], [ 'country' => 'US', 'state' => 'HI', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 11 ], [ 'country' => 'US', 'state' => 'ID', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 12 ], [ 'country' => 'US', 'state' => 'IL', 'rate' => '6.2500', 'name' => 'State Tax', 'shipping' => false, 'order' => 13 ], [ 'country' => 'US', 'state' => 'IN', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 14 ], [ 'country' => 'US', 'state' => 'IA', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 15 ], [ 'country' => 'US', 'state' => 'KS', 'rate' => '6.1500', 'name' => 'State Tax', 'shipping' => true, 'order' => 16 ], [ 'country' => 'US', 'state' => 'KY', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 17 ], [ 'country' => 'US', 'state' => 'LA', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 18 ], [ 'country' => 'US', 'state' => 'ME', 'rate' => '5.5000', 'name' => 'State Tax', 'shipping' => false, 'order' => 19 ], [ 'country' => 'US', 'state' => 'MD', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 20 ], [ 'country' => 'US', 'state' => 'MA', 'rate' => '6.2500', 'name' => 'State Tax', 'shipping' => false, 'order' => 21 ], [ 'country' => 'US', 'state' => 'MI', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 22 ], [ 'country' => 'US', 'state' => 'MN', 'rate' => '6.8750', 'name' => 'State Tax', 'shipping' => true, 'order' => 23 ], [ 'country' => 'US', 'state' => 'MS', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 24 ], [ 'country' => 'US', 'state' => 'MO', 'rate' => '4.2250', 'name' => 'State Tax', 'shipping' => false, 'order' => 25 ], [ 'country' => 'US', 'state' => 'NE', 'rate' => '5.5000', 'name' => 'State Tax', 'shipping' => true, 'order' => 26 ], [ 'country' => 'US', 'state' => 'NV', 'rate' => '6.8500', 'name' => 'State Tax', 'shipping' => false, 'order' => 27 ], [ 'country' => 'US', 'state' => 'NJ', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 28 ], [ 'country' => 'US', 'state' => 'NM', 'rate' => '5.1250', 'name' => 'State Tax', 'shipping' => true, 'order' => 29 ], [ 'country' => 'US', 'state' => 'NY', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 30 ], [ 'country' => 'US', 'state' => 'NC', 'rate' => '4.7500', 'name' => 'State Tax', 'shipping' => true, 'order' => 31 ], [ 'country' => 'US', 'state' => 'ND', 'rate' => '5.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 32 ], [ 'country' => 'US', 'state' => 'OH', 'rate' => '5.7500', 'name' => 'State Tax', 'shipping' => true, 'order' => 33 ], [ 'country' => 'US', 'state' => 'OK', 'rate' => '4.5000', 'name' => 'State Tax', 'shipping' => false, 'order' => 34 ], [ 'country' => 'US', 'state' => 'PA', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 35 ], [ 'country' => 'US', 'state' => 'PR', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 36 ], [ 'country' => 'US', 'state' => 'RI', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 37 ], [ 'country' => 'US', 'state' => 'SC', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 38 ], [ 'country' => 'US', 'state' => 'SD', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 39 ], [ 'country' => 'US', 'state' => 'TN', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 40 ], [ 'country' => 'US', 'state' => 'TX', 'rate' => '6.2500', 'name' => 'State Tax', 'shipping' => true, 'order' => 41 ], [ 'country' => 'US', 'state' => 'UT', 'rate' => '5.9500', 'name' => 'State Tax', 'shipping' => false, 'order' => 42 ], [ 'country' => 'US', 'state' => 'VT', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 43 ], [ 'country' => 'US', 'state' => 'VA', 'rate' => '5.3000', 'name' => 'State Tax', 'shipping' => false, 'order' => 44 ], [ 'country' => 'US', 'state' => 'WA', 'rate' => '6.5000', 'name' => 'State Tax', 'shipping' => true, 'order' => 45 ], [ 'country' => 'US', 'state' => 'WV', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 46 ], [ 'country' => 'US', 'state' => 'WI', 'rate' => '5.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 47 ], [ 'country' => 'US', 'state' => 'WY', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 48 ] ] ]; print_r($woocommerce->post('taxes/batch', $data)); ?> ``` ```python data = { "create": [ { "country": "US", "state": "AL", "rate": "4.0000", "name": "State Tax", "shipping": False, "order": 1 }, { "country": "US", "state": "AZ", "rate": "5.6000", "name": "State Tax", "shipping": False, "order": 2 }, { "country": "US", "state": "AR", "rate": "6.5000", "name": "State Tax", "shipping": True, "order": 3 }, { "country": "US", "state": "CA", "rate": "7.5000", "name": "State Tax", "shipping": False, "order": 4 }, { "country": "US", "state": "CO", "rate": "2.9000", "name": "State Tax", "shipping": False, "order": 5 }, { "country": "US", "state": "CT", "rate": "6.3500", "name": "State Tax", "shipping": True, "order": 6 }, { "country": "US", "state": "DC", "rate": "5.7500", "name": "State Tax", "shipping": True, "order": 7 }, { "country": "US", "state": "FL", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 8 }, { "country": "US", "state": "GA", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 9 }, { "country": "US", "state": "GU", "rate": "4.0000", "name": "State Tax", "shipping": False, "order": 10 }, { "country": "US", "state": "HI", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 11 }, { "country": "US", "state": "ID", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 12 }, { "country": "US", "state": "IL", "rate": "6.2500", "name": "State Tax", "shipping": False, "order": 13 }, { "country": "US", "state": "IN", "rate": "7.0000", "name": "State Tax", "shipping": False, "order": 14 }, { "country": "US", "state": "IA", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 15 }, { "country": "US", "state": "KS", "rate": "6.1500", "name": "State Tax", "shipping": True, "order": 16 }, { "country": "US", "state": "KY", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 17 }, { "country": "US", "state": "LA", "rate": "4.0000", "name": "State Tax", "shipping": False, "order": 18 }, { "country": "US", "state": "ME", "rate": "5.5000", "name": "State Tax", "shipping": False, "order": 19 }, { "country": "US", "state": "MD", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 20 }, { "country": "US", "state": "MA", "rate": "6.2500", "name": "State Tax", "shipping": False, "order": 21 }, { "country": "US", "state": "MI", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 22 }, { "country": "US", "state": "MN", "rate": "6.8750", "name": "State Tax", "shipping": True, "order": 23 }, { "country": "US", "state": "MS", "rate": "7.0000", "name": "State Tax", "shipping": True, "order": 24 }, { "country": "US", "state": "MO", "rate": "4.2250", "name": "State Tax", "shipping": False, "order": 25 }, { "country": "US", "state": "NE", "rate": "5.5000", "name": "State Tax", "shipping": True, "order": 26 }, { "country": "US", "state": "NV", "rate": "6.8500", "name": "State Tax", "shipping": False, "order": 27 }, { "country": "US", "state": "NJ", "rate": "7.0000", "name": "State Tax", "shipping": True, "order": 28 }, { "country": "US", "state": "NM", "rate": "5.1250", "name": "State Tax", "shipping": True, "order": 29 }, { "country": "US", "state": "NY", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 30 }, { "country": "US", "state": "NC", "rate": "4.7500", "name": "State Tax", "shipping": True, "order": 31 }, { "country": "US", "state": "ND", "rate": "5.0000", "name": "State Tax", "shipping": True, "order": 32 }, { "country": "US", "state": "OH", "rate": "5.7500", "name": "State Tax", "shipping": True, "order": 33 }, { "country": "US", "state": "OK", "rate": "4.5000", "name": "State Tax", "shipping": False, "order": 34 }, { "country": "US", "state": "PA", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 35 }, { "country": "US", "state": "PR", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 36 }, { "country": "US", "state": "RI", "rate": "7.0000", "name": "State Tax", "shipping": False, "order": 37 }, { "country": "US", "state": "SC", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 38 }, { "country": "US", "state": "SD", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 39 }, { "country": "US", "state": "TN", "rate": "7.0000", "name": "State Tax", "shipping": True, "order": 40 }, { "country": "US", "state": "TX", "rate": "6.2500", "name": "State Tax", "shipping": True, "order": 41 }, { "country": "US", "state": "UT", "rate": "5.9500", "name": "State Tax", "shipping": False, "order": 42 }, { "country": "US", "state": "VT", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 43 }, { "country": "US", "state": "VA", "rate": "5.3000", "name": "State Tax", "shipping": False, "order": 44 }, { "country": "US", "state": "WA", "rate": "6.5000", "name": "State Tax", "shipping": True, "order": 45 }, { "country": "US", "state": "WV", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 46 }, { "country": "US", "state": "WI", "rate": "5.0000", "name": "State Tax", "shipping": True, "order": 47 }, { "country": "US", "state": "WY", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 48 } ] } print(wcapi.post("taxes/batch", data).json()) ``` ```ruby data = { create: [ { country: "US", state: "AL", rate: "4.0000", name: "State Tax", shipping: false, order: 1 }, { country: "US", state: "AZ", rate: "5.6000", name: "State Tax", shipping: false, order: 2 }, { country: "US", state: "AR", rate: "6.5000", name: "State Tax", shipping: true, order: 3 }, { country: "US", state: "CA", rate: "7.5000", name: "State Tax", shipping: false, order: 4 }, { country: "US", state: "CO", rate: "2.9000", name: "State Tax", shipping: false, order: 5 }, { country: "US", state: "CT", rate: "6.3500", name: "State Tax", shipping: true, order: 6 }, { country: "US", state: "DC", rate: "5.7500", name: "State Tax", shipping: true, order: 7 }, { country: "US", state: "FL", rate: "6.0000", name: "State Tax", shipping: true, order: 8 }, { country: "US", state: "GA", rate: "4.0000", name: "State Tax", shipping: true, order: 9 }, { country: "US", state: "GU", rate: "4.0000", name: "State Tax", shipping: false, order: 10 }, { country: "US", state: "HI", rate: "4.0000", name: "State Tax", shipping: true, order: 11 }, { country: "US", state: "ID", rate: "6.0000", name: "State Tax", shipping: false, order: 12 }, { country: "US", state: "IL", rate: "6.2500", name: "State Tax", shipping: false, order: 13 }, { country: "US", state: "IN", rate: "7.0000", name: "State Tax", shipping: false, order: 14 }, { country: "US", state: "IA", rate: "6.0000", name: "State Tax", shipping: false, order: 15 }, { country: "US", state: "KS", rate: "6.1500", name: "State Tax", shipping: true, order: 16 }, { country: "US", state: "KY", rate: "6.0000", name: "State Tax", shipping: true, order: 17 }, { country: "US", state: "LA", rate: "4.0000", name: "State Tax", shipping: false, order: 18 }, { country: "US", state: "ME", rate: "5.5000", name: "State Tax", shipping: false, order: 19 }, { country: "US", state: "MD", rate: "6.0000", name: "State Tax", shipping: false, order: 20 }, { country: "US", state: "MA", rate: "6.2500", name: "State Tax", shipping: false, order: 21 }, { country: "US", state: "MI", rate: "6.0000", name: "State Tax", shipping: true, order: 22 }, { country: "US", state: "MN", rate: "6.8750", name: "State Tax", shipping: true, order: 23 }, { country: "US", state: "MS", rate: "7.0000", name: "State Tax", shipping: true, order: 24 }, { country: "US", state: "MO", rate: "4.2250", name: "State Tax", shipping: false, order: 25 }, { country: "US", state: "NE", rate: "5.5000", name: "State Tax", shipping: true, order: 26 }, { country: "US", state: "NV", rate: "6.8500", name: "State Tax", shipping: false, order: 27 }, { country: "US", state: "NJ", rate: "7.0000", name: "State Tax", shipping: true, order: 28 }, { country: "US", state: "NM", rate: "5.1250", name: "State Tax", shipping: true, order: 29 }, { country: "US", state: "NY", rate: "4.0000", name: "State Tax", shipping: true, order: 30 }, { country: "US", state: "NC", rate: "4.7500", name: "State Tax", shipping: true, order: 31 }, { country: "US", state: "ND", rate: "5.0000", name: "State Tax", shipping: true, order: 32 }, { country: "US", state: "OH", rate: "5.7500", name: "State Tax", shipping: true, order: 33 }, { country: "US", state: "OK", rate: "4.5000", name: "State Tax", shipping: false, order: 34 }, { country: "US", state: "PA", rate: "6.0000", name: "State Tax", shipping: true, order: 35 }, { country: "US", state: "PR", rate: "6.0000", name: "State Tax", shipping: false, order: 36 }, { country: "US", state: "RI", rate: "7.0000", name: "State Tax", shipping: false, order: 37 }, { country: "US", state: "SC", rate: "6.0000", name: "State Tax", shipping: true, order: 38 }, { country: "US", state: "SD", rate: "4.0000", name: "State Tax", shipping: true, order: 39 }, { country: "US", state: "TN", rate: "7.0000", name: "State Tax", shipping: true, order: 40 }, { country: "US", state: "TX", rate: "6.2500", name: "State Tax", shipping: true, order: 41 }, { country: "US", state: "UT", rate: "5.9500", name: "State Tax", shipping: false, order: 42 }, { country: "US", state: "VT", rate: "6.0000", name: "State Tax", shipping: true, order: 43 }, { country: "US", state: "VA", rate: "5.3000", name: "State Tax", shipping: false, order: 44 }, { country: "US", state: "WA", rate: "6.5000", name: "State Tax", shipping: true, order: 45 }, { country: "US", state: "WV", rate: "6.0000", name: "State Tax", shipping: true, order: 46 }, { country: "US", state: "WI", rate: "5.0000", name: "State Tax", shipping: true, order: 47 }, { country: "US", state: "WY", rate: "4.0000", name: "State Tax", shipping: true, order: 48 } ] } woocommerce.post("taxes/batch", data).parsed_response ``` ```json { "create": [ { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 73, "country": "US", "state": "AZ", "postcode": "", "city": "", "rate": "5.6000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 2, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/73" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 74, "country": "US", "state": "AR", "postcode": "", "city": "", "rate": "6.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 3, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/74" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 75, "country": "US", "state": "CA", "postcode": "", "city": "", "rate": "7.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 4, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/75" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 76, "country": "US", "state": "CO", "postcode": "", "city": "", "rate": "2.9000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 5, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/76" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 77, "country": "US", "state": "CT", "postcode": "", "city": "", "rate": "6.3500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 6, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/77" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 78, "country": "US", "state": "DC", "postcode": "", "city": "", "rate": "5.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 7, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/78" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 79, "country": "US", "state": "FL", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 8, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/79" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 80, "country": "US", "state": "GA", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 9, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/80" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 81, "country": "US", "state": "GU", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 10, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/81" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 82, "country": "US", "state": "HI", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 11, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/82" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 83, "country": "US", "state": "ID", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 12, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/83" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 84, "country": "US", "state": "IL", "postcode": "", "city": "", "rate": "6.2500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 13, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/84" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 85, "country": "US", "state": "IN", "postcode": "", "city": "", "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 14, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/85" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 86, "country": "US", "state": "IA", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 15, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/86" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 87, "country": "US", "state": "KS", "postcode": "", "city": "", "rate": "6.1500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 16, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/87" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 88, "country": "US", "state": "KY", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 17, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/88" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 89, "country": "US", "state": "LA", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 18, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/89" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 90, "country": "US", "state": "ME", "postcode": "", "city": "", "rate": "5.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 19, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/90" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 91, "country": "US", "state": "MD", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 20, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/91" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 92, "country": "US", "state": "MA", "postcode": "", "city": "", "rate": "6.2500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 21, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/92" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 93, "country": "US", "state": "MI", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 22, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/93" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 94, "country": "US", "state": "MN", "postcode": "", "city": "", "rate": "6.8750", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 23, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/94" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 95, "country": "US", "state": "MS", "postcode": "", "city": "", "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 24, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/95" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 96, "country": "US", "state": "MO", "postcode": "", "city": "", "rate": "4.2250", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 25, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/96" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 97, "country": "US", "state": "NE", "postcode": "", "city": "", "rate": "5.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 26, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/97" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 98, "country": "US", "state": "NV", "postcode": "", "city": "", "rate": "6.8500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 27, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/98" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 99, "country": "US", "state": "NJ", "postcode": "", "city": "", "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 28, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/99" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 100, "country": "US", "state": "NM", "postcode": "", "city": "", "rate": "5.1250", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 29, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/100" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 101, "country": "US", "state": "NY", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 30, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/101" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 102, "country": "US", "state": "NC", "postcode": "", "city": "", "rate": "4.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 31, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/102" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 103, "country": "US", "state": "ND", "postcode": "", "city": "", "rate": "5.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 32, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/103" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 104, "country": "US", "state": "OH", "postcode": "", "city": "", "rate": "5.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 33, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/104" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 105, "country": "US", "state": "OK", "postcode": "", "city": "", "rate": "4.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 34, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/105" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 106, "country": "US", "state": "PA", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 35, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/106" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 107, "country": "US", "state": "PR", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 36, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/107" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 108, "country": "US", "state": "RI", "postcode": "", "city": "", "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 37, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/108" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 109, "country": "US", "state": "SC", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 38, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/109" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 110, "country": "US", "state": "SD", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 39, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/110" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 111, "country": "US", "state": "TN", "postcode": "", "city": "", "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 40, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/111" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 112, "country": "US", "state": "TX", "postcode": "", "city": "", "rate": "6.2500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 41, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/112" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 113, "country": "US", "state": "UT", "postcode": "", "city": "", "rate": "5.9500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 42, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/113" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 114, "country": "US", "state": "VT", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 43, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/114" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 115, "country": "US", "state": "VA", "postcode": "", "city": "", "rate": "5.3000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 44, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/115" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 116, "country": "US", "state": "WA", "postcode": "", "city": "", "rate": "6.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 45, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/116" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 117, "country": "US", "state": "WV", "postcode": "", "city": "", "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 46, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/117" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 118, "country": "US", "state": "WI", "postcode": "", "city": "", "rate": "5.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 47, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/118" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } }, { "id": 119, "country": "US", "state": "WY", "postcode": "", "city": "", "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 48, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/taxes/119" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/taxes" } ] } } ] } ``` --- ## Webhooks *Source: apis/rest-api/v2/webhooks.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Webhooks The webhooks API allows you to create, view, update, and delete individual, or a batch, of webhooks. Webhooks can be managed via the WooCommerce settings screen or by using the REST API endpoints. The `WC_Webhook` class manages all data storage and retrieval of the webhook custom post type, as well as enqueuing webhook actions and processing/delivering/logging webhooks. On `woocommerce_init`, active webhooks are loaded. Each webhook has: * `status`: active (delivers payload), paused (delivery paused by admin), disabled (delivery paused by failure). * `topic`: determines which resource events the webhook is triggered for. * `delivery URL`: URL where the payload is delivered, must be HTTP or HTTPS. * `secret`: an optional secret key that is used to generate a HMAC-SHA256 hash of the request body so the receiver can verify authenticity of the webhook. * `hooks`: an array of hook names that are added and bound to the webhook for processing. ### Topics The topic is a combination resource (e.g. order) and event (e.g. created) and maps to one or more hook names (e.g. `woocommerce_checkout_order_processed`). Webhooks can be created using the topic name and the appropriate hooks are automatically added. Core topics are: * Coupons: `coupon.created`, `coupon.updated` and `coupon.deleted`. * Customers: `customer.created`, `customer.updated` and `customer.deleted`. * Orders: `order.created`, `order.updated` and `order.deleted`. * Products: `product.created`, `product.updated` and `product.deleted`. Custom topics can also be used which map to a single hook name, for example you could add a webhook with topic `action.woocommerce_add_to_cart` that is triggered on that event. Custom topics pass the first hook argument to the payload, so in this example the `cart_item_key` would be included in the payload. ### Delivery/payload Delivery is performed using `wp_remote_post()` (HTTP POST) and processed in the background by default using wp-cron. A few custom headers are added to the request to help the receiver process the webhook: * `X-WC-Webhook-Source`: `http://example.com/`. * `X-WC-Webhook-Topic` - e.g. `order.updated`. * `X-WC-Webhook-Resource` - e.g. `order`. * `X-WC-Webhook-Event` - e.g. `updated`. * `X-WC-Webhook-Signature` - a base64 encoded HMAC-SHA256 hash of the payload. * `X-WC-Webhook-ID` - webhook's post ID. * `X-WC-Webhook-Delivery-ID` - delivery log ID (a comment). The payload is JSON encoded and for API resources (coupons, customers, orders, products), the response is exactly the same as if requested via the REST API. ### Logging Requests/responses are logged as comments on the webhook custom post type. Each delivery log includes: * Request duration. * Request URL, method, headers, and body. * Response Code, message, headers, and body. Only the 25 most recent delivery logs are kept in order to reduce comment table bloat. After 5 consecutive failed deliveries (as defined by a non HTTP 2xx response code), the webhook is disabled and must be edited via the REST API to re-enable. Delivery logs can be fetched through the REST API endpoint or in code using `WC_Webhook::get_delivery_logs()`. ### Visual interface You can find the Webhooks interface going to "WooCommerce" > "Settings" > "API" > "Webhooks", see our [Visual Webhooks docs](https://docs.woocommerce.com/document/webhooks/) for more details. ## Webhook properties | Attribute | Type | Description | | ------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | A friendly name for the webhook. | | `status` | string | Webhook status. Options: `active`, `paused` and `disabled`. Default is `active`. | | `topic` | string | Webhook topic. `MANDATORY` | | `resource` | string | Webhook resource. `READ-ONLY` | | `event` | string | Webhook event. `READ-ONLY` | | `hooks` | array | WooCommerce action names associated with the webhook. `READ-ONLY` | | `delivery_url` | string | The URL where the webhook payload is delivered. `READ-ONLY` `MANDATORY` | | `secret` | string | Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default is a MD5 hash from the current user's ID|username if not provided. `WRITE-ONLY` `MANDATORY` | | `date_created` | date-time | The date the webhook was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the webhook was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the webhook was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the webhook was last modified, as GMT. `READ-ONLY` | ### Webhook delivery properties | Attribute | Type | Description | | ------------------ | --------- | --------------------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `duration` | string | The delivery duration, in seconds. `READ-ONLY` | | `summary` | string | A friendly summary of the response including the HTTP response code, message, and body. `READ-ONLY` | | `request_url` | string | The URL where the webhook was delivered. `READ-ONLY` | | `request_headers` | array | Request headers. `READ-ONLY` | | `request_body` | string | Request body. `READ-ONLY` | | `response_code` | string | The HTTP response code from the receiving server. `READ-ONLY` | | `response_message` | string | The HTTP response message from the receiving server. `READ-ONLY` | | `response_headers` | array | Array of the response headers from the receiving server. `READ-ONLY` | | `response_body` | string | The response body from the receiving server. `READ-ONLY` | | `date_created` | date-time | The date the webhook delivery was logged, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the webhook delivery was logged, GMT. `READ-ONLY` | #### Request header properties | Attribute | Type | Description | |----------------------------|---------|--------------------------------------------------------------------------------------------------------------------------------------| | `User-Agent` | string | The request user agent, default is "WooCommerce/\{version\} Hookshot (WordPress/\{version\})". `READ-ONLY` | | `Content-Type` | string | The request content-type, default is "application/json". `READ-ONLY` | | `X-WC-Webhook-Source` | string | The webhook source. `READ-ONLY` | | `X-WC-Webhook-Topic` | string | The webhook topic. `READ-ONLY` | | `X-WC-Webhook-Resource` | string | The webhook resource. `READ-ONLY` | | `X-WC-Webhook-Event` | string | The webhook event. `READ-ONLY` | | `X-WC-Webhook-Signature` | string | A base64 encoded HMAC-SHA256 hash of the payload. `READ-ONLY` | | `X-WC-Webhook-ID` | integer | The webhook's ID. `READ-ONLY` | | `X-WC-Webhook-Delivery-ID` | integer | The delivery ID. `READ-ONLY` | ## Create a webhook This API helps you to create a new webhook. ```http POST /wp-json/wc/v2/webhooks ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/webhooks \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Order updated", "topic": "order.updated", "delivery_url": "http://requestb.in/1g0sxmo1" }' ``` ```javascript const data = { name: "Order updated", topic: "order.updated", delivery_url: "http://requestb.in/1g0sxmo1" }; WooCommerce.post("webhooks", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'Order updated', 'topic' => 'order.updated', 'delivery_url' => 'http://requestb.in/1g0sxmo1' ]; print_r($woocommerce->post('webhooks', $data)); ?> ``` ```python data = { "name": "Order updated", "topic": "order.updated", "delivery_url": "http://requestb.in/1g0sxmo1" } print(wcapi.post("webhooks", data).json()) ``` ```ruby data = { name: "Order updated", topic: "order.updated", delivery_url: "http://requestb.in/1g0sxmo1" } woocommerce.post("webhooks", data).parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "active", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:17:52", "date_modified_gmt": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks" } ] } } ``` ## Retrieve a webhook This API lets you retrieve and view a specific webhook. ```http GET /wp-json/wc/v2/webhooks/ ``` ```shell curl https://example.com/wp-json/wc/v2/webhooks/142 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("webhooks/142") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('webhooks/142')); ?> ``` ```python print(wcapi.get("webhooks/142").json()) ``` ```ruby woocommerce.get("webhooks/142").parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "active", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:17:52", "date_modified_gmt": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks" } ] } } ``` ## List all webhooks This API helps you to view all the webhooks. ```http GET /wp-json/wc/v2/webhooks ``` ```shell curl https://example.com/wp-json/wc/v2/webhooks \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("webhooks") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('webhooks')); ?> ``` ```python print(wcapi.get("webhooks").json()) ``` ```ruby woocommerce.get("webhooks").parsed_response ``` ```json [ { "id": 143, "name": "Customer created", "status": "active", "topic": "customer.created", "resource": "customer", "event": "created", "hooks": [ "user_register", "woocommerce_created_customer", "woocommerce_api_create_customer" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:17:52", "date_modified_gmt": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/143" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks" } ] } }, { "id": 142, "name": "Order updated", "status": "active", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:17:52", "date_modified_gmt": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | --------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `id`, `include`, `title` and `slug`. Default is `date`. | | `status` | string | Limit result set to webhooks assigned a specific status. Options: `all`, `active`, `paused` and `disabled`. Default is `all`. | ## Update a webhook This API lets you make changes to a webhook. ```http PUT /wp-json/wc/v2/webhook/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v2/webhook/142 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "status": "paused" }' ``` ```javascript const data = { status: "paused" } WooCommerce.put("webhooks/142", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php 'paused' ]; print_r($woocommerce->put('webhooks/142', $data)); ?> ``` ```python data = { "status": "paused" } print(wcapi.put("webhooks/142", data).json()) ``` ```ruby data = { status: "paused" } woocommerce.put("webhooks/142", data).parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "paused", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T17:30:12", "date_modified_gmt": "2016-05-15T20:30:12", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks" } ] } } ``` ## Delete a webhook This API helps you delete a webhook. ```http DELETE /wp-json/wc/v2/webhooks/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v2/webhooks/142 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete("webhooks/142") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php delete('webhooks/142')); ?> ``` ```python print(wcapi.delete("webhooks/142").json()) ``` ```ruby woocommerce.delete("webhooks/142").parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "paused", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:30:12", "date_modified_gmt": "2016-05-15T20:30:12", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks" } ] } } ``` #### Available parameters | Parameter | Type | Description | |-----------|--------|----------------------------------------------------------------------------| | `force` | string | Use `true` whether to permanently delete the webhook, Default is `false`. | ## Batch update webhooks This API helps you to batch create, update and delete multiple webhooks. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v2/webhooks/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v2/webhooks/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Coupon created", "topic": "coupon.created", "delivery_url": "http://requestb.in/1g0sxmo1" }, { "name": "Customer deleted", "topic": "customer.deleted", "delivery_url": "http://requestb.in/1g0sxmo1" } ], "delete": [ 143 ] }' ``` ```javascript const data = { create: [ { name: "Round toe", topic: "coupon.created", delivery_url: "http://requestb.in/1g0sxmo1" }, { name: "Customer deleted", topic: "customer.deleted", delivery_url: "http://requestb.in/1g0sxmo1" } ], delete: [ 143 ] }; WooCommerce.post("webhooks/batch", data) .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php [ [ 'name' => 'Round toe', 'topic' => 'coupon.created', 'delivery_url' => 'http://requestb.in/1g0sxmo1' ], [ 'name' => 'Customer deleted', 'topic' => 'customer.deleted', 'delivery_url' => 'http://requestb.in/1g0sxmo1' ] ], 'delete' => [ 143 ] ]; print_r($woocommerce->post('webhooks/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Round toe", "topic": "coupon.created", "delivery_url": "http://requestb.in/1g0sxmo1" }, { "name": "Customer deleted", "topic": "customer.deleted", "delivery_url": "http://requestb.in/1g0sxmo1" } ], "delete": [ 143 ] } print(wcapi.post("webhooks/batch", data).json()) ``` ```ruby data = { create: [ { name: "Round toe", topic: "coupon.created", delivery_url: "http://requestb.in/1g0sxmo1" }, { name: "Customer deleted", topic: "customer.deleted", delivery_url: "http://requestb.in/1g0sxmo1" } ], delete: [ 143 ] } woocommerce.post("webhooks/batch", data).parsed_response ``` ```json { "create": [ { "id": 146, "name": "Coupon created", "status": "active", "topic": "coupon.created", "resource": "coupon", "event": "created", "hooks": [ "woocommerce_process_shop_coupon_meta", "woocommerce_api_create_coupon" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-25T01:56:26", "date_created_gmt": "2016-05-24T22:56:26", "date_modified": "2016-05-25T01:56:26", "date_modified_gmt": "2016-05-24T22:56:26", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/146" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks" } ] } }, { "id": 147, "name": "Customer deleted", "status": "active", "topic": "customer.deleted", "resource": "customer", "event": "deleted", "hooks": [ "delete_user" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-25T01:56:30", "date_created_gmt": "2016-05-24T22:56:30", "date_modified": "2016-05-25T01:56:30", "date_modified_gmt": "2016-05-24T22:56:30", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/147" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks" } ] } } ], "delete": [ { "id": 143, "name": "Webhook created on May 24, 2016 @ 03:20 AM", "status": "active", "topic": "customer.created", "resource": "customer", "event": "created", "hooks": [ "user_register", "woocommerce_created_customer", "woocommerce_api_create_customer" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:17:52", "date_modified_gmt": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/143" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks" } ] } } ] } ``` ## Retrieve webhook delivery This API lets you retrieve and view a specific webhook delivery. ```http GET /wp-json/wc/v2/webhooks//deliveries/ ``` ```shell curl https://example.com/wp-json/wc/v2/webhooks/142/deliveries/54 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("webhooks/142/deliveries/54") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('webhooks/142/deliveries/54')); ?> ``` ```python print(wcapi.get("webhooks/142/deliveries/54").json()) ``` ```ruby woocommerce.get("webhooks/142/deliveries/54").parsed_response ``` ```json { "id": 54, "duration": "0.40888", "summary": "HTTP 200 OK: ok", "request_method": "POST", "request_url": "http://requestb.in/1g0sxmo1", "request_headers": { "User-Agent": "WooCommerce/2.6.0 Hookshot (WordPress/4.5.2)", "Content-Type": "application/json", "X-WC-Webhook-Source": "http://example.com/", "X-WC-Webhook-Topic": "order.updated", "X-WC-Webhook-Resource": "order", "X-WC-Webhook-Event": "updated", "X-WC-Webhook-Signature": "J72iu7hL93aUt2dFnyOBoBypwbmP6nt6Aor33nnOHxU=", "X-WC-Webhook-ID": 142, "X-WC-Webhook-Delivery-ID": 54 }, "request_body": "{\"order\":{\"id\":118,\"order_number\":118,\"order_key\":\"wc_order_5728e9a347a2d\",\"created_at\":\"2016-05-03T18:10:00Z\",\"updated_at\":\"2016-05-16T03:30:30Z\",\"completed_at\":\"2016-05-16T03:29:19Z\",\"status\":\"completed\",\"currency\":\"BRL\",\"total\":\"14.00\",\"subtotal\":\"4.00\",\"total_line_items_quantity\":2,\"total_tax\":\"0.00\",\"total_shipping\":\"10.00\",\"cart_tax\":\"0.00\",\"shipping_tax\":\"0.00\",\"total_discount\":\"0.00\",\"shipping_methods\":\"Flat Rate\",\"payment_details\":{\"method_id\":\"bacs\",\"method_title\":\"Direct Bank Transfer\",\"paid\":true},\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"},\"note\":\"\",\"customer_ip\":\"127.0.0.1\",\"customer_user_agent\":\"curl/7.47.0\",\"customer_id\":0,\"view_order_url\":\"http://example.com/my-account/view-order/118\",\"line_items\":[{\"id\":8,\"subtotal\":\"4.00\",\"subtotal_tax\":\"0.00\",\"total\":\"4.00\",\"total_tax\":\"0.00\",\"price\":\"2.00\",\"quantity\":2,\"tax_class\":null,\"name\":\"Woo Single #2\",\"product_id\":99,\"sku\":\"12345\",\"meta\":[]}],\"shipping_lines\":[{\"id\":9,\"method_id\":\"flat_rate\",\"method_title\":\"Flat Rate\",\"total\":\"10.00\"}],\"tax_lines\":[],\"fee_lines\":[],\"coupon_lines\":[],\"is_vat_exempt\":false,\"customer\":{\"id\":0,\"email\":\"john.doe@claudiosmweb.com\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"}}}}", "response_code": "200", "response_message": "OK", "response_headers": { "connection": "close", "server": "gunicorn/19.3.0", "date": "Tue, 16 May 2016 03:30:31 GMT", "content-type": "text/html; charset=utf-8", "content-length": "2", "sponsored-by": "https://www.runscope.com", "via": "1.1 vegur" }, "response_body": "ok", "date_created": "2016-05-16T06:30:31", "date_created_gmt": "2016-05-16T03:30:31", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142/deliveries/54" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142/deliveries" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142" } ] } } ``` :::note View the Webhooks Delivery properties for more details on this response. ::: ## List all webhook deliveries This API helps you to view all deliveries from a specific webhooks. ```http GET /wp-json/wc/v2/webhooks//deliveries ``` ```shell curl https://example.com/wp-json/wc/v2/webhooks/142/deliveries \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get("webhooks/142/deliveries") .then((response) => { console.log(response.data); }) .catch((error) => { console.log(error.response.data); }); ``` ```php get('webhooks/142/deliveries')); ?> ``` ```python print(wcapi.get("webhooks/142/deliveries").json()) ``` ```ruby woocommerce.get("webhooks/142/deliveries").parsed_response ``` ```json [ { "id": 54, "duration": "0.40888", "summary": "HTTP 200 OK: ok", "request_method": "POST", "request_url": "http://requestb.in/1g0sxmo1", "request_headers": { "User-Agent": "WooCommerce/2.6.0 Hookshot (WordPress/4.5.2)", "Content-Type": "application/json", "X-WC-Webhook-Source": "http://example.com/", "X-WC-Webhook-Topic": "order.updated", "X-WC-Webhook-Resource": "order", "X-WC-Webhook-Event": "updated", "X-WC-Webhook-Signature": "J72iu7hL93aUt2dFnyOBoBypwbmP6nt6Aor33nnOHxU=", "X-WC-Webhook-ID": 142, "X-WC-Webhook-Delivery-ID": 54 }, "request_body": "{\"order\":{\"id\":118,\"order_number\":118,\"order_key\":\"wc_order_5728e9a347a2d\",\"created_at\":\"2016-05-03T18:10:00Z\",\"updated_at\":\"2016-05-16T03:30:30Z\",\"completed_at\":\"2016-05-16T03:29:19Z\",\"status\":\"completed\",\"currency\":\"BRL\",\"total\":\"14.00\",\"subtotal\":\"4.00\",\"total_line_items_quantity\":2,\"total_tax\":\"0.00\",\"total_shipping\":\"10.00\",\"cart_tax\":\"0.00\",\"shipping_tax\":\"0.00\",\"total_discount\":\"0.00\",\"shipping_methods\":\"Flat Rate\",\"payment_details\":{\"method_id\":\"bacs\",\"method_title\":\"Direct Bank Transfer\",\"paid\":true},\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"},\"note\":\"\",\"customer_ip\":\"127.0.0.1\",\"customer_user_agent\":\"curl/7.47.0\",\"customer_id\":0,\"view_order_url\":\"http://example.com/my-account/view-order/118\",\"line_items\":[{\"id\":8,\"subtotal\":\"4.00\",\"subtotal_tax\":\"0.00\",\"total\":\"4.00\",\"total_tax\":\"0.00\",\"price\":\"2.00\",\"quantity\":2,\"tax_class\":null,\"name\":\"Woo Single #2\",\"product_id\":99,\"sku\":\"12345\",\"meta\":[]}],\"shipping_lines\":[{\"id\":9,\"method_id\":\"flat_rate\",\"method_title\":\"Flat Rate\",\"total\":\"10.00\"}],\"tax_lines\":[],\"fee_lines\":[],\"coupon_lines\":[],\"is_vat_exempt\":false,\"customer\":{\"id\":0,\"email\":\"john.doe@claudiosmweb.com\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"}}}}", "response_code": "200", "response_message": "OK", "response_headers": { "connection": "close", "server": "gunicorn/19.3.0", "date": "Tue, 16 May 2016 03:30:31 GMT", "content-type": "text/html; charset=utf-8", "content-length": "2", "sponsored-by": "https://www.runscope.com", "via": "1.1 vegur" }, "response_body": "ok", "date_created": "2016-05-16T06:30:31", "date_created_gmt": "2016-05-16T03:30:31", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142/deliveries/54" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142/deliveries" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142" } ] } }, { "id": 53, "duration": "0.7615", "summary": "HTTP 200 OK: ok", "request_method": "POST", "request_url": "http://requestb.in/1g0sxmo1", "request_headers": { "User-Agent": "WooCommerce/2.6.0 Hookshot (WordPress/4.5.2)", "Content-Type": "application/json", "X-WC-Webhook-Source": "http://example.com/", "X-WC-Webhook-Topic": "order.updated", "X-WC-Webhook-Resource": "order", "X-WC-Webhook-Event": "updated", "X-WC-Webhook-Signature": "Z996ccyueeoqdXZFq2ND2ETpsPGrXmWKj+yvQ0c2N1w=", "X-WC-Webhook-ID": 142, "X-WC-Webhook-Delivery-ID": 53 }, "request_body": "{\"order\":{\"id\":118,\"order_number\":118,\"order_key\":\"wc_order_5728e9a347a2d\",\"created_at\":\"2016-05-03T18:10:00Z\",\"updated_at\":\"2016-05-16T03:29:13Z\",\"completed_at\":\"2016-05-16T03:29:19Z\",\"status\":\"completed\",\"currency\":\"BRL\",\"total\":\"14.00\",\"subtotal\":\"4.00\",\"total_line_items_quantity\":2,\"total_tax\":\"0.00\",\"total_shipping\":\"10.00\",\"cart_tax\":\"0.00\",\"shipping_tax\":\"0.00\",\"total_discount\":\"0.00\",\"shipping_methods\":\"Flat Rate\",\"payment_details\":{\"method_id\":\"bacs\",\"method_title\":\"Direct Bank Transfer\",\"paid\":true},\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"},\"note\":\"\",\"customer_ip\":\"127.0.0.1\",\"customer_user_agent\":\"curl/7.47.0\",\"customer_id\":0,\"view_order_url\":\"http://example.com/my-account/view-order/118\",\"line_items\":[{\"id\":8,\"subtotal\":\"4.00\",\"subtotal_tax\":\"0.00\",\"total\":\"4.00\",\"total_tax\":\"0.00\",\"price\":\"2.00\",\"quantity\":2,\"tax_class\":null,\"name\":\"Woo Single #2\",\"product_id\":99,\"sku\":\"12345\",\"meta\":[]}],\"shipping_lines\":[{\"id\":9,\"method_id\":\"flat_rate\",\"method_title\":\"Flat Rate\",\"total\":\"10.00\"}],\"tax_lines\":[],\"fee_lines\":[],\"coupon_lines\":[],\"is_vat_exempt\":false,\"customer\":{\"id\":0,\"email\":\"john.doe@claudiosmweb.com\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"billing_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\",\"email\":\"john.doe@claudiosmweb.com\",\"phone\":\"(555) 555-5555\"},\"shipping_address\":{\"first_name\":\"John\",\"last_name\":\"Doe\",\"company\":\"\",\"address_1\":\"969 Market\",\"address_2\":\"\",\"city\":\"San Francisco\",\"state\":\"CA\",\"postcode\":\"94103\",\"country\":\"US\"}}}}", "response_code": "200", "response_message": "OK", "response_headers": { "connection": "close", "server": "gunicorn/19.3.0", "date": "Tue, 16 May 2016 03:29:20 GMT", "content-type": "text/html; charset=utf-8", "content-length": "2", "sponsored-by": "https://www.runscope.com", "via": "1.1 vegur" }, "response_body": "ok", "date_created": "2016-05-16T06:29:19", "date_created_gmt": "2016-05-16T03:29:19", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142/deliveries/53" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142/deliveries" } ], "up": [ { "href": "https://example.com/wp-json/wc/v2/webhooks/142" } ] } } ] ``` --- ## Index *Source: apis/rest-api/v3/api-reference.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Index By default, the API provides information about all available endpoints on the site. Authentication is not required to access the API index. ```http GET /wp-json/wc/v3 ``` ```shell curl https://example.com/wp-json/wc/v3 ``` ```javascript WooCommerce.get( '' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('')); ?> ``` ```python print(wcapi.get("").json()) ``` ```ruby woocommerce.get("").parsed_response ``` ```json { "namespace": "wc/v3", "routes": { "/wc/v3": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "namespace": { "required": false, "default": "wc/v3" }, "context": { "required": false, "default": "view" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3" } }, "/wc/v3/coupons": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "after": { "required": false, "description": "Limit response to resources published after a given ISO8601 compliant date.", "type": "string" }, "before": { "required": false, "description": "Limit response to resources published before a given ISO8601 compliant date.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific IDs.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific ids.", "type": "array", "items": { "type": "integer" } }, "offset": { "required": false, "description": "Offset the result set by a specific number of items.", "type": "integer" }, "order": { "required": false, "default": "desc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "date", "enum": [ "date", "id", "include", "title", "slug" ], "description": "Sort collection by object attribute.", "type": "string" }, "code": { "required": false, "description": "Limit result set to resources with a specific code.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "code": { "required": true, "description": "Coupon code.", "type": "string" }, "amount": { "required": false, "description": "The amount of discount. Should always be numeric, even if setting a percentage.", "type": "string" }, "discount_type": { "required": false, "default": "fixed_cart", "enum": [ "percent", "fixed_cart", "fixed_product" ], "description": "Determines the type of discount that will be applied.", "type": "string" }, "description": { "required": false, "description": "Coupon description.", "type": "string" }, "date_expires": { "required": false, "description": "The date the coupon expires, in the site's timezone.", "type": "string" }, "date_expires_gmt": { "required": false, "description": "The date the coupon expires, as GMT.", "type": "string" }, "individual_use": { "required": false, "default": false, "description": "If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.", "type": "boolean" }, "product_ids": { "required": false, "description": "List of product IDs the coupon can be used on.", "type": "array", "items": { "type": "integer" } }, "excluded_product_ids": { "required": false, "description": "List of product IDs the coupon cannot be used on.", "type": "array", "items": { "type": "integer" } }, "usage_limit": { "required": false, "description": "How many times the coupon can be used in total.", "type": "integer" }, "usage_limit_per_user": { "required": false, "description": "How many times the coupon can be used per customer.", "type": "integer" }, "limit_usage_to_x_items": { "required": false, "description": "Max number of items in the cart the coupon can be applied to.", "type": "integer" }, "free_shipping": { "required": false, "default": false, "description": "If true and if the free shipping method requires a coupon, this coupon will enable free shipping.", "type": "boolean" }, "product_categories": { "required": false, "description": "List of category IDs the coupon applies to.", "type": "array", "items": { "type": "integer" } }, "excluded_product_categories": { "required": false, "description": "List of category IDs the coupon does not apply to.", "type": "array", "items": { "type": "integer" } }, "exclude_sale_items": { "required": false, "default": false, "description": "If true, this coupon will not be applied to items that have sale prices.", "type": "boolean" }, "minimum_amount": { "required": false, "description": "Minimum order amount that needs to be in the cart before coupon applies.", "type": "string" }, "maximum_amount": { "required": false, "description": "Maximum order amount allowed when using the coupon.", "type": "string" }, "email_restrictions": { "required": false, "description": "List of email addresses that can use this coupon.", "type": "array", "items": { "type": "string" } }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/coupons" } }, "/wc/v3/coupons/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "code": { "required": false, "description": "Coupon code.", "type": "string" }, "amount": { "required": false, "description": "The amount of discount. Should always be numeric, even if setting a percentage.", "type": "string" }, "discount_type": { "required": false, "enum": [ "percent", "fixed_cart", "fixed_product" ], "description": "Determines the type of discount that will be applied.", "type": "string" }, "description": { "required": false, "description": "Coupon description.", "type": "string" }, "date_expires": { "required": false, "description": "The date the coupon expires, in the site's timezone.", "type": "string" }, "date_expires_gmt": { "required": false, "description": "The date the coupon expires, as GMT.", "type": "string" }, "individual_use": { "required": false, "description": "If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.", "type": "boolean" }, "product_ids": { "required": false, "description": "List of product IDs the coupon can be used on.", "type": "array", "items": { "type": "integer" } }, "excluded_product_ids": { "required": false, "description": "List of product IDs the coupon cannot be used on.", "type": "array", "items": { "type": "integer" } }, "usage_limit": { "required": false, "description": "How many times the coupon can be used in total.", "type": "integer" }, "usage_limit_per_user": { "required": false, "description": "How many times the coupon can be used per customer.", "type": "integer" }, "limit_usage_to_x_items": { "required": false, "description": "Max number of items in the cart the coupon can be applied to.", "type": "integer" }, "free_shipping": { "required": false, "description": "If true and if the free shipping method requires a coupon, this coupon will enable free shipping.", "type": "boolean" }, "product_categories": { "required": false, "description": "List of category IDs the coupon applies to.", "type": "array", "items": { "type": "integer" } }, "excluded_product_categories": { "required": false, "description": "List of category IDs the coupon does not apply to.", "type": "array", "items": { "type": "integer" } }, "exclude_sale_items": { "required": false, "description": "If true, this coupon will not be applied to items that have sale prices.", "type": "boolean" }, "minimum_amount": { "required": false, "description": "Minimum order amount that needs to be in the cart before coupon applies.", "type": "string" }, "maximum_amount": { "required": false, "description": "Maximum order amount allowed when using the coupon.", "type": "string" }, "email_restrictions": { "required": false, "description": "List of email addresses that can use this coupon.", "type": "array", "items": { "type": "string" } }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Whether to bypass trash and force deletion.", "type": "boolean" } } } ] }, "/wc/v3/coupons/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "code": { "required": false, "description": "Coupon code.", "type": "string" }, "amount": { "required": false, "description": "The amount of discount. Should always be numeric, even if setting a percentage.", "type": "string" }, "discount_type": { "required": false, "enum": [ "percent", "fixed_cart", "fixed_product" ], "description": "Determines the type of discount that will be applied.", "type": "string" }, "description": { "required": false, "description": "Coupon description.", "type": "string" }, "date_expires": { "required": false, "description": "The date the coupon expires, in the site's timezone.", "type": "string" }, "date_expires_gmt": { "required": false, "description": "The date the coupon expires, as GMT.", "type": "string" }, "individual_use": { "required": false, "description": "If true, the coupon can only be used individually. Other applied coupons will be removed from the cart.", "type": "boolean" }, "product_ids": { "required": false, "description": "List of product IDs the coupon can be used on.", "type": "array", "items": { "type": "integer" } }, "excluded_product_ids": { "required": false, "description": "List of product IDs the coupon cannot be used on.", "type": "array", "items": { "type": "integer" } }, "usage_limit": { "required": false, "description": "How many times the coupon can be used in total.", "type": "integer" }, "usage_limit_per_user": { "required": false, "description": "How many times the coupon can be used per customer.", "type": "integer" }, "limit_usage_to_x_items": { "required": false, "description": "Max number of items in the cart the coupon can be applied to.", "type": "integer" }, "free_shipping": { "required": false, "description": "If true and if the free shipping method requires a coupon, this coupon will enable free shipping.", "type": "boolean" }, "product_categories": { "required": false, "description": "List of category IDs the coupon applies to.", "type": "array", "items": { "type": "integer" } }, "excluded_product_categories": { "required": false, "description": "List of category IDs the coupon does not apply to.", "type": "array", "items": { "type": "integer" } }, "exclude_sale_items": { "required": false, "description": "If true, this coupon will not be applied to items that have sale prices.", "type": "boolean" }, "minimum_amount": { "required": false, "description": "Minimum order amount that needs to be in the cart before coupon applies.", "type": "string" }, "maximum_amount": { "required": false, "description": "Maximum order amount allowed when using the coupon.", "type": "string" }, "email_restrictions": { "required": false, "description": "List of email addresses that can use this coupon.", "type": "array", "items": { "type": "string" } }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/coupons/batch" } }, "/wc/v3/customers/(?P[\\d]+)/downloads": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "customer_id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } } ] }, "/wc/v3/customers": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific IDs.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific IDs.", "type": "array", "items": { "type": "integer" } }, "offset": { "required": false, "description": "Offset the result set by a specific number of items.", "type": "integer" }, "order": { "required": false, "default": "asc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "name", "enum": [ "id", "include", "name", "registered_date" ], "description": "Sort collection by object attribute.", "type": "string" }, "email": { "required": false, "description": "Limit result set to resources with a specific email.", "type": "string" }, "role": { "required": false, "default": "customer", "enum": [ "all", "administrator", "editor", "author", "contributor", "subscriber", "customer", "shop_manager" ], "description": "Limit result set to resources with a specific role.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "email": { "required": true, "description": "New user email address.", "type": "string" }, "first_name": { "required": false, "description": "Customer first name.", "type": "string" }, "last_name": { "required": false, "description": "Customer last name.", "type": "string" }, "username": { "required": false, "description": "New user username.", "type": "string" }, "password": { "required": false, "description": "New user password.", "type": "string" }, "billing": { "required": false, "description": "List of billing address data.", "type": "object" }, "shipping": { "required": false, "description": "List of shipping address data.", "type": "object" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/customers" } }, "/wc/v3/customers/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "email": { "required": false, "description": "The email address for the customer.", "type": "string" }, "first_name": { "required": false, "description": "Customer first name.", "type": "string" }, "last_name": { "required": false, "description": "Customer last name.", "type": "string" }, "username": { "required": false, "description": "Customer login name.", "type": "string" }, "password": { "required": false, "description": "Customer password.", "type": "string" }, "billing": { "required": false, "description": "List of billing address data.", "type": "object" }, "shipping": { "required": false, "description": "List of shipping address data.", "type": "object" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Required to be true, as resource does not support trashing.", "type": "boolean" }, "reassign": { "required": false, "default": 0, "description": "ID to reassign posts to.", "type": "integer" } } } ] }, "/wc/v3/customers/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "email": { "required": false, "description": "The email address for the customer.", "type": "string" }, "first_name": { "required": false, "description": "Customer first name.", "type": "string" }, "last_name": { "required": false, "description": "Customer last name.", "type": "string" }, "username": { "required": false, "description": "Customer login name.", "type": "string" }, "password": { "required": false, "description": "Customer password.", "type": "string" }, "billing": { "required": false, "description": "List of billing address data.", "type": "object" }, "shipping": { "required": false, "description": "List of shipping address data.", "type": "object" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/customers/batch" } }, "/wc/v3/orders/(?P[\\d]+)/notes": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "order_id": { "required": false, "description": "The order ID.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "type": { "required": false, "default": "any", "enum": [ "any", "customer", "internal" ], "description": "Limit result to customers or internal notes.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "order_id": { "required": false, "description": "The order ID.", "type": "integer" }, "note": { "required": true, "description": "Order note content.", "type": "string" }, "customer_note": { "required": false, "default": false, "description": "If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only.", "type": "boolean" } } } ] }, "/wc/v3/orders/(?P[\\d]+)/notes/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "order_id": { "required": false, "description": "The order ID.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "order_id": { "required": false, "description": "The order ID.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Required to be true, as resource does not support trashing.", "type": "boolean" } } } ] }, "/wc/v3/orders/(?P[\\d]+)/refunds": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "order_id": { "required": false, "description": "The order ID.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "after": { "required": false, "description": "Limit response to resources published after a given ISO8601 compliant date.", "type": "string" }, "before": { "required": false, "description": "Limit response to resources published before a given ISO8601 compliant date.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific IDs.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific ids.", "type": "array", "items": { "type": "integer" } }, "offset": { "required": false, "description": "Offset the result set by a specific number of items.", "type": "integer" }, "order": { "required": false, "default": "desc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "date", "enum": [ "date", "id", "include", "title", "slug" ], "description": "Sort collection by object attribute.", "type": "string" }, "parent": { "required": false, "default": [], "description": "Limit result set to those of particular parent IDs.", "type": "array", "items": { "type": "integer" } }, "parent_exclude": { "required": false, "default": [], "description": "Limit result set to all items except those of a particular parent ID.", "type": "array", "items": { "type": "integer" } }, "dp": { "required": false, "default": 2, "description": "Number of decimal points to use in each resource.", "type": "integer" } } }, { "methods": [ "POST" ], "args": { "order_id": { "required": false, "description": "The order ID.", "type": "integer" }, "amount": { "required": false, "description": "Refund amount.", "type": "string" }, "reason": { "required": false, "description": "Reason for refund.", "type": "string" }, "refunded_by": { "required": false, "description": "User ID of user who created the refund.", "type": "integer" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } }, "line_items": { "required": false, "description": "Line items data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "Product name.", "type": "string", "context": [ "view", "edit" ] }, "product_id": { "description": "Product ID.", "type": "integer", "context": [ "view", "edit" ] }, "variation_id": { "description": "Variation ID, if applicable.", "type": "integer", "context": [ "view", "edit" ] }, "quantity": { "description": "Quantity ordered.", "type": "integer", "context": [ "view", "edit" ] }, "tax_class": { "description": "Tax class of product.", "type": "integer", "context": [ "view", "edit" ] }, "subtotal": { "description": "Line subtotal (before discounts).", "type": "string", "context": [ "view", "edit" ] }, "subtotal_tax": { "description": "Line subtotal tax (before discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "total": { "description": "Line total (after discounts).", "type": "string", "context": [ "view", "edit" ] }, "total_tax": { "description": "Line total tax (after discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "taxes": { "description": "Line taxes.", "type": "array", "context": [ "view", "edit" ], "readonly": true, "items": { "type": "object", "properties": { "id": { "description": "Tax rate ID.", "type": "integer", "context": [ "view", "edit" ] }, "total": { "description": "Tax total.", "type": "string", "context": [ "view", "edit" ] }, "subtotal": { "description": "Tax subtotal.", "type": "string", "context": [ "view", "edit" ] } } } }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } }, "sku": { "description": "Product SKU.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "price": { "description": "Product price.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "api_refund": { "required": false, "default": true, "description": "When true, the payment gateway API is used to generate the refund.", "type": "boolean" } } } ] }, "/wc/v3/orders/(?P[\\d]+)/refunds/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "order_id": { "required": false, "description": "The order ID.", "type": "integer" }, "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "DELETE" ], "args": { "order_id": { "required": false, "description": "The order ID.", "type": "integer" }, "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": true, "description": "Required to be true, as resource does not support trashing.", "type": "boolean" } } } ] }, "/wc/v3/orders": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "after": { "required": false, "description": "Limit response to resources published after a given ISO8601 compliant date.", "type": "string" }, "before": { "required": false, "description": "Limit response to resources published before a given ISO8601 compliant date.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific IDs.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific ids.", "type": "array", "items": { "type": "integer" } }, "offset": { "required": false, "description": "Offset the result set by a specific number of items.", "type": "integer" }, "order": { "required": false, "default": "desc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "date", "enum": [ "date", "id", "include", "title", "slug" ], "description": "Sort collection by object attribute.", "type": "string" }, "parent": { "required": false, "default": [], "description": "Limit result set to those of particular parent IDs.", "type": "array", "items": { "type": "integer" } }, "parent_exclude": { "required": false, "default": [], "description": "Limit result set to all items except those of a particular parent ID.", "type": "array", "items": { "type": "integer" } }, "status": { "required": false, "default": "any", "enum": [ "any", "pending", "processing", "on-hold", "completed", "cancelled", "refunded", "failed" ], "description": "Limit result set to orders assigned a specific status.", "type": "string" }, "customer": { "required": false, "description": "Limit result set to orders assigned a specific customer.", "type": "integer" }, "product": { "required": false, "description": "Limit result set to orders assigned a specific product.", "type": "integer" }, "dp": { "required": false, "default": 2, "description": "Number of decimal points to use in each resource.", "type": "integer" } } }, { "methods": [ "POST" ], "args": { "parent_id": { "required": false, "description": "Parent order ID.", "type": "integer" }, "status": { "required": false, "default": "pending", "enum": [ "pending", "processing", "on-hold", "completed", "cancelled", "refunded", "failed" ], "description": "Order status.", "type": "string" }, "currency": { "required": false, "default": "USD", "enum": [ "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTC", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "IRT", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PRB", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD", "XOF", "XPF", "YER", "ZAR", "ZMW" ], "description": "Currency the order was created with, in ISO format.", "type": "string" }, "customer_id": { "required": false, "default": 0, "description": "User ID who owns the order. 0 for guests.", "type": "integer" }, "customer_note": { "required": false, "description": "Note left by customer during checkout.", "type": "string" }, "billing": { "required": false, "description": "Billing address.", "type": "object" }, "shipping": { "required": false, "description": "Shipping address.", "type": "object" }, "payment_method": { "required": false, "description": "Payment method ID.", "type": "string" }, "payment_method_title": { "required": false, "description": "Payment method title.", "type": "string" }, "transaction_id": { "required": false, "description": "Unique transaction ID.", "type": "string" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } }, "line_items": { "required": false, "description": "Line items data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "Product name.", "type": "string", "context": [ "view", "edit" ] }, "product_id": { "description": "Product ID.", "type": "integer", "context": [ "view", "edit" ] }, "variation_id": { "description": "Variation ID, if applicable.", "type": "integer", "context": [ "view", "edit" ] }, "quantity": { "description": "Quantity ordered.", "type": "integer", "context": [ "view", "edit" ] }, "tax_class": { "description": "Tax class of product.", "type": "integer", "context": [ "view", "edit" ] }, "subtotal": { "description": "Line subtotal (before discounts).", "type": "string", "context": [ "view", "edit" ] }, "subtotal_tax": { "description": "Line subtotal tax (before discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "total": { "description": "Line total (after discounts).", "type": "string", "context": [ "view", "edit" ] }, "total_tax": { "description": "Line total tax (after discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "taxes": { "description": "Line taxes.", "type": "array", "context": [ "view", "edit" ], "readonly": true, "items": { "type": "object", "properties": { "id": { "description": "Tax rate ID.", "type": "integer", "context": [ "view", "edit" ] }, "total": { "description": "Tax total.", "type": "string", "context": [ "view", "edit" ] }, "subtotal": { "description": "Tax subtotal.", "type": "string", "context": [ "view", "edit" ] } } } }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } }, "sku": { "description": "Product SKU.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "price": { "description": "Product price.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "shipping_lines": { "required": false, "description": "Shipping lines data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "method_title": { "description": "Shipping method name.", "type": "string", "context": [ "view", "edit" ] }, "method_id": { "description": "Shipping method ID.", "type": "string", "context": [ "view", "edit" ] }, "total": { "description": "Line total (after discounts).", "type": "string", "context": [ "view", "edit" ] }, "total_tax": { "description": "Line total tax (after discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "taxes": { "description": "Line taxes.", "type": "array", "context": [ "view", "edit" ], "readonly": true, "items": { "type": "object", "properties": { "id": { "description": "Tax rate ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "total": { "description": "Tax total.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } }, "fee_lines": { "required": false, "description": "Fee lines data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "Fee name.", "type": "string", "context": [ "view", "edit" ] }, "tax_class": { "description": "Tax class of fee.", "type": "string", "context": [ "view", "edit" ] }, "tax_status": { "description": "Tax status of fee.", "type": "string", "context": [ "view", "edit" ], "enum": [ "taxable", "none" ] }, "total": { "description": "Line total (after discounts).", "type": "string", "context": [ "view", "edit" ] }, "total_tax": { "description": "Line total tax (after discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "taxes": { "description": "Line taxes.", "type": "array", "context": [ "view", "edit" ], "readonly": true, "items": { "type": "object", "properties": { "id": { "description": "Tax rate ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "total": { "description": "Tax total.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "subtotal": { "description": "Tax subtotal.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } }, "coupon_lines": { "required": false, "description": "Coupons line data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "code": { "description": "Coupon code.", "type": "string", "context": [ "view", "edit" ] }, "discount": { "description": "Discount total.", "type": "string", "context": [ "view", "edit" ] }, "discount_tax": { "description": "Discount total tax.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } }, "set_paid": { "required": false, "default": false, "description": "Define if the order is paid. It will set the status to processing and reduce stock items.", "type": "boolean" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/orders" } }, "/wc/v3/orders/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "parent_id": { "required": false, "description": "Parent order ID.", "type": "integer" }, "status": { "required": false, "enum": [ "pending", "processing", "on-hold", "completed", "cancelled", "refunded", "failed" ], "description": "Order status.", "type": "string" }, "currency": { "required": false, "enum": [ "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTC", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "IRT", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PRB", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD", "XOF", "XPF", "YER", "ZAR", "ZMW" ], "description": "Currency the order was created with, in ISO format.", "type": "string" }, "customer_id": { "required": false, "description": "User ID who owns the order. 0 for guests.", "type": "integer" }, "customer_note": { "required": false, "description": "Note left by customer during checkout.", "type": "string" }, "billing": { "required": false, "description": "Billing address.", "type": "object" }, "shipping": { "required": false, "description": "Shipping address.", "type": "object" }, "payment_method": { "required": false, "description": "Payment method ID.", "type": "string" }, "payment_method_title": { "required": false, "description": "Payment method title.", "type": "string" }, "transaction_id": { "required": false, "description": "Unique transaction ID.", "type": "string" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } }, "line_items": { "required": false, "description": "Line items data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "Product name.", "type": "string", "context": [ "view", "edit" ] }, "product_id": { "description": "Product ID.", "type": "integer", "context": [ "view", "edit" ] }, "variation_id": { "description": "Variation ID, if applicable.", "type": "integer", "context": [ "view", "edit" ] }, "quantity": { "description": "Quantity ordered.", "type": "integer", "context": [ "view", "edit" ] }, "tax_class": { "description": "Tax class of product.", "type": "integer", "context": [ "view", "edit" ] }, "subtotal": { "description": "Line subtotal (before discounts).", "type": "string", "context": [ "view", "edit" ] }, "subtotal_tax": { "description": "Line subtotal tax (before discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "total": { "description": "Line total (after discounts).", "type": "string", "context": [ "view", "edit" ] }, "total_tax": { "description": "Line total tax (after discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "taxes": { "description": "Line taxes.", "type": "array", "context": [ "view", "edit" ], "readonly": true, "items": { "type": "object", "properties": { "id": { "description": "Tax rate ID.", "type": "integer", "context": [ "view", "edit" ] }, "total": { "description": "Tax total.", "type": "string", "context": [ "view", "edit" ] }, "subtotal": { "description": "Tax subtotal.", "type": "string", "context": [ "view", "edit" ] } } } }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } }, "sku": { "description": "Product SKU.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "price": { "description": "Product price.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "shipping_lines": { "required": false, "description": "Shipping lines data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "method_title": { "description": "Shipping method name.", "type": "string", "context": [ "view", "edit" ] }, "method_id": { "description": "Shipping method ID.", "type": "string", "context": [ "view", "edit" ] }, "total": { "description": "Line total (after discounts).", "type": "string", "context": [ "view", "edit" ] }, "total_tax": { "description": "Line total tax (after discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "taxes": { "description": "Line taxes.", "type": "array", "context": [ "view", "edit" ], "readonly": true, "items": { "type": "object", "properties": { "id": { "description": "Tax rate ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "total": { "description": "Tax total.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } }, "fee_lines": { "required": false, "description": "Fee lines data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "Fee name.", "type": "string", "context": [ "view", "edit" ] }, "tax_class": { "description": "Tax class of fee.", "type": "string", "context": [ "view", "edit" ] }, "tax_status": { "description": "Tax status of fee.", "type": "string", "context": [ "view", "edit" ], "enum": [ "taxable", "none" ] }, "total": { "description": "Line total (after discounts).", "type": "string", "context": [ "view", "edit" ] }, "total_tax": { "description": "Line total tax (after discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "taxes": { "description": "Line taxes.", "type": "array", "context": [ "view", "edit" ], "readonly": true, "items": { "type": "object", "properties": { "id": { "description": "Tax rate ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "total": { "description": "Tax total.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "subtotal": { "description": "Tax subtotal.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } }, "coupon_lines": { "required": false, "description": "Coupons line data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "code": { "description": "Coupon code.", "type": "string", "context": [ "view", "edit" ] }, "discount": { "description": "Discount total.", "type": "string", "context": [ "view", "edit" ] }, "discount_tax": { "description": "Discount total tax.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } }, "set_paid": { "required": false, "description": "Define if the order is paid. It will set the status to processing and reduce stock items.", "type": "boolean" } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Whether to bypass trash and force deletion.", "type": "boolean" } } } ] }, "/wc/v3/orders/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "parent_id": { "required": false, "description": "Parent order ID.", "type": "integer" }, "status": { "required": false, "enum": [ "pending", "processing", "on-hold", "completed", "cancelled", "refunded", "failed" ], "description": "Order status.", "type": "string" }, "currency": { "required": false, "enum": [ "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTC", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "IRT", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PRB", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD", "XOF", "XPF", "YER", "ZAR", "ZMW" ], "description": "Currency the order was created with, in ISO format.", "type": "string" }, "customer_id": { "required": false, "description": "User ID who owns the order. 0 for guests.", "type": "integer" }, "customer_note": { "required": false, "description": "Note left by customer during checkout.", "type": "string" }, "billing": { "required": false, "description": "Billing address.", "type": "object" }, "shipping": { "required": false, "description": "Shipping address.", "type": "object" }, "payment_method": { "required": false, "description": "Payment method ID.", "type": "string" }, "payment_method_title": { "required": false, "description": "Payment method title.", "type": "string" }, "transaction_id": { "required": false, "description": "Unique transaction ID.", "type": "string" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } }, "line_items": { "required": false, "description": "Line items data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "Product name.", "type": "string", "context": [ "view", "edit" ] }, "product_id": { "description": "Product ID.", "type": "integer", "context": [ "view", "edit" ] }, "variation_id": { "description": "Variation ID, if applicable.", "type": "integer", "context": [ "view", "edit" ] }, "quantity": { "description": "Quantity ordered.", "type": "integer", "context": [ "view", "edit" ] }, "tax_class": { "description": "Tax class of product.", "type": "integer", "context": [ "view", "edit" ] }, "subtotal": { "description": "Line subtotal (before discounts).", "type": "string", "context": [ "view", "edit" ] }, "subtotal_tax": { "description": "Line subtotal tax (before discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "total": { "description": "Line total (after discounts).", "type": "string", "context": [ "view", "edit" ] }, "total_tax": { "description": "Line total tax (after discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "taxes": { "description": "Line taxes.", "type": "array", "context": [ "view", "edit" ], "readonly": true, "items": { "type": "object", "properties": { "id": { "description": "Tax rate ID.", "type": "integer", "context": [ "view", "edit" ] }, "total": { "description": "Tax total.", "type": "string", "context": [ "view", "edit" ] }, "subtotal": { "description": "Tax subtotal.", "type": "string", "context": [ "view", "edit" ] } } } }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } }, "sku": { "description": "Product SKU.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "price": { "description": "Product price.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "shipping_lines": { "required": false, "description": "Shipping lines data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "method_title": { "description": "Shipping method name.", "type": "string", "context": [ "view", "edit" ] }, "method_id": { "description": "Shipping method ID.", "type": "string", "context": [ "view", "edit" ] }, "total": { "description": "Line total (after discounts).", "type": "string", "context": [ "view", "edit" ] }, "total_tax": { "description": "Line total tax (after discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "taxes": { "description": "Line taxes.", "type": "array", "context": [ "view", "edit" ], "readonly": true, "items": { "type": "object", "properties": { "id": { "description": "Tax rate ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "total": { "description": "Tax total.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } }, "fee_lines": { "required": false, "description": "Fee lines data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "Fee name.", "type": "string", "context": [ "view", "edit" ] }, "tax_class": { "description": "Tax class of fee.", "type": "string", "context": [ "view", "edit" ] }, "tax_status": { "description": "Tax status of fee.", "type": "string", "context": [ "view", "edit" ], "enum": [ "taxable", "none" ] }, "total": { "description": "Line total (after discounts).", "type": "string", "context": [ "view", "edit" ] }, "total_tax": { "description": "Line total tax (after discounts).", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "taxes": { "description": "Line taxes.", "type": "array", "context": [ "view", "edit" ], "readonly": true, "items": { "type": "object", "properties": { "id": { "description": "Tax rate ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "total": { "description": "Tax total.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "subtotal": { "description": "Tax subtotal.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } }, "coupon_lines": { "required": false, "description": "Coupons line data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Item ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "code": { "description": "Coupon code.", "type": "string", "context": [ "view", "edit" ] }, "discount": { "description": "Discount total.", "type": "string", "context": [ "view", "edit" ] }, "discount_tax": { "description": "Discount total tax.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "meta_data": { "description": "Meta data.", "type": "array", "context": [ "view", "edit" ], "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } }, "set_paid": { "required": false, "description": "Define if the order is paid. It will set the status to processing and reduce stock items.", "type": "boolean" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/orders/batch" } }, "/wc/v3/products/attributes/(?P[\\d]+)/terms": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "attribute_id": { "required": false, "description": "Unique identifier for the attribute of the terms.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific ids.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific ids.", "type": "array", "items": { "type": "integer" } }, "order": { "required": false, "default": "asc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "name", "enum": [ "id", "include", "name", "slug", "term_group", "description", "count" ], "description": "Sort collection by resource attribute.", "type": "string" }, "hide_empty": { "required": false, "default": false, "description": "Whether to hide resources not assigned to any products.", "type": "boolean" }, "parent": { "required": false, "description": "Limit result set to resources assigned to a specific parent.", "type": "integer" }, "product": { "required": false, "description": "Limit result set to resources assigned to a specific product.", "type": "integer" }, "slug": { "required": false, "description": "Limit result set to resources with a specific slug.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "attribute_id": { "required": false, "description": "Unique identifier for the attribute of the terms.", "type": "integer" }, "name": { "required": true, "description": "Name for the resource.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" }, "menu_order": { "required": false, "description": "Menu order, used to custom sort the resource.", "type": "integer" } } } ] }, "/wc/v3/products/attributes/(?P[\\d]+)/terms/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "attribute_id": { "required": false, "description": "Unique identifier for the attribute of the terms.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "attribute_id": { "required": false, "description": "Unique identifier for the attribute of the terms.", "type": "integer" }, "name": { "required": false, "description": "Term name.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" }, "menu_order": { "required": false, "description": "Menu order, used to custom sort the resource.", "type": "integer" } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "attribute_id": { "required": false, "description": "Unique identifier for the attribute of the terms.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Required to be true, as resource does not support trashing.", "type": "boolean" } } } ] }, "/wc/v3/products/attributes/(?P[\\d]+)/terms/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "attribute_id": { "required": false, "description": "Unique identifier for the attribute of the terms.", "type": "integer" }, "name": { "required": false, "description": "Term name.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" }, "menu_order": { "required": false, "description": "Menu order, used to custom sort the resource.", "type": "integer" } } } ] }, "/wc/v3/products/attributes": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "name": { "required": true, "description": "Name for the resource.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "type": { "required": false, "default": "select", "enum": [ "select", "text" ], "description": "Type of attribute.", "type": "string" }, "order_by": { "required": false, "default": "menu_order", "enum": [ "menu_order", "name", "name_num", "id" ], "description": "Default sort order.", "type": "string" }, "has_archives": { "required": false, "default": false, "description": "Enable/Disable attribute archives.", "type": "boolean" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/products/attributes" } }, "/wc/v3/products/attributes/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "name": { "required": false, "description": "Attribute name.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "type": { "required": false, "enum": [ "select", "text" ], "description": "Type of attribute.", "type": "string" }, "order_by": { "required": false, "enum": [ "menu_order", "name", "name_num", "id" ], "description": "Default sort order.", "type": "string" }, "has_archives": { "required": false, "description": "Enable/Disable attribute archives.", "type": "boolean" } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": true, "description": "Required to be true, as resource does not support trashing.", "type": "boolean" } } } ] }, "/wc/v3/products/attributes/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "name": { "required": false, "description": "Attribute name.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "type": { "required": false, "enum": [ "select", "text" ], "description": "Type of attribute.", "type": "string" }, "order_by": { "required": false, "enum": [ "menu_order", "name", "name_num", "id" ], "description": "Default sort order.", "type": "string" }, "has_archives": { "required": false, "description": "Enable/Disable attribute archives.", "type": "boolean" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/products/attributes/batch" } }, "/wc/v3/products/categories": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific ids.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific ids.", "type": "array", "items": { "type": "integer" } }, "order": { "required": false, "default": "asc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "name", "enum": [ "id", "include", "name", "slug", "term_group", "description", "count" ], "description": "Sort collection by resource attribute.", "type": "string" }, "hide_empty": { "required": false, "default": false, "description": "Whether to hide resources not assigned to any products.", "type": "boolean" }, "parent": { "required": false, "description": "Limit result set to resources assigned to a specific parent.", "type": "integer" }, "product": { "required": false, "description": "Limit result set to resources assigned to a specific product.", "type": "integer" }, "slug": { "required": false, "description": "Limit result set to resources with a specific slug.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "name": { "required": true, "description": "Name for the resource.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "parent": { "required": false, "description": "The ID for the parent of the resource.", "type": "integer" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" }, "display": { "required": false, "default": "default", "enum": [ "default", "products", "subcategories", "both" ], "description": "Category archive display type.", "type": "string" }, "image": { "required": false, "description": "Image data.", "type": "object" }, "menu_order": { "required": false, "description": "Menu order, used to custom sort the resource.", "type": "integer" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/products/categories" } }, "/wc/v3/products/categories/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "name": { "required": false, "description": "Category name.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "parent": { "required": false, "description": "The ID for the parent of the resource.", "type": "integer" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" }, "display": { "required": false, "enum": [ "default", "products", "subcategories", "both" ], "description": "Category archive display type.", "type": "string" }, "image": { "required": false, "description": "Image data.", "type": "object" }, "menu_order": { "required": false, "description": "Menu order, used to custom sort the resource.", "type": "integer" } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Required to be true, as resource does not support trashing.", "type": "boolean" } } } ] }, "/wc/v3/products/categories/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "name": { "required": false, "description": "Category name.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "parent": { "required": false, "description": "The ID for the parent of the resource.", "type": "integer" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" }, "display": { "required": false, "enum": [ "default", "products", "subcategories", "both" ], "description": "Category archive display type.", "type": "string" }, "image": { "required": false, "description": "Image data.", "type": "object" }, "menu_order": { "required": false, "description": "Menu order, used to custom sort the resource.", "type": "integer" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/products/categories/batch" } }, "/wc/v3/products/(?P[\\d]+)/reviews": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "id": { "required": false, "description": "Unique identifier for the variation.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "id": { "required": false, "description": "Unique identifier for the variation.", "type": "integer" }, "review": { "required": true, "description": "Review content.", "type": "string" }, "date_created": { "required": false, "description": "The date the review was created, in the site's timezone.", "type": "date-time" }, "date_created_gmt": { "required": false, "description": "The date the review was created, as GMT.", "type": "date-time" }, "rating": { "required": false, "description": "Review rating (0 to 5).", "type": "integer" }, "name": { "required": true, "description": "Name of the reviewer.", "type": "string" }, "email": { "required": true, "description": "Email of the reviewer.", "type": "string" } } } ] }, "/wc/v3/products/(?P[\\d]+)/reviews/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "review": { "required": false, "description": "The content of the review.", "type": "string" }, "date_created": { "required": false, "description": "The date the review was created, in the site's timezone.", "type": "date-time" }, "date_created_gmt": { "required": false, "description": "The date the review was created, as GMT.", "type": "date-time" }, "rating": { "required": false, "description": "Review rating (0 to 5).", "type": "integer" }, "name": { "required": false, "description": "Reviewer name.", "type": "string" }, "email": { "required": false, "description": "Reviewer email.", "type": "string" } } }, { "methods": [ "DELETE" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Whether to bypass trash and force deletion.", "type": "boolean" } } } ] }, "/wc/v3/products/(?P[\\d]+)/reviews/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "review": { "required": false, "description": "The content of the review.", "type": "string" }, "date_created": { "required": false, "description": "The date the review was created, in the site's timezone.", "type": "date-time" }, "date_created_gmt": { "required": false, "description": "The date the review was created, as GMT.", "type": "date-time" }, "rating": { "required": false, "description": "Review rating (0 to 5).", "type": "integer" }, "name": { "required": false, "description": "Reviewer name.", "type": "string" }, "email": { "required": false, "description": "Reviewer email.", "type": "string" } } } ] }, "/wc/v3/products/shipping_classes": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific ids.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific ids.", "type": "array", "items": { "type": "integer" } }, "offset": { "required": false, "description": "Offset the result set by a specific number of items.", "type": "integer" }, "order": { "required": false, "default": "asc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "name", "enum": [ "id", "include", "name", "slug", "term_group", "description", "count" ], "description": "Sort collection by resource attribute.", "type": "string" }, "hide_empty": { "required": false, "default": false, "description": "Whether to hide resources not assigned to any products.", "type": "boolean" }, "product": { "required": false, "description": "Limit result set to resources assigned to a specific product.", "type": "integer" }, "slug": { "required": false, "description": "Limit result set to resources with a specific slug.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "name": { "required": true, "description": "Name for the resource.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/products/shipping_classes" } }, "/wc/v3/products/shipping_classes/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "name": { "required": false, "description": "Shipping class name.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Required to be true, as resource does not support trashing.", "type": "boolean" } } } ] }, "/wc/v3/products/shipping_classes/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "name": { "required": false, "description": "Shipping class name.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/products/shipping_classes/batch" } }, "/wc/v3/products/tags": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific ids.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific ids.", "type": "array", "items": { "type": "integer" } }, "offset": { "required": false, "description": "Offset the result set by a specific number of items.", "type": "integer" }, "order": { "required": false, "default": "asc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "name", "enum": [ "id", "include", "name", "slug", "term_group", "description", "count" ], "description": "Sort collection by resource attribute.", "type": "string" }, "hide_empty": { "required": false, "default": false, "description": "Whether to hide resources not assigned to any products.", "type": "boolean" }, "product": { "required": false, "description": "Limit result set to resources assigned to a specific product.", "type": "integer" }, "slug": { "required": false, "description": "Limit result set to resources with a specific slug.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "name": { "required": true, "description": "Name for the resource.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/products/tags" } }, "/wc/v3/products/tags/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "name": { "required": false, "description": "Tag name.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Required to be true, as resource does not support trashing.", "type": "boolean" } } } ] }, "/wc/v3/products/tags/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "name": { "required": false, "description": "Tag name.", "type": "string" }, "slug": { "required": false, "description": "An alphanumeric identifier for the resource unique to its type.", "type": "string" }, "description": { "required": false, "description": "HTML description of the resource.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/products/tags/batch" } }, "/wc/v3/products": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "after": { "required": false, "description": "Limit response to resources published after a given ISO8601 compliant date.", "type": "string" }, "before": { "required": false, "description": "Limit response to resources published before a given ISO8601 compliant date.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific IDs.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific ids.", "type": "array", "items": { "type": "integer" } }, "offset": { "required": false, "description": "Offset the result set by a specific number of items.", "type": "integer" }, "order": { "required": false, "default": "desc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "date", "enum": [ "date", "id", "include", "title", "slug", "price", "popularity", "rating" ], "description": "Sort collection by object attribute.", "type": "string" }, "parent": { "required": false, "default": [], "description": "Limit result set to those of particular parent IDs.", "type": "array", "items": { "type": "integer" } }, "parent_exclude": { "required": false, "default": [], "description": "Limit result set to all items except those of a particular parent ID.", "type": "array", "items": { "type": "integer" } }, "slug": { "required": false, "description": "Limit result set to products with a specific slug.", "type": "string" }, "status": { "required": false, "default": "any", "enum": [ "any", "draft", "pending", "private", "publish" ], "description": "Limit result set to products assigned a specific status.", "type": "string" }, "type": { "required": false, "enum": [ "simple", "grouped", "external", "variable" ], "description": "Limit result set to products assigned a specific type.", "type": "string" }, "sku": { "required": false, "description": "Limit result set to products with a specific SKU.", "type": "string" }, "featured": { "required": false, "description": "Limit result set to featured products.", "type": "boolean" }, "category": { "required": false, "description": "Limit result set to products assigned a specific category ID.", "type": "string" }, "tag": { "required": false, "description": "Limit result set to products assigned a specific tag ID.", "type": "string" }, "shipping_class": { "required": false, "description": "Limit result set to products assigned a specific shipping class ID.", "type": "string" }, "attribute": { "required": false, "description": "Limit result set to products with a specific attribute.", "type": "string" }, "attribute_term": { "required": false, "description": "Limit result set to products with a specific attribute term ID (required an assigned attribute).", "type": "string" }, "tax_class": { "required": false, "enum": [ "standard", "reduced-rate", "zero-rate" ], "description": "Limit result set to products with a specific tax class.", "type": "string" }, "in_stock": { "required": false, "description": "Limit result set to products in stock or out of stock.", "type": "boolean" }, "on_sale": { "required": false, "description": "Limit result set to products on sale.", "type": "boolean" }, "min_price": { "required": false, "description": "Limit result set to products based on a minimum price.", "type": "string" }, "max_price": { "required": false, "description": "Limit result set to products based on a maximum price.", "type": "string" }, "image_size": { "required": false, "default": "full", "description": "Use a specific registered image size for the returned image src values. Falls back to the full size if the requested size is not registered.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "name": { "required": false, "description": "Product name.", "type": "string" }, "slug": { "required": false, "description": "Product slug.", "type": "string" }, "type": { "required": false, "default": "simple", "enum": [ "simple", "grouped", "external", "variable" ], "description": "Product type.", "type": "string" }, "status": { "required": false, "default": "publish", "enum": [ "draft", "pending", "private", "publish" ], "description": "Product status (post status).", "type": "string" }, "featured": { "required": false, "default": false, "description": "Featured product.", "type": "boolean" }, "catalog_visibility": { "required": false, "default": "visible", "enum": [ "visible", "catalog", "search", "hidden" ], "description": "Catalog visibility.", "type": "string" }, "description": { "required": false, "description": "Product description.", "type": "string" }, "short_description": { "required": false, "description": "Product short description.", "type": "string" }, "sku": { "required": false, "description": "Unique identifier.", "type": "string" }, "regular_price": { "required": false, "description": "Product regular price.", "type": "string" }, "sale_price": { "required": false, "description": "Product sale price.", "type": "string" }, "date_on_sale_from": { "required": false, "description": "Start date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_from_gmt": { "required": false, "description": "Start date of sale price, as GMT.", "type": "date-time" }, "date_on_sale_to": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_to_gmt": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "virtual": { "required": false, "default": false, "description": "If the product is virtual.", "type": "boolean" }, "downloadable": { "required": false, "default": false, "description": "If the product is downloadable.", "type": "boolean" }, "downloads": { "required": false, "description": "List of downloadable files.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "File ID.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "File name.", "type": "string", "context": [ "view", "edit" ] }, "file": { "description": "File URL.", "type": "string", "context": [ "view", "edit" ] } } } }, "download_limit": { "required": false, "default": -1, "description": "Number of times downloadable files can be downloaded after purchase.", "type": "integer" }, "download_expiry": { "required": false, "default": -1, "description": "Number of days until access to downloadable files expires.", "type": "integer" }, "external_url": { "required": false, "description": "Product external URL. Only for external products.", "type": "string" }, "button_text": { "required": false, "description": "Product external button text. Only for external products.", "type": "string" }, "tax_status": { "required": false, "default": "taxable", "enum": [ "taxable", "shipping", "none" ], "description": "Tax status.", "type": "string" }, "tax_class": { "required": false, "description": "Tax class.", "type": "string" }, "manage_stock": { "required": false, "default": false, "description": "Stock management at product level.", "type": "boolean" }, "stock_quantity": { "required": false, "description": "Stock quantity.", "type": "integer" }, "in_stock": { "required": false, "default": true, "description": "Controls whether or not the product is listed as \"in stock\" or \"out of stock\" on the frontend.", "type": "boolean" }, "backorders": { "required": false, "default": "no", "enum": [ "no", "notify", "yes" ], "description": "If managing stock, this controls if backorders are allowed.", "type": "string" }, "sold_individually": { "required": false, "default": false, "description": "Allow one item to be bought in a single order.", "type": "boolean" }, "weight": { "required": false, "description": "Product weight (kg).", "type": "string" }, "dimensions": { "required": false, "description": "Product dimensions.", "type": "object" }, "shipping_class": { "required": false, "description": "Shipping class slug.", "type": "string" }, "reviews_allowed": { "required": false, "default": true, "description": "Allow reviews.", "type": "boolean" }, "upsell_ids": { "required": false, "description": "List of up-sell products IDs.", "type": "array", "items": { "type": "integer" } }, "cross_sell_ids": { "required": false, "description": "List of cross-sell products IDs.", "type": "array", "items": { "type": "integer" } }, "parent_id": { "required": false, "description": "Product parent ID.", "type": "integer" }, "purchase_note": { "required": false, "description": "Optional note to send the customer after purchase.", "type": "string" }, "categories": { "required": false, "description": "List of categories.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Category ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Category name.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "slug": { "description": "Category slug.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "tags": { "required": false, "description": "List of tags.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Tag ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Tag name.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "slug": { "description": "Tag slug.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "images": { "required": false, "description": "List of images.", "type": "object", "items": { "type": "object", "properties": { "id": { "description": "Image ID.", "type": "integer", "context": [ "view", "edit" ] }, "date_created": { "description": "The date the image was created, in the site's timezone.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "date_created_gmt": { "description": "The date the image was created, as GMT.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "date_modified": { "description": "The date the image was last modified, in the site's timezone.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "date_modified_gmt": { "description": "The date the image was last modified, as GMT.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "src": { "description": "Image URL.", "type": "string", "format": "uri", "context": [ "view", "edit" ] }, "name": { "description": "Image name.", "type": "string", "context": [ "view", "edit" ] }, "alt": { "description": "Image alternative text.", "type": "string", "context": [ "view", "edit" ] }, "position": { "description": "Image position. 0 means that the image is featured.", "type": "integer", "context": [ "view", "edit" ] } } } }, "attributes": { "required": false, "description": "List of attributes.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Attribute ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Attribute name.", "type": "string", "context": [ "view", "edit" ] }, "position": { "description": "Attribute position.", "type": "integer", "context": [ "view", "edit" ] }, "visible": { "description": "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", "type": "boolean", "default": false, "context": [ "view", "edit" ] }, "variation": { "description": "Define if the attribute can be used as variation.", "type": "boolean", "default": false, "context": [ "view", "edit" ] }, "options": { "description": "List of available term names of the attribute.", "type": "array", "context": [ "view", "edit" ] } } } }, "default_attributes": { "required": false, "description": "Defaults variation attributes.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Attribute ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Attribute name.", "type": "string", "context": [ "view", "edit" ] }, "option": { "description": "Selected attribute term name.", "type": "string", "context": [ "view", "edit" ] } } } }, "menu_order": { "required": false, "description": "Menu order, used to custom sort products.", "type": "integer" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/products" } }, "/wc/v3/products/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "image_size": { "required": false, "default": "full", "description": "Use a specific registered image size for the returned image src values. Falls back to the full size if the requested size is not registered.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "name": { "required": false, "description": "Product name.", "type": "string" }, "slug": { "required": false, "description": "Product slug.", "type": "string" }, "type": { "required": false, "enum": [ "simple", "grouped", "external", "variable" ], "description": "Product type.", "type": "string" }, "status": { "required": false, "enum": [ "draft", "pending", "private", "publish" ], "description": "Product status (post status).", "type": "string" }, "featured": { "required": false, "description": "Featured product.", "type": "boolean" }, "catalog_visibility": { "required": false, "enum": [ "visible", "catalog", "search", "hidden" ], "description": "Catalog visibility.", "type": "string" }, "description": { "required": false, "description": "Product description.", "type": "string" }, "short_description": { "required": false, "description": "Product short description.", "type": "string" }, "sku": { "required": false, "description": "Unique identifier.", "type": "string" }, "regular_price": { "required": false, "description": "Product regular price.", "type": "string" }, "sale_price": { "required": false, "description": "Product sale price.", "type": "string" }, "date_on_sale_from": { "required": false, "description": "Start date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_from_gmt": { "required": false, "description": "Start date of sale price, as GMT.", "type": "date-time" }, "date_on_sale_to": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_to_gmt": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "virtual": { "required": false, "description": "If the product is virtual.", "type": "boolean" }, "downloadable": { "required": false, "description": "If the product is downloadable.", "type": "boolean" }, "downloads": { "required": false, "description": "List of downloadable files.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "File ID.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "File name.", "type": "string", "context": [ "view", "edit" ] }, "file": { "description": "File URL.", "type": "string", "context": [ "view", "edit" ] } } } }, "download_limit": { "required": false, "description": "Number of times downloadable files can be downloaded after purchase.", "type": "integer" }, "download_expiry": { "required": false, "description": "Number of days until access to downloadable files expires.", "type": "integer" }, "external_url": { "required": false, "description": "Product external URL. Only for external products.", "type": "string" }, "button_text": { "required": false, "description": "Product external button text. Only for external products.", "type": "string" }, "tax_status": { "required": false, "enum": [ "taxable", "shipping", "none" ], "description": "Tax status.", "type": "string" }, "tax_class": { "required": false, "description": "Tax class.", "type": "string" }, "manage_stock": { "required": false, "description": "Stock management at product level.", "type": "boolean" }, "stock_quantity": { "required": false, "description": "Stock quantity.", "type": "integer" }, "in_stock": { "required": false, "description": "Controls whether or not the product is listed as \"in stock\" or \"out of stock\" on the frontend.", "type": "boolean" }, "backorders": { "required": false, "enum": [ "no", "notify", "yes" ], "description": "If managing stock, this controls if backorders are allowed.", "type": "string" }, "sold_individually": { "required": false, "description": "Allow one item to be bought in a single order.", "type": "boolean" }, "weight": { "required": false, "description": "Product weight (kg).", "type": "string" }, "dimensions": { "required": false, "description": "Product dimensions.", "type": "object" }, "shipping_class": { "required": false, "description": "Shipping class slug.", "type": "string" }, "reviews_allowed": { "required": false, "description": "Allow reviews.", "type": "boolean" }, "upsell_ids": { "required": false, "description": "List of up-sell products IDs.", "type": "array", "items": { "type": "integer" } }, "cross_sell_ids": { "required": false, "description": "List of cross-sell products IDs.", "type": "array", "items": { "type": "integer" } }, "parent_id": { "required": false, "description": "Product parent ID.", "type": "integer" }, "purchase_note": { "required": false, "description": "Optional note to send the customer after purchase.", "type": "string" }, "categories": { "required": false, "description": "List of categories.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Category ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Category name.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "slug": { "description": "Category slug.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "tags": { "required": false, "description": "List of tags.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Tag ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Tag name.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "slug": { "description": "Tag slug.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "images": { "required": false, "description": "List of images.", "type": "object", "items": { "type": "object", "properties": { "id": { "description": "Image ID.", "type": "integer", "context": [ "view", "edit" ] }, "date_created": { "description": "The date the image was created, in the site's timezone.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "date_created_gmt": { "description": "The date the image was created, as GMT.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "date_modified": { "description": "The date the image was last modified, in the site's timezone.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "date_modified_gmt": { "description": "The date the image was last modified, as GMT.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "src": { "description": "Image URL.", "type": "string", "format": "uri", "context": [ "view", "edit" ] }, "name": { "description": "Image name.", "type": "string", "context": [ "view", "edit" ] }, "alt": { "description": "Image alternative text.", "type": "string", "context": [ "view", "edit" ] }, "position": { "description": "Image position. 0 means that the image is featured.", "type": "integer", "context": [ "view", "edit" ] } } } }, "attributes": { "required": false, "description": "List of attributes.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Attribute ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Attribute name.", "type": "string", "context": [ "view", "edit" ] }, "position": { "description": "Attribute position.", "type": "integer", "context": [ "view", "edit" ] }, "visible": { "description": "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", "type": "boolean", "default": false, "context": [ "view", "edit" ] }, "variation": { "description": "Define if the attribute can be used as variation.", "type": "boolean", "default": false, "context": [ "view", "edit" ] }, "options": { "description": "List of available term names of the attribute.", "type": "array", "context": [ "view", "edit" ] } } } }, "default_attributes": { "required": false, "description": "Defaults variation attributes.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Attribute ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Attribute name.", "type": "string", "context": [ "view", "edit" ] }, "option": { "description": "Selected attribute term name.", "type": "string", "context": [ "view", "edit" ] } } } }, "menu_order": { "required": false, "description": "Menu order, used to custom sort products.", "type": "integer" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Whether to bypass trash and force deletion.", "type": "boolean" } } } ] }, "/wc/v3/products/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "name": { "required": false, "description": "Product name.", "type": "string" }, "slug": { "required": false, "description": "Product slug.", "type": "string" }, "type": { "required": false, "enum": [ "simple", "grouped", "external", "variable" ], "description": "Product type.", "type": "string" }, "status": { "required": false, "enum": [ "draft", "pending", "private", "publish" ], "description": "Product status (post status).", "type": "string" }, "featured": { "required": false, "description": "Featured product.", "type": "boolean" }, "catalog_visibility": { "required": false, "enum": [ "visible", "catalog", "search", "hidden" ], "description": "Catalog visibility.", "type": "string" }, "description": { "required": false, "description": "Product description.", "type": "string" }, "short_description": { "required": false, "description": "Product short description.", "type": "string" }, "sku": { "required": false, "description": "Unique identifier.", "type": "string" }, "regular_price": { "required": false, "description": "Product regular price.", "type": "string" }, "sale_price": { "required": false, "description": "Product sale price.", "type": "string" }, "date_on_sale_from": { "required": false, "description": "Start date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_from_gmt": { "required": false, "description": "Start date of sale price, as GMT.", "type": "date-time" }, "date_on_sale_to": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_to_gmt": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "virtual": { "required": false, "description": "If the product is virtual.", "type": "boolean" }, "downloadable": { "required": false, "description": "If the product is downloadable.", "type": "boolean" }, "downloads": { "required": false, "description": "List of downloadable files.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "File ID.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "File name.", "type": "string", "context": [ "view", "edit" ] }, "file": { "description": "File URL.", "type": "string", "context": [ "view", "edit" ] } } } }, "download_limit": { "required": false, "description": "Number of times downloadable files can be downloaded after purchase.", "type": "integer" }, "download_expiry": { "required": false, "description": "Number of days until access to downloadable files expires.", "type": "integer" }, "external_url": { "required": false, "description": "Product external URL. Only for external products.", "type": "string" }, "button_text": { "required": false, "description": "Product external button text. Only for external products.", "type": "string" }, "tax_status": { "required": false, "enum": [ "taxable", "shipping", "none" ], "description": "Tax status.", "type": "string" }, "tax_class": { "required": false, "description": "Tax class.", "type": "string" }, "manage_stock": { "required": false, "description": "Stock management at product level.", "type": "boolean" }, "stock_quantity": { "required": false, "description": "Stock quantity.", "type": "integer" }, "in_stock": { "required": false, "description": "Controls whether or not the product is listed as \"in stock\" or \"out of stock\" on the frontend.", "type": "boolean" }, "backorders": { "required": false, "enum": [ "no", "notify", "yes" ], "description": "If managing stock, this controls if backorders are allowed.", "type": "string" }, "sold_individually": { "required": false, "description": "Allow one item to be bought in a single order.", "type": "boolean" }, "weight": { "required": false, "description": "Product weight (kg).", "type": "string" }, "dimensions": { "required": false, "description": "Product dimensions.", "type": "object" }, "shipping_class": { "required": false, "description": "Shipping class slug.", "type": "string" }, "reviews_allowed": { "required": false, "description": "Allow reviews.", "type": "boolean" }, "upsell_ids": { "required": false, "description": "List of up-sell products IDs.", "type": "array", "items": { "type": "integer" } }, "cross_sell_ids": { "required": false, "description": "List of cross-sell products IDs.", "type": "array", "items": { "type": "integer" } }, "parent_id": { "required": false, "description": "Product parent ID.", "type": "integer" }, "purchase_note": { "required": false, "description": "Optional note to send the customer after purchase.", "type": "string" }, "categories": { "required": false, "description": "List of categories.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Category ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Category name.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "slug": { "description": "Category slug.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "tags": { "required": false, "description": "List of tags.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Tag ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Tag name.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "slug": { "description": "Tag slug.", "type": "string", "context": [ "view", "edit" ], "readonly": true } } } }, "images": { "required": false, "description": "List of images.", "type": "object", "items": { "type": "object", "properties": { "id": { "description": "Image ID.", "type": "integer", "context": [ "view", "edit" ] }, "date_created": { "description": "The date the image was created, in the site's timezone.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "date_created_gmt": { "description": "The date the image was created, as GMT.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "date_modified": { "description": "The date the image was last modified, in the site's timezone.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "date_modified_gmt": { "description": "The date the image was last modified, as GMT.", "type": "date-time", "context": [ "view", "edit" ], "readonly": true }, "src": { "description": "Image URL.", "type": "string", "format": "uri", "context": [ "view", "edit" ] }, "name": { "description": "Image name.", "type": "string", "context": [ "view", "edit" ] }, "alt": { "description": "Image alternative text.", "type": "string", "context": [ "view", "edit" ] }, "position": { "description": "Image position. 0 means that the image is featured.", "type": "integer", "context": [ "view", "edit" ] } } } }, "attributes": { "required": false, "description": "List of attributes.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Attribute ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Attribute name.", "type": "string", "context": [ "view", "edit" ] }, "position": { "description": "Attribute position.", "type": "integer", "context": [ "view", "edit" ] }, "visible": { "description": "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", "type": "boolean", "default": false, "context": [ "view", "edit" ] }, "variation": { "description": "Define if the attribute can be used as variation.", "type": "boolean", "default": false, "context": [ "view", "edit" ] }, "options": { "description": "List of available term names of the attribute.", "type": "array", "context": [ "view", "edit" ] } } } }, "default_attributes": { "required": false, "description": "Defaults variation attributes.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Attribute ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Attribute name.", "type": "string", "context": [ "view", "edit" ] }, "option": { "description": "Selected attribute term name.", "type": "string", "context": [ "view", "edit" ] } } } }, "menu_order": { "required": false, "description": "Menu order, used to custom sort products.", "type": "integer" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/products/batch" } }, "/wc/v3/products/(?P[\\d]+)/variations": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "after": { "required": false, "description": "Limit response to resources published after a given ISO8601 compliant date.", "type": "string" }, "before": { "required": false, "description": "Limit response to resources published before a given ISO8601 compliant date.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific IDs.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific ids.", "type": "array", "items": { "type": "integer" } }, "offset": { "required": false, "description": "Offset the result set by a specific number of items.", "type": "integer" }, "order": { "required": false, "default": "desc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "date", "enum": [ "date", "id", "include", "title", "slug" ], "description": "Sort collection by object attribute.", "type": "string" }, "parent": { "required": false, "default": [], "description": "Limit result set to those of particular parent IDs.", "type": "array", "items": { "type": "integer" } }, "parent_exclude": { "required": false, "default": [], "description": "Limit result set to all items except those of a particular parent ID.", "type": "array", "items": { "type": "integer" } }, "slug": { "required": false, "description": "Limit result set to products with a specific slug.", "type": "string" }, "status": { "required": false, "default": "any", "enum": [ "any", "draft", "pending", "private", "publish" ], "description": "Limit result set to products assigned a specific status.", "type": "string" }, "type": { "required": false, "enum": [ "simple", "grouped", "external", "variable" ], "description": "Limit result set to products assigned a specific type.", "type": "string" }, "sku": { "required": false, "description": "Limit result set to products with a specific SKU.", "type": "string" }, "featured": { "required": false, "description": "Limit result set to featured products.", "type": "boolean" }, "category": { "required": false, "description": "Limit result set to products assigned a specific category ID.", "type": "string" }, "tag": { "required": false, "description": "Limit result set to products assigned a specific tag ID.", "type": "string" }, "shipping_class": { "required": false, "description": "Limit result set to products assigned a specific shipping class ID.", "type": "string" }, "attribute": { "required": false, "description": "Limit result set to products with a specific attribute.", "type": "string" }, "attribute_term": { "required": false, "description": "Limit result set to products with a specific attribute term ID (required an assigned attribute).", "type": "string" }, "tax_class": { "required": false, "enum": [ "standard", "reduced-rate", "zero-rate" ], "description": "Limit result set to products with a specific tax class.", "type": "string" }, "in_stock": { "required": false, "description": "Limit result set to products in stock or out of stock.", "type": "boolean" }, "on_sale": { "required": false, "description": "Limit result set to products on sale.", "type": "boolean" }, "min_price": { "required": false, "description": "Limit result set to products based on a minimum price.", "type": "string" }, "max_price": { "required": false, "description": "Limit result set to products based on a maximum price.", "type": "string" }, "image_size": { "required": false, "default": "full", "description": "Use a specific registered image size for the returned variation image src. Falls back to the full size if the requested size is not registered.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "description": { "required": false, "description": "Variation description.", "type": "string" }, "sku": { "required": false, "description": "Unique identifier.", "type": "string" }, "regular_price": { "required": false, "description": "Variation regular price.", "type": "string" }, "sale_price": { "required": false, "description": "Variation sale price.", "type": "string" }, "date_on_sale_from": { "required": false, "description": "Start date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_from_gmt": { "required": false, "description": "Start date of sale price, as GMT.", "type": "date-time" }, "date_on_sale_to": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_to_gmt": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "visible": { "required": false, "default": true, "description": "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", "type": "boolean" }, "virtual": { "required": false, "default": false, "description": "If the variation is virtual.", "type": "boolean" }, "downloadable": { "required": false, "default": false, "description": "If the variation is downloadable.", "type": "boolean" }, "downloads": { "required": false, "description": "List of downloadable files.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "File ID.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "File name.", "type": "string", "context": [ "view", "edit" ] }, "file": { "description": "File URL.", "type": "string", "context": [ "view", "edit" ] } } } }, "download_limit": { "required": false, "default": -1, "description": "Number of times downloadable files can be downloaded after purchase.", "type": "integer" }, "download_expiry": { "required": false, "default": -1, "description": "Number of days until access to downloadable files expires.", "type": "integer" }, "tax_status": { "required": false, "default": "taxable", "enum": [ "taxable", "shipping", "none" ], "description": "Tax status.", "type": "string" }, "tax_class": { "required": false, "description": "Tax class.", "type": "string" }, "manage_stock": { "required": false, "default": false, "description": "Stock management at variation level.", "type": [ "boolean", "string" ] }, "stock_quantity": { "required": false, "description": "Stock quantity.", "type": "integer" }, "in_stock": { "required": false, "default": true, "description": "Controls whether or not the variation is listed as \"in stock\" or \"out of stock\" on the frontend.", "type": "boolean" }, "backorders": { "required": false, "default": "no", "enum": [ "no", "notify", "yes" ], "description": "If managing stock, this controls if backorders are allowed.", "type": "string" }, "weight": { "required": false, "description": "Variation weight (kg).", "type": "string" }, "dimensions": { "required": false, "description": "Variation dimensions.", "type": "object" }, "shipping_class": { "required": false, "description": "Shipping class slug.", "type": "string" }, "image": { "required": false, "description": "Variation image data.", "type": "object" }, "gallery_image_ids": { "required": false, "description": "Variation gallery image IDs, excluding the featured image (which is set via \"image\").", "type": "array", "items": { "type": "integer", "minimum": 1 } }, "attributes": { "required": false, "description": "List of attributes.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Attribute ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Attribute name.", "type": "string", "context": [ "view", "edit" ] }, "option": { "description": "Selected attribute term name.", "type": "string", "context": [ "view", "edit" ] } } } }, "menu_order": { "required": false, "description": "Menu order, used to custom sort products.", "type": "integer" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } ] }, "/wc/v3/products/(?P[\\d]+)/variations/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "id": { "required": false, "description": "Unique identifier for the variation.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "image_size": { "required": false, "default": "full", "description": "Use a specific registered image size for the returned variation image src. Falls back to the full size if the requested size is not registered.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "id": { "required": false, "description": "Unique identifier for the variation.", "type": "integer" }, "description": { "required": false, "description": "Variation description.", "type": "string" }, "sku": { "required": false, "description": "Unique identifier.", "type": "string" }, "regular_price": { "required": false, "description": "Variation regular price.", "type": "string" }, "sale_price": { "required": false, "description": "Variation sale price.", "type": "string" }, "date_on_sale_from": { "required": false, "description": "Start date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_from_gmt": { "required": false, "description": "Start date of sale price, as GMT.", "type": "date-time" }, "date_on_sale_to": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_to_gmt": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "visible": { "required": false, "description": "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", "type": "boolean" }, "virtual": { "required": false, "description": "If the variation is virtual.", "type": "boolean" }, "downloadable": { "required": false, "description": "If the variation is downloadable.", "type": "boolean" }, "downloads": { "required": false, "description": "List of downloadable files.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "File ID.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "File name.", "type": "string", "context": [ "view", "edit" ] }, "file": { "description": "File URL.", "type": "string", "context": [ "view", "edit" ] } } } }, "download_limit": { "required": false, "description": "Number of times downloadable files can be downloaded after purchase.", "type": "integer" }, "download_expiry": { "required": false, "description": "Number of days until access to downloadable files expires.", "type": "integer" }, "tax_status": { "required": false, "enum": [ "taxable", "shipping", "none" ], "description": "Tax status.", "type": "string" }, "tax_class": { "required": false, "description": "Tax class.", "type": "string" }, "manage_stock": { "required": false, "description": "Stock management at variation level.", "type": [ "boolean", "string" ] }, "stock_quantity": { "required": false, "description": "Stock quantity.", "type": "integer" }, "in_stock": { "required": false, "description": "Controls whether or not the variation is listed as \"in stock\" or \"out of stock\" on the frontend.", "type": "boolean" }, "backorders": { "required": false, "enum": [ "no", "notify", "yes" ], "description": "If managing stock, this controls if backorders are allowed.", "type": "string" }, "weight": { "required": false, "description": "Variation weight (kg).", "type": "string" }, "dimensions": { "required": false, "description": "Variation dimensions.", "type": "object" }, "shipping_class": { "required": false, "description": "Shipping class slug.", "type": "string" }, "image": { "required": false, "description": "Variation image data.", "type": "object" }, "gallery_image_ids": { "required": false, "description": "Variation gallery image IDs, excluding the featured image (which is set via \"image\").", "type": "array", "items": { "type": "integer", "minimum": 1 } }, "attributes": { "required": false, "description": "List of attributes.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Attribute ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Attribute name.", "type": "string", "context": [ "view", "edit" ] }, "option": { "description": "Selected attribute term name.", "type": "string", "context": [ "view", "edit" ] } } } }, "menu_order": { "required": false, "description": "Menu order, used to custom sort products.", "type": "integer" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } }, { "methods": [ "DELETE" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "id": { "required": false, "description": "Unique identifier for the variation.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Whether to bypass trash and force deletion.", "type": "boolean" } } } ] }, "/wc/v3/products/(?P[\\d]+)/variations/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "product_id": { "required": false, "description": "Unique identifier for the variable product.", "type": "integer" }, "description": { "required": false, "description": "Variation description.", "type": "string" }, "sku": { "required": false, "description": "Unique identifier.", "type": "string" }, "regular_price": { "required": false, "description": "Variation regular price.", "type": "string" }, "sale_price": { "required": false, "description": "Variation sale price.", "type": "string" }, "date_on_sale_from": { "required": false, "description": "Start date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_from_gmt": { "required": false, "description": "Start date of sale price, as GMT.", "type": "date-time" }, "date_on_sale_to": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "date_on_sale_to_gmt": { "required": false, "description": "End date of sale price, in the site's timezone.", "type": "date-time" }, "visible": { "required": false, "description": "Define if the attribute is visible on the \"Additional information\" tab in the product's page.", "type": "boolean" }, "virtual": { "required": false, "description": "If the variation is virtual.", "type": "boolean" }, "downloadable": { "required": false, "description": "If the variation is downloadable.", "type": "boolean" }, "downloads": { "required": false, "description": "List of downloadable files.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "File ID.", "type": "string", "context": [ "view", "edit" ], "readonly": true }, "name": { "description": "File name.", "type": "string", "context": [ "view", "edit" ] }, "file": { "description": "File URL.", "type": "string", "context": [ "view", "edit" ] } } } }, "download_limit": { "required": false, "description": "Number of times downloadable files can be downloaded after purchase.", "type": "integer" }, "download_expiry": { "required": false, "description": "Number of days until access to downloadable files expires.", "type": "integer" }, "tax_status": { "required": false, "enum": [ "taxable", "shipping", "none" ], "description": "Tax status.", "type": "string" }, "tax_class": { "required": false, "description": "Tax class.", "type": "string" }, "manage_stock": { "required": false, "description": "Stock management at variation level.", "type": [ "boolean", "string" ] }, "stock_quantity": { "required": false, "description": "Stock quantity.", "type": "integer" }, "in_stock": { "required": false, "description": "Controls whether or not the variation is listed as \"in stock\" or \"out of stock\" on the frontend.", "type": "boolean" }, "backorders": { "required": false, "enum": [ "no", "notify", "yes" ], "description": "If managing stock, this controls if backorders are allowed.", "type": "string" }, "weight": { "required": false, "description": "Variation weight (kg).", "type": "string" }, "dimensions": { "required": false, "description": "Variation dimensions.", "type": "object" }, "shipping_class": { "required": false, "description": "Shipping class slug.", "type": "string" }, "image": { "required": false, "description": "Variation image data.", "type": "object" }, "gallery_image_ids": { "required": false, "description": "Variation gallery image IDs, excluding the featured image (which is set via \"image\").", "type": "array", "items": { "type": "integer", "minimum": 1 } }, "attributes": { "required": false, "description": "List of attributes.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Attribute ID.", "type": "integer", "context": [ "view", "edit" ] }, "name": { "description": "Attribute name.", "type": "string", "context": [ "view", "edit" ] }, "option": { "description": "Selected attribute term name.", "type": "string", "context": [ "view", "edit" ] } } } }, "menu_order": { "required": false, "description": "Menu order, used to custom sort products.", "type": "integer" }, "meta_data": { "required": false, "description": "Meta data.", "type": "array", "items": { "type": "object", "properties": { "id": { "description": "Meta ID.", "type": "integer", "context": [ "view", "edit" ], "readonly": true }, "key": { "description": "Meta key.", "type": "string", "context": [ "view", "edit" ] }, "value": { "description": "Meta value.", "type": "string", "context": [ "view", "edit" ] } } } } } } ] }, "/wc/v3/reports/sales": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "period": { "required": false, "enum": [ "week", "month", "last_month", "year" ], "description": "Report period.", "type": "string" }, "date_min": { "required": false, "description": "Return sales for a specific start date, the date need to be in the YYYY-MM-DD format.", "type": "string" }, "date_max": { "required": false, "description": "Return sales for a specific end date, the date need to be in the YYYY-MM-DD format.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/reports/sales" } }, "/wc/v3/reports/top_sellers": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "period": { "required": false, "enum": [ "week", "month", "last_month", "year" ], "description": "Report period.", "type": "string" }, "date_min": { "required": false, "description": "Return sales for a specific start date, the date need to be in the YYYY-MM-DD format.", "type": "string" }, "date_max": { "required": false, "description": "Return sales for a specific end date, the date need to be in the YYYY-MM-DD format.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/reports/top_sellers" } }, "/wc/v3/reports": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/reports" } }, "/wc/v3/settings": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": [] } ], "_links": { "self": "https://example.com/wp-json/wc/v3/settings" } }, "/wc/v3/settings/(?P[\\w-]+)": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "group": { "required": false, "description": "Settings group ID.", "type": "string" } } } ] }, "/wc/v3/settings/(?P[\\w-]+)/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "group": { "required": false, "description": "Settings group ID.", "type": "string" }, "value": { "required": false, "description": "Setting value.", "type": "mixed" } } } ] }, "/wc/v3/settings/(?P[\\w-]+)/(?P[\\w-]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "GET" ], "args": { "group": { "required": false, "description": "Settings group ID.", "type": "string" }, "id": { "required": false, "description": "Unique identifier for the resource.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "group": { "required": false, "description": "Settings group ID.", "type": "string" }, "id": { "required": false, "description": "Unique identifier for the resource.", "type": "string" }, "value": { "required": false, "description": "Setting value.", "type": "mixed" } } } ] }, "/wc/v3/shipping/zones": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": [] }, { "methods": [ "POST" ], "args": { "name": { "required": true, "description": "Shipping zone name.", "type": "string" }, "order": { "required": false, "description": "Shipping zone order.", "type": "integer" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/shipping/zones" } }, "/wc/v3/shipping/zones/(?P[\\d-]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique ID for the resource.", "type": "integer" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique ID for the resource.", "type": "integer" }, "name": { "required": false, "description": "Shipping zone name.", "type": "string" }, "order": { "required": false, "description": "Shipping zone order.", "type": "integer" } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique ID for the resource.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Whether to bypass trash and force deletion.", "type": "boolean" } } } ] }, "/wc/v3/shipping/zones/(?P[\\d-]+)/locations": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique ID for the resource.", "type": "integer" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique ID for the resource.", "type": "integer" }, "code": { "required": false, "description": "Shipping zone location code.", "type": "string" }, "type": { "required": false, "enum": [ "postcode", "state", "country", "continent" ], "description": "Shipping zone location type.", "type": "string" } } } ] }, "/wc/v3/shipping/zones/(?P[\\d-]+)/methods": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "zone_id": { "required": false, "description": "Unique ID for the zone.", "type": "integer" } } }, { "methods": [ "POST" ], "args": { "zone_id": { "required": false, "description": "Unique ID for the zone.", "type": "integer" }, "order": { "required": false, "description": "Shipping method sort order.", "type": "integer" }, "enabled": { "required": false, "description": "Shipping method enabled status.", "type": "boolean" }, "settings": { "required": false, "description": "Shipping method settings.", "type": "object" }, "method_id": { "required": true, "description": "Shipping method ID." } } } ] }, "/wc/v3/shipping/zones/(?P[\\d-]+)/methods/(?P[\\d-]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "zone_id": { "required": false, "description": "Unique ID for the zone.", "type": "integer" }, "instance_id": { "required": false, "description": "Unique ID for the instance.", "type": "integer" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "zone_id": { "required": false, "description": "Unique ID for the zone.", "type": "integer" }, "instance_id": { "required": false, "description": "Unique ID for the instance.", "type": "integer" }, "order": { "required": false, "description": "Shipping method sort order.", "type": "integer" }, "enabled": { "required": false, "description": "Shipping method enabled status.", "type": "boolean" }, "settings": { "required": false, "description": "Shipping method settings.", "type": "object" } } }, { "methods": [ "DELETE" ], "args": { "zone_id": { "required": false, "description": "Unique ID for the zone.", "type": "integer" }, "instance_id": { "required": false, "description": "Unique ID for the instance.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Whether to bypass trash and force deletion.", "type": "boolean" } } } ] }, "/wc/v3/taxes/classes": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "name": { "required": true, "description": "Tax class name.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/taxes/classes" } }, "/wc/v3/taxes/classes/(?P\\w[\\w\\s\\-]*)": { "namespace": "wc/v3", "methods": [ "DELETE" ], "endpoints": [ { "methods": [ "DELETE" ], "args": { "slug": { "required": false, "description": "Unique slug for the resource.", "type": "string" }, "force": { "required": false, "default": false, "description": "Required to be true, as resource does not support trashing.", "type": "boolean" } } } ] }, "/wc/v3/taxes": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific IDs.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific IDs.", "type": "array", "items": { "type": "integer" } }, "offset": { "required": false, "description": "Offset the result set by a specific number of items.", "type": "integer" }, "order": { "required": false, "default": "asc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "order", "enum": [ "id", "order" ], "description": "Sort collection by object attribute.", "type": "string" }, "class": { "required": false, "enum": [ "standard", "reduced-rate", "zero-rate" ], "description": "Sort by tax class.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "country": { "required": false, "description": "Country ISO 3166 code.", "type": "string" }, "state": { "required": false, "description": "State code.", "type": "string" }, "postcode": { "required": false, "description": "Postcode / ZIP.", "type": "string" }, "city": { "required": false, "description": "City name.", "type": "string" }, "rate": { "required": false, "description": "Tax rate.", "type": "string" }, "name": { "required": false, "description": "Tax rate name.", "type": "string" }, "priority": { "required": false, "default": 1, "description": "Tax priority.", "type": "integer" }, "compound": { "required": false, "default": false, "description": "Whether or not this is a compound rate.", "type": "boolean" }, "shipping": { "required": false, "default": true, "description": "Whether or not this tax rate also gets applied to shipping.", "type": "boolean" }, "order": { "required": false, "description": "Indicates the order that will appear in queries.", "type": "integer" }, "class": { "required": false, "default": "standard", "enum": [ "standard", "reduced-rate", "zero-rate" ], "description": "Tax class.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/taxes" } }, "/wc/v3/taxes/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "country": { "required": false, "description": "Country ISO 3166 code.", "type": "string" }, "state": { "required": false, "description": "State code.", "type": "string" }, "postcode": { "required": false, "description": "Postcode / ZIP.", "type": "string" }, "city": { "required": false, "description": "City name.", "type": "string" }, "rate": { "required": false, "description": "Tax rate.", "type": "string" }, "name": { "required": false, "description": "Tax rate name.", "type": "string" }, "priority": { "required": false, "description": "Tax priority.", "type": "integer" }, "compound": { "required": false, "description": "Whether or not this is a compound rate.", "type": "boolean" }, "shipping": { "required": false, "description": "Whether or not this tax rate also gets applied to shipping.", "type": "boolean" }, "order": { "required": false, "description": "Indicates the order that will appear in queries.", "type": "integer" }, "class": { "required": false, "enum": [ "standard", "reduced-rate", "zero-rate" ], "description": "Tax class.", "type": "string" } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Required to be true, as resource does not support trashing.", "type": "boolean" } } } ] }, "/wc/v3/taxes/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "country": { "required": false, "description": "Country ISO 3166 code.", "type": "string" }, "state": { "required": false, "description": "State code.", "type": "string" }, "postcode": { "required": false, "description": "Postcode / ZIP.", "type": "string" }, "city": { "required": false, "description": "City name.", "type": "string" }, "rate": { "required": false, "description": "Tax rate.", "type": "string" }, "name": { "required": false, "description": "Tax rate name.", "type": "string" }, "priority": { "required": false, "description": "Tax priority.", "type": "integer" }, "compound": { "required": false, "description": "Whether or not this is a compound rate.", "type": "boolean" }, "shipping": { "required": false, "description": "Whether or not this tax rate also gets applied to shipping.", "type": "boolean" }, "order": { "required": false, "description": "Indicates the order that will appear in queries.", "type": "integer" }, "class": { "required": false, "enum": [ "standard", "reduced-rate", "zero-rate" ], "description": "Tax class.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/taxes/batch" } }, "/wc/v3/webhooks/(?P[\\d]+)/deliveries": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "webhook_id": { "required": false, "description": "Unique identifier for the webhook.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } } ] }, "/wc/v3/webhooks/(?P[\\d]+)/deliveries/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "webhook_id": { "required": false, "description": "Unique identifier for the webhook.", "type": "integer" }, "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } } ] }, "/wc/v3/webhooks": { "namespace": "wc/v3", "methods": [ "GET", "POST" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" }, "page": { "required": false, "default": 1, "description": "Current page of the collection.", "type": "integer" }, "per_page": { "required": false, "default": 10, "description": "Maximum number of items to be returned in result set.", "type": "integer" }, "search": { "required": false, "description": "Limit results to those matching a string.", "type": "string" }, "after": { "required": false, "description": "Limit response to resources published after a given ISO8601 compliant date.", "type": "string" }, "before": { "required": false, "description": "Limit response to resources published before a given ISO8601 compliant date.", "type": "string" }, "exclude": { "required": false, "default": [], "description": "Ensure result set excludes specific IDs.", "type": "array", "items": { "type": "integer" } }, "include": { "required": false, "default": [], "description": "Limit result set to specific ids.", "type": "array", "items": { "type": "integer" } }, "offset": { "required": false, "description": "Offset the result set by a specific number of items.", "type": "integer" }, "order": { "required": false, "default": "desc", "enum": [ "asc", "desc" ], "description": "Order sort attribute ascending or descending.", "type": "string" }, "orderby": { "required": false, "default": "date", "enum": [ "date", "id", "include", "title", "slug" ], "description": "Sort collection by object attribute.", "type": "string" }, "status": { "required": false, "default": "all", "enum": [ "all", "active", "paused", "disabled" ], "description": "Limit result set to webhooks assigned a specific status.", "type": "string" } } }, { "methods": [ "POST" ], "args": { "name": { "required": false, "description": "A friendly name for the webhook.", "type": "string" }, "status": { "required": false, "default": "active", "enum": [ "active", "paused", "disabled" ], "description": "Webhook status.", "type": "string" }, "topic": { "required": true, "description": "Webhook topic.", "type": "string" }, "secret": { "required": true, "description": "Webhook secret.", "type": "string" }, "delivery_url": { "required": true, "description": "Webhook delivery URL.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/webhooks" } }, "/wc/v3/webhooks/(?P[\\d]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "name": { "required": false, "description": "A friendly name for the webhook.", "type": "string" }, "status": { "required": false, "enum": [ "active", "paused", "disabled" ], "description": "Webhook status.", "type": "string" }, "topic": { "required": false, "description": "Webhook topic.", "type": "string" }, "secret": { "required": false, "description": "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default is a MD5 hash from the current user's ID|username if not provided.", "type": "string" } } }, { "methods": [ "DELETE" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "integer" }, "force": { "required": false, "default": false, "description": "Required to be true, as resource does not support trashing.", "type": "boolean" } } } ] }, "/wc/v3/webhooks/batch": { "namespace": "wc/v3", "methods": [ "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "POST", "PUT", "PATCH" ], "args": { "name": { "required": false, "description": "A friendly name for the webhook.", "type": "string" }, "status": { "required": false, "enum": [ "active", "paused", "disabled" ], "description": "Webhook status.", "type": "string" }, "topic": { "required": false, "description": "Webhook topic.", "type": "string" }, "secret": { "required": false, "description": "Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default is a MD5 hash from the current user's ID|username if not provided.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/webhooks/batch" } }, "/wc/v3/system_status": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/system_status" } }, "/wc/v3/system_status/tools": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/system_status/tools" } }, "/wc/v3/system_status/tools/(?P[\\w-]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "A unique identifier for the tool.", "type": "string" }, "name": { "required": false, "description": "Tool name.", "type": "string" }, "action": { "required": false, "description": "What running the tool will do.", "type": "string" }, "description": { "required": false, "description": "Tool description.", "type": "string" }, "success": { "required": false, "description": "Did the tool run successfully?", "type": "boolean" }, "message": { "required": false, "description": "Tool return message.", "type": "string" } } } ] }, "/wc/v3/shipping_methods": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/shipping_methods" } }, "/wc/v3/shipping_methods/(?P[\\w-]+)": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "string" }, "context": { "required": false, "default": "view", "enum": [ "view" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } } ] }, "/wc/v3/payment_gateways": { "namespace": "wc/v3", "methods": [ "GET" ], "endpoints": [ { "methods": [ "GET" ], "args": { "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } } ], "_links": { "self": "https://example.com/wp-json/wc/v3/payment_gateways" } }, "/wc/v3/payment_gateways/(?P[\\w-]+)": { "namespace": "wc/v3", "methods": [ "GET", "POST", "PUT", "PATCH" ], "endpoints": [ { "methods": [ "GET" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "string" }, "context": { "required": false, "default": "view", "enum": [ "view", "edit" ], "description": "Scope under which the request is made; determines fields present in response.", "type": "string" } } }, { "methods": [ "POST", "PUT", "PATCH" ], "args": { "id": { "required": false, "description": "Unique identifier for the resource.", "type": "string" }, "title": { "required": false, "description": "Payment gateway title on checkout.", "type": "string" }, "description": { "required": false, "description": "Payment gateway description on checkout.", "type": "string" }, "order": { "required": false, "description": "Payment gateway sort order.", "type": "integer" }, "enabled": { "required": false, "description": "Payment gateway enabled status.", "type": "boolean" }, "settings": { "required": false, "description": "Payment gateway settings.", "type": "object" } } } ] } }, "_links": { "up": [ { "href": "https://example.com/wp-json/" } ] } } ``` --- ## Coupons *Source: apis/rest-api/v3/coupons.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Coupons The coupons API allows you to create, view, update, and delete individual, or a batch, of coupon codes. ## Coupon properties | Attribute | Type | Description | | ----------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------ | | `id` | integer | Unique identifier for the object. `READ-ONLY` | | `code` | string | Coupon code. `MANDATORY` | | `amount` | string | The amount of discount. Should always be numeric, even if setting a percentage. | | `date_created` | date-time | The date the coupon was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the coupon was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the coupon was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the coupon was last modified, as GMT. `READ-ONLY` | | `discount_type` | string | Determines the type of discount that will be applied. Options: `percent`, `fixed_cart` and `fixed_product`. Default is `fixed_cart`. | | `description` | string | Coupon description. | | `date_expires` | string | The date the coupon expires, in the site's timezone. | | `date_expires_gmt` | string | The date the coupon expires, as GMT. | | `usage_count` | integer | Number of times the coupon has been used already. `READ-ONLY` | | `individual_use` | boolean | If true, the coupon can only be used individually. Other applied coupons will be removed from the cart. Default is `false`. | | `product_ids` | array | List of product IDs the coupon can be used on. | | `excluded_product_ids` | array | List of product IDs the coupon cannot be used on. | | `usage_limit` | integer | How many times the coupon can be used in total. | | `usage_limit_per_user` | integer | How many times the coupon can be used per customer. | | `limit_usage_to_x_items` | integer | Max number of items in the cart the coupon can be applied to. | | `free_shipping` | boolean | If true and if the free shipping method requires a coupon, this coupon will enable free shipping. Default is `false`. | | `product_categories` | array | List of category IDs the coupon applies to. | | `excluded_product_categories` | array | List of category IDs the coupon does not apply to. | | `exclude_sale_items` | boolean | If true, this coupon will not be applied to items that have sale prices. Default is `false`. | | `minimum_amount` | string | Minimum order amount that needs to be in the cart before coupon applies. | | `maximum_amount` | string | Maximum order amount allowed when using the coupon. | | `email_restrictions` | array | List of email addresses that can use this coupon. | | `used_by` | array | List of user IDs (or guest email addresses) that have used the coupon. `READ-ONLY` | | `meta_data` | array | Meta data. See [Coupon - Meta data properties](#coupon---meta-data-properties) | ### Coupon - Meta data properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------- | | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ## Create a coupon This API helps you to create a new coupon. ```http POST /wp-json/wc/v3/coupons ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/coupons \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "code": "10off", "discount_type": "percent", "amount": "10", "individual_use": true, "exclude_sale_items": true, "minimum_amount": "100.00" }' ``` ```javascript const data = { code: '10off', discount_type: 'percent', amount: '10', individual_use: true, exclude_sale_items: true, minimum_amount: '100.00', }; WooCommerce.post( 'coupons', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php '10off', 'discount_type' => 'percent', 'amount' => '10', 'individual_use' => true, 'exclude_sale_items' => true, 'minimum_amount' => '100.00' ]; print_r($woocommerce->post('coupons', $data)); ?> ``` ```python data = { "code": "10off", "discount_type": "percent", "amount": "10", "individual_use": True, "exclude_sale_items": True, "minimum_amount": "100.00" } print(wcapi.post("coupons", data).json()) ``` ```ruby data = { code: "10off", discount_type: "percent", amount: "10", individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" } woocommerce.post("coupons", data).parsed_response ``` ```json { "id": 719, "code": "10off", "amount": "10.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:23:00", "date_modified_gmt": "2017-03-21T18:23:00", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/coupons" } ] } } ``` ## Retrieve a coupon This API lets you retrieve and view a specific coupon by ID. ```http GET /wp-json/wc/v3/coupons/ ``` ```shell curl https://example.com/wp-json/wc/v3/coupons/719 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'coupons/719' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('coupons/719')); ?> ``` ```python print(wcapi.get("coupons/719").json()) ``` ```ruby woocommerce.get("coupons/719").parsed_response ``` ```json { "id": 719, "code": "10off", "amount": "10.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:23:00", "date_modified_gmt": "2017-03-21T18:23:00", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/coupons" } ] } } ``` ## List all coupons This API helps you to list all the coupons that have been created. ```http GET /wp-json/wc/v3/coupons ``` ```shell curl https://example.com/wp-json/wc/v3/coupons \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'coupons' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('coupons')); ?> ``` ```python print(wcapi.get("coupons").json()) ``` ```ruby woocommerce.get("coupons").parsed_response ``` ```json [ { "id": 720, "code": "free shipping", "amount": "0.00", "date_created": "2017-03-21T15:25:02", "date_created_gmt": "2017-03-21T18:25:02", "date_modified": "2017-03-21T15:25:02", "date_modified_gmt": "2017-03-21T18:25:02", "discount_type": "fixed_cart", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": true, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": false, "minimum_amount": "0.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/coupons/720" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/coupons" } ] } }, { "id": 719, "code": "10off", "amount": "10.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:23:00", "date_modified_gmt": "2017-03-21T18:23:00", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/coupons" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ----------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `modified_after` | string | Limit response to resources modified after a given ISO8601 compliant date. | | `modified_before` | string | Limit response to resources modified after a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Whether to interpret dates as GMT when limiting response by published or modified date. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `modified`, `id`, `include`, `title` and `slug`. Default is `date`. | | `code` | string | Limit result set to resources with a specific code. | ## Update a coupon This API lets you make changes to a coupon. ```http PUT /wp-json/wc/v3/coupons/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/coupons/719 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "amount": "5" }' ``` ```javascript const data = { amount: '5', }; WooCommerce.put( 'coupons/719', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php '5' ]; print_r($woocommerce->put('coupons/719', $data)); ?> ``` ```python data = { "amount": "5" } print(wcapi.put("coupons/719", data).json()) ``` ```ruby data = { amount: "5" } woocommerce.put("coupons/719", data).parsed_response ``` ```json { "id": 719, "code": "10off", "amount": "5.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:26:16", "date_modified_gmt": "2017-03-21T18:26:16", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/coupons" } ] } } ``` ## Delete a coupon This API helps you delete a coupon. ```http DELETE /wp-json/wc/v3/coupons/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/coupons/719?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'coupons/719', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('coupons/719', ['force' => true])); ?> ``` ```python print(wcapi.delete("coupons/719", params={"force": True}).json()) ``` ```ruby woocommerce.delete("coupons/719", force: true).parsed_response ``` ```json { "id": 719, "code": "10off", "amount": "5.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:26:16", "date_modified_gmt": "2017-03-21T18:26:16", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/coupons" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------------------ | | `force` | string | Use `true` whether to permanently delete the coupon, Default is `false`. | ## Batch update coupons This API helps you to batch create, update and delete multiple coupons. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/coupons/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/coupons/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "code": "20off", "discount_type": "percent", "amount": "20", "individual_use": true, "exclude_sale_items": true, "minimum_amount": "100.00" }, { "code": "30off", "discount_type": "percent", "amount": "30", "individual_use": true, "exclude_sale_items": true, "minimum_amount": "100.00" } ], "update": [ { "id": 719, "minimum_amount": "50.00" } ], "delete": [ 720 ] }' ``` ```javascript const data = { create: [ { code: '20off', discount_type: 'percent', amount: '20', individual_use: true, exclude_sale_items: true, minimum_amount: '100.00', }, { code: '30off', discount_type: 'percent', amount: '30', individual_use: true, exclude_sale_items: true, minimum_amount: '100.00', }, ], update: [ { id: 719, minimum_amount: '50.00', }, ], delete: [ 720 ], }; WooCommerce.post( 'coupons/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'code' => '20off', 'discount_type' => 'percent', 'amount' => '20', 'individual_use' => true, 'exclude_sale_items' => true, 'minimum_amount' => '100.00' ], [ 'code' => '30off', 'discount_type' => 'percent', 'amount' => '30', 'individual_use' => true, 'exclude_sale_items' => true, 'minimum_amount' => '100.00' ] ], 'update' => [ [ 'id' => 719, 'minimum_amount' => '50.00' ] ], 'delete' => [ 720 ] ]; print_r($woocommerce->post('coupons/batch', $data)); ?> ``` ```python data = { "create": [ { "code": "20off", "discount_type": "percent", "amount": "20", "individual_use": True, "exclude_sale_items": True, "minimum_amount": "100.00" }, { "code": "30off", "discount_type": "percent", "amount": "30", "individual_use": True, "exclude_sale_items": True, "minimum_amount": "100.00" } ], "update": [ { "id": 719, "minimum_amount": "50.00" } ], "delete": [ 720 ] } print(wcapi.post("coupons/batch", data).json()) ``` ```ruby data = { create: [ { code: "20off", discount_type: "percent", amount: "20", individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" }, { code: "30off", discount_type: "percent", amount: "30", individual_use: true, exclude_sale_items: true, minimum_amount: "100.00" } ], update: [ { id: 719, minimum_amount: "50.00" } ], delete: [ 720 ] } woocommerce.post("coupons/batch", data).parsed_response ``` ```json { "create": [ { "id": 721, "code": "20off", "amount": "20.00", "date_created": "2017-03-21T15:27:29", "date_created_gmt": "2017-03-21T18:27:29", "date_modified": "2017-03-21T15:27:29", "date_modified_gmt": "2017-03-21T18:27:29", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/coupons/721" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/coupons" } ] } }, { "id": 722, "code": "30off", "amount": "30.00", "date_created": "2017-03-21T15:27:31", "date_created_gmt": "2017-03-21T18:27:31", "date_modified": "2017-03-21T15:27:31", "date_modified_gmt": "2017-03-21T18:27:31", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "100.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/coupons/722" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/coupons" } ] } } ], "update": [ { "id": 719, "code": "10off", "amount": "5.00", "date_created": "2017-03-21T15:23:00", "date_created_gmt": "2017-03-21T18:23:00", "date_modified": "2017-03-21T15:27:32", "date_modified_gmt": "2017-03-21T18:27:32", "discount_type": "percent", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": false, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": true, "minimum_amount": "50.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/coupons/719" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/coupons" } ] } } ], "delete": [ { "id": 720, "code": "free shipping", "amount": "0.00", "date_created": "2017-03-21T15:25:02", "date_created_gmt": "2017-03-21T18:25:02", "date_modified": "2017-03-21T15:25:02", "date_modified_gmt": "2017-03-21T18:25:02", "discount_type": "fixed_cart", "description": "", "date_expires": null, "date_expires_gmt": null, "usage_count": 0, "individual_use": true, "product_ids": [], "excluded_product_ids": [], "usage_limit": null, "usage_limit_per_user": null, "limit_usage_to_x_items": null, "free_shipping": true, "product_categories": [], "excluded_product_categories": [], "exclude_sale_items": false, "minimum_amount": "0.00", "maximum_amount": "0.00", "email_restrictions": [], "used_by": [], "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/coupons/720" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/coupons" } ] } } ] } ``` --- ## Customers *Source: apis/rest-api/v3/customers.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Customers The customer API allows you to create, view, update, and delete individual, or a batch, of customers. ## Customer properties | Attribute | Type | Description | | -------------------- | --------- | ---------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | date-time | The date the customer was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the customer was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the customer was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the customer was last modified, as GMT. `READ-ONLY` | | `email` | string | The email address for the customer. `MANDATORY` | | `first_name` | string | Customer first name. | | `last_name` | string | Customer last name. | | `role` | string | Customer role. `READ-ONLY` | | `username` | string | Customer login name. | | `password` | string | Customer password. `WRITE-ONLY` | | `billing` | object | List of billing address data. See [Customer - Billing properties](#customer---billing-properties) | | `shipping` | object | List of shipping address data. See [Customer - Shipping properties](#customer---shipping-properties) | | `is_paying_customer` | bool | Is the customer a paying customer? `READ-ONLY` | | `avatar_url` | string | Avatar URL. `READ-ONLY` | | `meta_data` | array | Meta data. See [Customer - Meta data properties](#customer---meta-data-properties) | ### Customer - Billing properties | Attribute | Type | Description | | ------------ | ------ | ---------------------------------------------------- | | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1 | | `address_2` | string | Address line 2 | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | ISO code of the country. | | `email` | string | Email address. | | `phone` | string | Phone number. | ### Customer - Shipping properties | Attribute | Type | Description | | ------------ | ------ | ---------------------------------------------------- | | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1 | | `address_2` | string | Address line 2 | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | ISO code of the country. | ### Customer - Meta data properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------- | | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ## Create a customer This API helps you to create a new customer. ```http POST /wp-json/wc/v3/customers ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/customers \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } }' ``` ```javascript const data = { email: 'john.doe@example.com', first_name: 'John', last_name: 'Doe', username: 'john.doe', billing: { first_name: 'John', last_name: 'Doe', company: '', address_1: '969 Market', address_2: '', city: 'San Francisco', state: 'CA', postcode: '94103', country: 'US', email: 'john.doe@example.com', phone: '(555) 555-5555', }, shipping: { first_name: 'John', last_name: 'Doe', company: '', address_1: '969 Market', address_2: '', city: 'San Francisco', state: 'CA', postcode: '94103', country: 'US', }, }; WooCommerce.post( 'customers', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'john.doe@example.com', 'first_name' => 'John', 'last_name' => 'Doe', 'username' => 'john.doe', 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ] ]; print_r($woocommerce->post('customers', $data)); ?> ``` ```python data = { "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } } print(wcapi.post("customers", data).json()) ``` ```ruby data = { email: "john.doe@example.com", first_name: "John", last_name: "Doe", username: "john.doe", billing: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" } } woocommerce.post("customers", data).parsed_response ``` ```json { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:09:30", "date_modified_gmt": "2017-03-21T19:09:30", "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/customers" } ] } } ``` ## Retrieve a customer This API lets you retrieve and view a specific customer by ID. ```http GET /wp-json/wc/v3/customers/ ``` ```shell curl https://example.com/wp-json/wc/v3/customers/25 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'customers/25' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('customers/25')); ?> ``` ```python print(wcapi.get("customers/25").json()) ``` ```ruby woocommerce.get("customers/25").parsed_response ``` ```json { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:09:30", "date_modified_gmt": "2017-03-21T19:09:30", "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/customers" } ] } } ``` ## List all customers This API helps you to view all the customers. ```http GET /wp-json/wc/v3/customers ``` ```shell curl https://example.com/wp-json/wc/v3/customers \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'customers' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('customers')); ?> ``` ```python print(wcapi.get("customers").json()) ``` ```ruby woocommerce.get("customers").parsed_response ``` ```json [ { "id": 26, "date_created": "2017-03-21T16:11:14", "date_created_gmt": "2017-03-21T19:11:14", "date_modified": "2017-03-21T16:11:16", "date_modified_gmt": "2017-03-21T19:11:16", "email": "joao.silva@example.com", "first_name": "João", "last_name": "Silva", "role": "customer", "username": "joao.silva", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "is_paying_customer": false, "avatar_url": "https://secure.gravatar.com/avatar/be7b5febff88a2d947c3289e90cdf017?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/customers/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/customers" } ] } }, { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:09:30", "date_modified_gmt": "2017-03-21T19:09:30", "email": "john.doe@example.com", "first_name": "John", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/customers" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ---------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific IDs. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `asc`. | | `orderby` | string | Sort collection by object attribute. Options: `id`, `include`, `name` and `registered_date`. Default is `name`. | | `email` | string | Limit result set to resources with a specific email. | | `role` | string | Limit result set to resources with a specific role. Options: `all`, `administrator`, `editor`, `author`, `contributor`, `subscriber`, `customer` and `shop_manager`. Default is `customer`. | ## Update a customer This API lets you make changes to a customer. ```http PUT /wp-json/wc/v3/customers/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/customers/25 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "first_name": "James", "billing": { "first_name": "James" }, "shipping": { "first_name": "James" } }' ``` ```javascript const data = { first_name: 'James', billing: { first_name: 'James', }, shipping: { first_name: 'James', }, }; WooCommerce.put( 'customers/25', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'James', 'billing' => [ 'first_name' => 'James' ], 'shipping' => [ 'first_name' => 'James' ] ]; print_r($woocommerce->put('customers/25', $data)); ?> ``` ```python data = { "first_name": "James", "billing": { "first_name": "James" }, "shipping": { "first_name": "James" } } print(wcapi.put("customers/25", data).json()) ``` ```ruby data = { first_name: "James", billing: { first_name: "James" }, shipping: { first_name: "James" } } woocommerce.put("customers/25", data).parsed_response ``` ```json { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:12:28", "date_modified_gmt": "2017-03-21T19:12:28", "email": "john.doe@example.com", "first_name": "James", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/customers" } ] } } ``` ## Delete a customer This API helps you delete a customer. ```http DELETE /wp-json/wc/v3/customers/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/customers/25?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'customers/25', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('customers/25', ['force' => true])); ?> ``` ```python print(wcapi.delete("customers/25", params={"force": True}).json()) ``` ```ruby woocommerce.delete("customers/25", force: true).parsed_response ``` ```json { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:12:28", "date_modified_gmt": "2017-03-21T19:12:28", "email": "john.doe@example.com", "first_name": "James", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/customers" } ] } } ``` #### Available parameters | Parameter | Type | Description | | ---------- | ------- | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | | `reassign` | integer | User ID to reassign posts to. | ## Batch update customers This API helps you to batch create, update and delete multiple customers. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/customers/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/customers/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "email": "john.doe2@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe2", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } }, { "email": "joao.silva2@example.com", "first_name": "João", "last_name": "Silva", "username": "joao.silva2", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" } } ], "update": [ { "id": 26, "billing": { "phone": "(11) 1111-1111" } } ], "delete": [ 25 ] }' ``` ```javascript const data = { create: [ { email: 'john.doe2@example.com', first_name: 'John', last_name: 'Doe', username: 'john.doe2', billing: { first_name: 'John', last_name: 'Doe', company: '', address_1: '969 Market', address_2: '', city: 'San Francisco', state: 'CA', postcode: '94103', country: 'US', email: 'john.doe@example.com', phone: '(555) 555-5555', }, shipping: { first_name: 'John', last_name: 'Doe', company: '', address_1: '969 Market', address_2: '', city: 'San Francisco', state: 'CA', postcode: '94103', country: 'US', }, }, { email: 'joao.silva2@example.com', first_name: 'João', last_name: 'Silva', username: 'joao.silva2', billing: { first_name: 'João', last_name: 'Silva', company: '', address_1: 'Av. Brasil, 432', address_2: '', city: 'Rio de Janeiro', state: 'RJ', postcode: '12345-000', country: 'BR', email: 'joao.silva@example.com', phone: '(55) 5555-5555', }, shipping: { first_name: 'João', last_name: 'Silva', company: '', address_1: 'Av. Brasil, 432', address_2: '', city: 'Rio de Janeiro', state: 'RJ', postcode: '12345-000', country: 'BR', }, }, ], update: [ { id: 26, billing: { phone: '(11) 1111-1111', }, }, ], delete: [ 11 ], }; WooCommerce.post( 'customers/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'email' => 'john.doe2@example.com', 'first_name' => 'John', 'last_name' => 'Doe', 'username' => 'john.doe2', 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'company' => '', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ] ], [ 'email' => 'joao.silva2@example.com', 'first_name' => 'João', 'last_name' => 'Silva', 'username' => 'joao.silva2', 'billing' => [ 'first_name' => 'João', 'last_name' => 'Silva', 'company' => '', 'address_1' => 'Av. Brasil, 432', 'address_2' => '', 'city' => 'Rio de Janeiro', 'state' => 'RJ', 'postcode' => '12345-000', 'country' => 'BR', 'email' => 'joao.silva@example.com', 'phone' => '(55) 5555-5555' ], 'shipping' => [ 'first_name' => 'João', 'last_name' => 'Silva', 'company' => '', 'address_1' => 'Av. Brasil, 432', 'address_2' => '', 'city' => 'Rio de Janeiro', 'state' => 'RJ', 'postcode' => '12345-000', 'country' => 'BR' ] ] ], 'update' => [ [ 'id' => 26, 'billing' => [ 'phone' => '(11) 1111-1111' ] ] ], 'delete' => [ 25 ] ]; print_r($woocommerce->post('customers/batch', $data)); ?> ``` ```python data = { "create": [ { "email": "john.doe2@example.com", "first_name": "John", "last_name": "Doe", "username": "john.doe2", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" } }, { "email": "joao.silva2@example.com", "first_name": "João", "last_name": "Silva", "username": "joao.silva2", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" } } ], "update": [ { "id": 26, "billing": { "phone": "(11) 1111-1111" } } ], "delete": [ 25 ] } print(wcapi.post("customers/batch", data).json()) ``` ```ruby data = { create: [ { email: "john.doe2@example.com", first_name: "John", last_name: "Doe", username: "john.doe2", billing: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", company: "", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" } }, { email: "joao.silva2@example.com", first_name: "João", last_name: "Silva", username: "joao.silva2", billing: { first_name: "João", last_name: "Silva", company: "", address_1: "Av. Brasil, 432", address_2: "", city: "Rio de Janeiro", state: "RJ", postcode: "12345-000", country: "BR", email: "joao.silva@example.com", phone: "(55) 5555-5555" }, shipping: { first_name: "João", last_name: "Silva", company: "", address_1: "Av. Brasil, 432", address_2: "", city: "Rio de Janeiro", state: "RJ", postcode: "12345-000", country: "BR" } } ], update: [ { id: 26, billing: { phone: "(11) 1111-1111" } } ], delete: [ 25 ] } woocommerce.post("customers/batch", data).parsed_response ``` ```json { "create": [ { "id": 27, "date_created": "2017-03-21T16:13:58", "date_created_gmt": "2017-03-21T19:13:58", "date_modified": "2017-03-21T16:13:59", "date_modified_gmt": "2017-03-21T19:13:59", "email": "john.doe2@example.com", "first_name": "John", "last_name": "Doe", "role": "customer", "username": "john.doe2", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "avatar_url": "https://secure.gravatar.com/avatar/6ad0b094bac53a85bb282ccdb3958279?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/customers/27" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/customers" } ] } }, { "id": 28, "date_created": "2017-03-21T16:14:00", "date_created_gmt": "2017-03-21T19:14:00", "date_modified": "2017-03-21T16:14:01", "date_modified_gmt": "2017-03-21T19:14:01", "email": "joao.silva2@example.com", "first_name": "João", "last_name": "Silva", "role": "customer", "username": "joao.silva2", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(55) 5555-5555" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "is_paying_customer": false, "avatar_url": "https://secure.gravatar.com/avatar/ea9ad095f2970f27cbff07e7f5e99453?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/customers/28" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/customers" } ] } } ], "update": [ { "id": 26, "date_created": "2017-03-21T16:11:14", "date_created_gmt": "2017-03-21T19:11:14", "date_modified": "2017-03-21T16:14:03", "date_modified_gmt": "2017-03-21T19:14:03", "email": "joao.silva@example.com", "first_name": "João", "last_name": "Silva", "role": "customer", "username": "joao.silva", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(11) 1111-1111" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "is_paying_customer": false, "avatar_url": "https://secure.gravatar.com/avatar/be7b5febff88a2d947c3289e90cdf017?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/customers/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/customers" } ] } } ], "delete": [ { "id": 25, "date_created": "2017-03-21T16:09:28", "date_created_gmt": "2017-03-21T19:09:28", "date_modified": "2017-03-21T16:12:28", "date_modified_gmt": "2017-03-21T19:12:28", "email": "john.doe@example.com", "first_name": "James", "last_name": "Doe", "role": "customer", "username": "john.doe", "billing": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "James", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "is_paying_customer": false, "avatar_url": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96", "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/customers/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/customers" } ] } } ] } ``` ## Retrieve customer downloads This API lets you retrieve customer downloads permissions. ```http GET /wp-json/wc/v3/customers//downloads ``` ```shell curl https://example.com/wp-json/wc/v3/customers/26/downloads \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'customers/26/downloads' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('customers/26/downloads')); ?> ``` ```python print(wcapi.get("customers/26/downloads").json()) ``` ```ruby woocommerce.get("customers/26/downloads").parsed_response ``` ```json [ { "download_id": "91447fd1849316bbc89dfb7e986a6006", "download_url": "https://example.com/?download_file=87&order=wc_order_58d17c18352&email=joao.silva%40example.com&key=91447fd1849316bbc89dfb7e986a6006", "product_id": 87, "product_name": "Woo Album #2", "download_name": "Woo Album #2 – Song 2", "order_id": 723, "order_key": "wc_order_58d17c18352", "downloads_remaining": "3", "access_expires": "never", "access_expires_gmt": "never", "file": { "name": "Song 2", "file": "http://example.com/wp-content/uploads/woocommerce_uploads/2013/06/Song.mp3" }, "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v3/customers/26/downloads" } ], "product": [ { "href": "https://example.com/wp-json/wc/v3/products/87" } ], "order": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } } ] ``` ### Customer downloads properties | Attribute | Type | Description | | --------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------- | | `download_id` | string | Download ID (MD5). `READ-ONLY` | | `download_url` | string | Download file URL. `READ-ONLY` | | `product_id` | integer | Downloadable product ID. `READ-ONLY` | | `product_name` | string | Product name. `READ-ONLY` | | `download_name` | string | Downloadable file name. `READ-ONLY` | | `order_id` | integer | Order ID. `READ-ONLY` | | `order_key` | string | Order key. `READ-ONLY` | | `downloads_remaining` | string | Number of downloads remaining. `READ-ONLY` | | `access_expires` | string | The date when download access expires, in the site's timezone. `READ-ONLY` | | `access_expires_gmt` | string | The date when download access expires, as GMT. `READ-ONLY` | | `file` | object | File details. `READ-ONLY` See [Customers downloads - File properties](#customer-downloads---file-properties) | ### Customer downloads - File properties | Attribute | Type | Description | | --------- | ------ | ---------------------------------------------------- | | `name` | string | File name. `READ-ONLY` | | `file` | string | File URL. `READ-ONLY` | --- ## Data *Source: apis/rest-api/v3/data.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Data The data API allows you to view all types of data available. ## List all data This API lets you retrieve and view a simple list of available data endpoints. ```http GET /wp-json/wc/v3/data ``` ```shell curl https://example.com/wp-json/wc/v3/data \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'data' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('data')); ?> ``` ```python print(wcapi.get("data").json()) ``` ```ruby woocommerce.get("data").parsed_response ``` ```json [ { "slug": "continents", "description": "List of supported continents, countries, and states.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/continents" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data" } ] } }, { "slug": "countries", "description": "List of supported states in a given country.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data" } ] } }, { "slug": "currencies", "description": "List of supported currencies.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/currencies" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data" } ] } } ] ``` #### Data properties | Attribute | Type | Description | | ------------- | ------ | -------------------------------------------------------------------- | | `slug` | string | Data resource ID. `READ-ONLY` | | `description` | string | Data resource description. `READ-ONLY` | ## List all continents This API helps you to view all the continents. ```http GET /wp-json/wc/v3/data/continents ``` ```shell curl https://example.com/wp-json/wc/v3/data/continents \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'data/continents' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('data/continents')); ?> ``` ```python print(wcapi.get("data/continents").json()) ``` ```ruby woocommerce.get("data/continents").parsed_response ``` ```json [ { "code": "AF", "name": "Africa", "countries": [ { "code": "AO", "name": "Angola", "states": [ { "code": "BGO", "name": "Bengo" }, { "code": "BLU", "name": "Benguela" }, { "code": "BIE", "name": "Bié" }, { "code": "CAB", "name": "Cabinda" }, { "code": "CNN", "name": "Cunene" }, { "code": "HUA", "name": "Huambo" }, { "code": "HUI", "name": "Huíla" }, { "code": "CCU", "name": "Kuando Kubango" }, { "code": "CNO", "name": "Kwanza-Norte" }, { "code": "CUS", "name": "Kwanza-Sul" }, { "code": "LUA", "name": "Luanda" }, { "code": "LNO", "name": "Lunda-Norte" }, { "code": "LSU", "name": "Lunda-Sul" }, { "code": "MAL", "name": "Malanje" }, { "code": "MOX", "name": "Moxico" }, { "code": "NAM", "name": "Namibe" }, { "code": "UIG", "name": "Uíge" }, { "code": "ZAI", "name": "Zaire" } ] }, { "code": "BF", "name": "Burkina Faso", "states": [] }, { "code": "BI", "name": "Burundi", "states": [] } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/continents/af" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data/continents" } ] } } ] ``` #### Continents properties | Attribute | Type | Description | | ----------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | | `code` | string | 2 character continent code. `READ-ONLY` | | `name` | string | Full name of continent. `READ-ONLY` | | `countries` | array | List of countries on this continent. See [Continents - Countries properties](#continents---countries-properties) `READ-ONLY` | ##### Continents - Countries properties | Attribute | Type | Description | | ---------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `code` | string | ISO3166 alpha-2 country code. `READ-ONLY` | | `currency_code` | string | Default ISO4127 alpha-3 currency code for the country. `READ-ONLY` | | `currency_pos` | string | Currency symbol position for this country. `READ-ONLY` | | `decimal_sep` | string | Decimal separator for displayed prices for this country. `READ-ONLY` | | `dimension_unit` | string | The unit lengths are defined in for this country. `READ-ONLY` | | `name` | string | Full name of country. `READ-ONLY` | | `num_decimals` | integer | Number of decimal points shown in displayed prices for this country. `READ-ONLY` | | `states` | array | List of states in this country. See [Continents - Countries - States properties](#continents---countries---states-properties) `READ-ONLY` | | `thousand_sep` | string | Thousands separator for displayed prices in this country. `READ-ONLY` | | `weight_unit` | string | The unit weights are defined in for this country. `READ-ONLY` | ##### Continents - Countries - States properties | Attribute | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `code` | string | State code. `READ-ONLY` | | `name` | string | Full name of state. `READ-ONLY` | ## Retrieve continent data This API lets you retrieve and view a continent data. ```http GET /wp-json/wc/v3/data/continents/ ``` ```shell curl https://example.com/wp-json/wc/v3/data/continents/eu \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'data/continents/eu' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('data/continents/eu')); ?> ``` ```python print(wcapi.get("data/continents/eu").json()) ``` ```ruby woocommerce.get("data/continents/eu").parsed_response ``` ```json { "code": "EU", "name": "Europe", "countries": [ { "code": "AD", "name": "Andorra", "states": [] }, { "code": "AL", "name": "Albania", "states": [] }, { "code": "AT", "name": "Austria", "states": [] }, { "code": "AX", "name": "Åland Islands", "states": [] }, { "code": "BA", "name": "Bosnia and Herzegovina", "states": [] }, { "code": "BE", "name": "Belgium", "currency_code": "EUR", "currency_pos": "left", "decimal_sep": ",", "dimension_unit": "cm", "num_decimals": 2, "thousand_sep": " ", "weight_unit": "kg", "states": [] }, { "code": "BG", "name": "Bulgaria", "states": [ { "code": "BG-01", "name": "Blagoevgrad" }, { "code": "BG-02", "name": "Burgas" }, { "code": "BG-08", "name": "Dobrich" }, { "code": "BG-07", "name": "Gabrovo" }, { "code": "BG-26", "name": "Haskovo" }, { "code": "BG-09", "name": "Kardzhali" }, { "code": "BG-10", "name": "Kyustendil" }, { "code": "BG-11", "name": "Lovech" }, { "code": "BG-12", "name": "Montana" }, { "code": "BG-13", "name": "Pazardzhik" }, { "code": "BG-14", "name": "Pernik" }, { "code": "BG-15", "name": "Pleven" }, { "code": "BG-16", "name": "Plovdiv" }, { "code": "BG-17", "name": "Razgrad" }, { "code": "BG-18", "name": "Ruse" }, { "code": "BG-27", "name": "Shumen" }, { "code": "BG-19", "name": "Silistra" }, { "code": "BG-20", "name": "Sliven" }, { "code": "BG-21", "name": "Smolyan" }, { "code": "BG-23", "name": "Sofia" }, { "code": "BG-22", "name": "Sofia-Grad" }, { "code": "BG-24", "name": "Stara Zagora" }, { "code": "BG-25", "name": "Targovishte" }, { "code": "BG-03", "name": "Varna" }, { "code": "BG-04", "name": "Veliko Tarnovo" }, { "code": "BG-05", "name": "Vidin" }, { "code": "BG-06", "name": "Vratsa" }, { "code": "BG-28", "name": "Yambol" } ] } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/continents/eu" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data/continents" } ] } } ``` #### Continent properties See [list of continents properties](#continents-properties). ## List all countries This API helps you to view all the countries. ```http GET /wp-json/wc/v3/data/countries ``` ```shell curl https://example.com/wp-json/wc/v3/data/countries \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'data/countries' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('data/countries')); ?> ``` ```python print(wcapi.get("data/countries").json()) ``` ```ruby woocommerce.get("data/countries").parsed_response ``` ```json [ { "code": "US", "name": "United States (US)", "states": [ { "code": "AL", "name": "Alabama" }, { "code": "AK", "name": "Alaska" }, { "code": "AZ", "name": "Arizona" }, { "code": "AR", "name": "Arkansas" }, { "code": "CA", "name": "California" }, { "code": "CO", "name": "Colorado" }, { "code": "CT", "name": "Connecticut" }, { "code": "DE", "name": "Delaware" }, { "code": "DC", "name": "District Of Columbia" }, { "code": "FL", "name": "Florida" }, { "code": "GA", "name": "Georgia" }, { "code": "HI", "name": "Hawaii" }, { "code": "ID", "name": "Idaho" }, { "code": "IL", "name": "Illinois" }, { "code": "IN", "name": "Indiana" }, { "code": "IA", "name": "Iowa" }, { "code": "KS", "name": "Kansas" }, { "code": "KY", "name": "Kentucky" }, { "code": "LA", "name": "Louisiana" }, { "code": "ME", "name": "Maine" }, { "code": "MD", "name": "Maryland" }, { "code": "MA", "name": "Massachusetts" }, { "code": "MI", "name": "Michigan" }, { "code": "MN", "name": "Minnesota" }, { "code": "MS", "name": "Mississippi" }, { "code": "MO", "name": "Missouri" }, { "code": "MT", "name": "Montana" }, { "code": "NE", "name": "Nebraska" }, { "code": "NV", "name": "Nevada" }, { "code": "NH", "name": "New Hampshire" }, { "code": "NJ", "name": "New Jersey" }, { "code": "NM", "name": "New Mexico" }, { "code": "NY", "name": "New York" }, { "code": "NC", "name": "North Carolina" }, { "code": "ND", "name": "North Dakota" }, { "code": "OH", "name": "Ohio" }, { "code": "OK", "name": "Oklahoma" }, { "code": "OR", "name": "Oregon" }, { "code": "PA", "name": "Pennsylvania" }, { "code": "RI", "name": "Rhode Island" }, { "code": "SC", "name": "South Carolina" }, { "code": "SD", "name": "South Dakota" }, { "code": "TN", "name": "Tennessee" }, { "code": "TX", "name": "Texas" }, { "code": "UT", "name": "Utah" }, { "code": "VT", "name": "Vermont" }, { "code": "VA", "name": "Virginia" }, { "code": "WA", "name": "Washington" }, { "code": "WV", "name": "West Virginia" }, { "code": "WI", "name": "Wisconsin" }, { "code": "WY", "name": "Wyoming" }, { "code": "AA", "name": "Armed Forces (AA)" }, { "code": "AE", "name": "Armed Forces (AE)" }, { "code": "AP", "name": "Armed Forces (AP)" } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/countries/us" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data/countries" } ] } } ] ``` #### Countries properties | Attribute | Type | Description | | --------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------- | | `code` | string | ISO3166 alpha-2 country code. `READ-ONLY` | | `name` | string | Full name of country. `READ-ONLY` | | `states` | array | List of states in this country. See [Countries - States properties](#countries---states-properties) `READ-ONLY` | ##### Countries - States properties | Attribute | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `code` | string | State code. `READ-ONLY` | | `name` | string | Full name of state. `READ-ONLY` | ## Retrieve country data This API lets you retrieve and view a country data. ```http GET /wp-json/wc/v3/data/countries/ ``` ```shell curl https://example.com/wp-json/wc/v3/data/countries/br \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'data/countries/br' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('data/countries/br')); ?> ``` ```python print(wcapi.get("data/countries/br").json()) ``` ```ruby woocommerce.get("data/countries/br").parsed_response ``` ```json { "code": "BR", "name": "Brazil", "states": [ { "code": "AC", "name": "Acre" }, { "code": "AL", "name": "Alagoas" }, { "code": "AP", "name": "Amapá" }, { "code": "AM", "name": "Amazonas" }, { "code": "BA", "name": "Bahia" }, { "code": "CE", "name": "Ceará" }, { "code": "DF", "name": "Distrito Federal" }, { "code": "ES", "name": "Espírito Santo" }, { "code": "GO", "name": "Goiás" }, { "code": "MA", "name": "Maranhão" }, { "code": "MT", "name": "Mato Grosso" }, { "code": "MS", "name": "Mato Grosso do Sul" }, { "code": "MG", "name": "Minas Gerais" }, { "code": "PA", "name": "Pará" }, { "code": "PB", "name": "Paraíba" }, { "code": "PR", "name": "Paraná" }, { "code": "PE", "name": "Pernambuco" }, { "code": "PI", "name": "Piauí" }, { "code": "RJ", "name": "Rio de Janeiro" }, { "code": "RN", "name": "Rio Grande do Norte" }, { "code": "RS", "name": "Rio Grande do Sul" }, { "code": "RO", "name": "Rondônia" }, { "code": "RR", "name": "Roraima" }, { "code": "SC", "name": "Santa Catarina" }, { "code": "SP", "name": "São Paulo" }, { "code": "SE", "name": "Sergipe" }, { "code": "TO", "name": "Tocantins" } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/countries/br" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data/countries" } ] } } ``` #### Country properties See [list of countries properties](#countries-properties). ## List all currencies This API helps you to view all the currencies. ```http GET /wp-json/wc/v3/data/currencies ``` ```shell curl https://example.com/wp-json/wc/v3/data/currencies \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'data/currencies' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('data/currencies')); ?> ``` ```python print(wcapi.get("data/currencies").json()) ``` ```ruby woocommerce.get("data/currencies").parsed_response ``` ```json [ { "code": "BTC", "name": "Bitcoin", "symbol": "฿", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/currencies/BTC" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data/currencies" } ] } }, { "code": "EUR", "name": "Euro", "symbol": "€", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/currencies/EUR" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data/currencies" } ] } }, { "code": "USD", "name": "United States (US) dollar", "symbol": "$", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/currencies/USD" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data/currencies" } ] } } ] ``` #### Currencies properties | Attribute | Type | Description | | --------- | ------ | ---------------------------------------------------------------- | | `code` | string | ISO4217 currency code. `READ-ONLY` | | `name` | string | Full name of currency. `READ-ONLY` | | `symbol` | string | Currency symbol. `READ-ONLY` | ## Retrieve currency data This API lets you retrieve and view a currency data. ```http GET /wp-json/wc/v3/data/currencies/ ``` ```shell curl https://example.com/wp-json/wc/v3/data/currencies/brl \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'data/currencies/brl' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('data/currencies/brl')); ?> ``` ```python print(wcapi.get("data/currencies/brl").json()) ``` ```ruby woocommerce.get("data/currencies/brl").parsed_response ``` ```json { "code": "BRL", "name": "Brazilian real", "symbol": "R$", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/currencies/BRL" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data/currencies" } ] } } ``` #### Currency properties See [list of currencies properties](#currencies-properties). ## Retrieve current currency This API lets you retrieve and view store's current currency data. ```http GET /wp-json/wc/v3/data/currencies/current ``` ```shell curl https://example.com/wp-json/wc/v3/data/currencies/current \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'data/currencies/current' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('data/currencies/current')); ?> ``` ```python print(wcapi.get("data/currencies/current").json()) ``` ```ruby woocommerce.get("data/currencies/current").parsed_response ``` ```json { "code": "USD", "name": "United States (US) dollar", "symbol": "$", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/data/currencies/USD" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/data/currencies" } ] } } ``` #### Currency properties See [list of currencies properties](#currencies-properties). --- ## REST API v3 *Source: apis/rest-api/v3/index.mdx* import DocCardList from '@theme/DocCardList'; The current and recommended version of the WooCommerce REST API. Use `/wp-json/wc/v3/` endpoints for all new integrations. --- ## Order actions *Source: apis/rest-api/v3/order-actions.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Order actions The order actions API allows you to perform specific actions with existing orders like you can from the Edit Order screen in the web app. _Note: currently only some actions are available, other actions will be introduced at a later time._ ## Send order details to customer This endpoint allows you to trigger an email to the customer with the details of their order. In case the order doesn't yet have a billing email set, you can specify an email recipient. However, if the order does have an existing billing email, this will return an error, unless you also specify that the existing email should be overwritten by using the `force_email_update` parameter. ```http POST /wp-json/wc/v3/orders//actions/send_order_details ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/orders/723/actions/send_order_details \ -u consumer_key:consumer_secret \ -d '{ "email": "somebody@example.com", "force_email_update": true }' ``` ```javascript const data = { email: 'somebody@example.com', force_email_update: true, }; WooCommerce.post( 'orders/723/actions/send_order_details', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'somebody@example.com', 'force_email_update' => true, ]; print_r($woocommerce->post('orders/723/actions/send_order_details', $data)); ?> ``` ```python data = { "email": "somebody@example.com", "force_email_update": true } print(wcapi.post("orders/723/actions/send_order_details", data).json()) ``` ```ruby data = { "email": "somebody@example.com", "force_email_update": true } woocommerce.post("orders/723/actions/send_order_details", data).parsed_response ``` ```json { "message": "Billing email updated to somebody@example.com. Order details sent to somebody@example.com, via REST API." } ``` ```json { "code": "woocommerce_rest_missing_email", "message": "Order does not have an email address.", "data": { "status": 400 } } ``` ## Send order notification email to customer This endpoint allows you to trigger an email to a customer about the status of their order. This is similar to the [`send_order_details`](#send-order-details-to-customer) endpoint, but allows you to specify which email template to send, based on which email templates are relevant to the order. For example, an order that is on hold has the `customer_on_hold_order` template available. A completed order that also has a partial refund has both the `customer_completed_order` and `customer_refunded_order` templates available. Specifying the `customer_invoice` template is the same as using the `send_order_details` endpoint. ```http POST /wp-json/wc/v3/orders//actions/send_email ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/orders/723/actions/send_email \ -u consumer_key:consumer_secret \ -d '{ "template_id": "customer_completed_order", "email": "somebody@example.com", "force_email_update": true }' ``` ```javascript const data = { template_id: 'customer_completed_order', email: 'somebody@example.com', force_email_update: true, }; WooCommerce.post( 'orders/723/actions/send_email', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'customer_completed_order', 'email' => 'somebody@example.com', 'force_email_update' => true, ]; print_r($woocommerce->post('orders/723/actions/send_email', $data)); ?> ``` ```python data = { "template_id": "customer_completed_order", "email": "somebody@example.com", "force_email_update": true } print(wcapi.post("orders/723/actions/send_email", data).json()) ``` ```ruby data = { "template_id": "customer_completed_order", "email": "somebody@example.com", "force_email_update": true } woocommerce.post("orders/723/actions/send_email", data).parsed_response ``` ```json { "message": "Billing email updated to somebody@example.com. Email template "Completed order" sent to somebody@example.com, via REST API." } ``` ```json { "code": "woocommerce_rest_invalid_email_template", "message": "customer_completed_order is not a valid template for this order.", "data": { "status": 400 } } ``` ## Get available email templates for an order This endpoint allows you to retrieve a list of email templates that are available for the specified order. You can also get this data embedded in the response for the [`orders` endpoint](../orders#list-all-orders). ```http GET /wp-json/wc/v3/orders//actions/email_templates ``` ```shell curl -X GET https://example.com/wp-json/wc/v3/orders/723/actions/email_templates \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'orders/723/actions/email_templates' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('orders/723/actions/email_templates')); ?> ``` ```python print(wcapi.get("orders/723/actions/email_templates").json()) ``` ```ruby woocommerce.post("orders/723/actions/email_templates").parsed_response ``` ```json [ { "id": "customer_completed_order", "title": "Completed order", "description": "Order complete emails are sent to customers when their orders are marked completed and usually indicate that their orders have been shipped." }, { "id": "customer_invoice", "title": "Order details", "description": "Order detail emails can be sent to customers containing their order information and payment links." } ] ``` --- ## Order notes *Source: apis/rest-api/v3/order-notes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Order notes The order notes API allows you to create, view, and delete individual order notes. Order notes are added by administrators and programmatically to store data about an order, or order events. ## Order note properties | Attribute | Type | Description | | ------------------ | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `author` | string | Order note author. `READ-ONLY` | | `date_created` | date-time | The date the order note was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the order note was created, as GMT. `READ-ONLY` | | `note` | string | Order note content. `MANDATORY` | | `customer_note` | boolean | If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only. Default is `false`. | | `added_by_user` | boolean | If true, this note will be attributed to the current user. If false, the note will be attributed to the system. Default is `false`. | ## Create an order note This API helps you to create a new note for an order. ```http POST /wp-json/wc/v3/orders//notes ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/orders/723/notes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "note": "Order ok!!!" }' ``` ```javascript const data = { note: 'Order ok!!!', }; WooCommerce.post( 'orders/723/notes', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'Order ok!!!' ]; print_r($woocommerce->post('orders/723/notes', $data)); ?> ``` ```python data = { "note": "Order ok!!!" } print(wcapi.post("orders/723/notes", data).json()) ``` ```ruby data = { note: "Order ok!!!" } woocommerce.post("orders/723/notes", data).parsed_response ``` ```json { "id": 281, "author": "system", "date_created": "2017-03-21T16:46:41", "date_created_gmt": "2017-03-21T19:46:41", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes/281" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } } ``` ## Retrieve an order note This API lets you retrieve and view a specific note from an order. ```http GET /wp-json/wc/v3/orders//notes/ ``` ```shell curl https://example.com/wp-json/wc/v3/orders/723/notes/281 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'orders/723/notes/281' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('orders/723/notes/281')); ?> ``` ```python print(wcapi.get("orders/723/notes/281").json()) ``` ```ruby woocommerce.get("orders/723/notes/281").parsed_response ``` ```json { "id": 281, "author": "system", "date_created": "2017-03-21T16:46:41", "date_created_gmt": "2017-03-21T19:46:41", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes/281" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } } ``` ## List all order notes This API helps you to view all the notes from an order. ```http GET /wp-json/wc/v3/orders//notes ``` ```shell curl https://example.com/wp-json/wc/v3/orders/723/notes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'orders/723/notes' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('orders/723/notes')); ?> ``` ```python print(wcapi.get("orders/723/notes").json()) ``` ```ruby woocommerce.get("orders/723/notes").parsed_response ``` ```json [ { "id": 281, "author": "system", "date_created": "2017-03-21T16:46:41", "date_created_gmt": "2017-03-21T19:46:41", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes/281" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } }, { "id": 280, "author": "system", "date_created": "2017-03-21T16:16:58", "date_created_gmt": "2017-03-21T19:16:58", "note": "Order status changed from On hold to Completed.", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes/280" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } }, { "id": 279, "author": "system", "date_created": "2017-03-21T16:16:46", "date_created_gmt": "2017-03-21T19:16:46", "note": "Awaiting BACS payment Order status changed from Pending payment to On hold.", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes/279" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ---------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `type` | string | Limit result to customers or internal notes. Options: `any`, `customer` and `internal`. Default is `any`. | ## Delete an order note This API helps you delete an order note. ```http DELETE /wp-json/wc/v3/orders//notes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/orders/723/notes/281?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'orders/723/notes/281', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('orders/723/notes/281', ['force' => true])); ?> ``` ```python print(wcapi.delete("orders/723/notes/281", params={"force": True}).json()) ``` ```ruby woocommerce.delete("orders/723/notes/281", force: true).parsed_response ``` ```json { "id": 281, "author": "system", "date_created": "2017-03-21T16:46:41", "date_created_gmt": "2017-03-21T19:46:41", "note": "Order ok!!!", "customer_note": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes/281" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/notes" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | --- ## Order refunds *Source: apis/rest-api/v3/order-refunds.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Order refunds The order refunds API allows you to create, view, and delete individual refunds, based on an existing order. ## Order refund properties | Attribute | Type | Description | | ------------------ | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | date-time | The date the order refund was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the order refund was created, as GMT. `READ-ONLY` | | `amount` | string | Total refund amount. Optional. If this parameter is provided, it will take precedence over line item totals, even when total of line items does not matches with this amount. | | `reason` | string | Reason for refund. | | `refunded_by` | integer | User ID of user who created the refund. | | `refunded_payment` | boolean | If the payment was refunded via the API. See `api_refund`. `READ-ONLY` | | `meta_data` | array | Meta data. See [Order refund - Meta data properties](#order-refund---meta-data-properties) | | `line_items` | array | Line items data. See [Order refund - Line items properties](#order-refund---line-items-properties) | | `tax_lines` | array | Tax lines data. See [Order refund - Tax lines properties](#order-refund---tax-lines-properties) `READ-ONLY` | | `shipping_lines` | array | Shipping lines data. See [Order refund - Shipping lines properties](#order-refund---shipping-lines-properties) | | `fee_lines` | array | Fee lines data. See [Order refund - Fee lines properties](#order-refund---fee-lines-properties) | | `api_refund` | boolean | When true, the payment gateway API is used to generate the refund. Default is `true`. `WRITE-ONLY` | | `api_restock` | boolean | When true, the selected line items are restocked Default is `true`. `WRITE-ONLY` | | `compute_totals` | boolean | When true, the server computes per-line refund amounts from quantities and validates the request against the order's refund history. Available since WooCommerce 11.1. See [Server-computed refunds](#server-computed-refunds-compute_totals). Default is `false`. `WRITE-ONLY` | ### Order refund - Meta data properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------- | | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ### Order refund - Line items properties | Attribute | Type | Description | | -------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `name` | string | Product name. | | `product_id` | integer | Product ID. | | `variation_id` | integer | Variation ID, if applicable. | | `quantity` | integer | Quantity ordered. | | `tax_class` | string | Tax class of product. | | `subtotal` | string | Line subtotal (before discounts). | | `subtotal_tax` | string | Line subtotal tax (before discounts). `READ-ONLY` | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). `READ-ONLY` | | `taxes` | array | Line taxes. See [Order refund line item - Taxes properties](#order-refund-line-item---taxes-properties) `READ-ONLY` | | `meta_data` | array | Meta data. See [Order refund - Meta data properties](#order-refund---meta-data-properties) | | `sku` | string | Product SKU. `READ-ONLY` | | `price` | string | Product price. `READ-ONLY` | #### Order refund line item - Taxes properties | Attribute | Type | Description | | ---------- | ------- | ------------------------------------------------------- | | `id` | integer | Tax rate ID. `READ-ONLY` | | `total` | string | Tax total. `READ-ONLY` | | `subtotal` | string | Tax subtotal. `READ-ONLY` | ### Order refund - Tax lines properties | Attribute | Type | Description | | -------------------- | ------- | ---------------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `rate_code` | string | Tax rate code. `READ-ONLY` | | `rate_id` | integer | Tax rate ID. `READ-ONLY` | | `label` | string | Tax rate label. `READ-ONLY` | | `compound` | boolean | Whether or not this is a compound tax rate. `READ-ONLY` | | `tax_total` | string | Tax total (not including shipping taxes). `READ-ONLY` | | `shipping_tax_total` | string | Shipping tax total. `READ-ONLY` | | `meta_data` | array | Meta data. See [Order refund - Meta data properties](#order-refund---meta-data-properties) | ### Order refund - Shipping lines properties | Attribute | Type | Description | | -------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `method_title` | string | Shipping method name. | | `method_id` | string | Shipping method ID. | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). `READ-ONLY` | | `taxes` | array | Line taxes. See [Order refund - Tax lines properties](#order-refund---tax-lines-properties) `READ-ONLY` | | `meta_data` | array | Meta data. See [Order refund - Meta data properties](#order-refund---meta-data-properties) | ### Order refund - Fee lines properties | Attribute | Type | Description | | ------------ | ------- | ----------------------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `name` | string | Fee name. | | `tax_class` | string | Tax class of fee. | | `tax_status` | string | Tax status of fee. Options: `taxable` and `none`. | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). `READ-ONLY` | | `taxes` | array | Line taxes. See [Order refund - Tax lines properties](#order-refund---tax-lines-properties) `READ-ONLY` | | `meta_data` | array | Meta data. See [Order refund - Meta data properties](#order-refund---meta-data-properties) | ## Create a refund This API helps you to create a new refund for an order. ```http POST /wp-json/wc/v3/orders//refunds ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/orders/723/refunds \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "amount": "30", "line_items": [ { "id": "111", "refund_total": 10, "refund_tax": [ { "id": "222", "refund_total": 20 } ] } }' ``` ```javascript const data = { amount: '30', line_items: [ { id: '111', refund_total: 10, refund_tax: [ { id: '222', refund_total: 20, }, ], }, ], }; WooCommerce.post( 'orders/723/refunds', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php '30', 'line_items' => [ [ 'id' => '111', 'refund_total' => 10, 'refund_tax' => [ [ 'id' => '222', 'amount' => 20 ] ] ] ] ]; print_r($woocommerce->post('orders/723/refunds', $data)); ?> ``` ```python data = { "amount": "30", "line_items": [ { "id": "111", "refund_total": 10, "refund_tax": [ { "id": "222", "refund_total": 20 } ] } ] } print(wcapi.post("orders/723/refunds", data).json()) ``` ```ruby data = { amount: "30", line_items: [ { id: "111", refund_total: 10, refund_tax: [ { id: "222", refund_total: 20 } ] } ] } woocommerce.post("orders/723/refunds", data).parsed_response ``` ```json { "id": 726, "date_created": "2017-03-21T17:07:11", "date_created_gmt": "2017-03-21T20:07:11", "amount": "10.00", "reason": "", "refunded_by": 1, "refunded_payment": false, "meta_data": [], "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds/726" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } } ``` #### Line item parameters | Parameter | Type | Description | | -------------- | ------- | -------------------------------------------------------------------------- | | `id` | integer | The ID of the line item in the order. | | `refund_total` | number | The amount to refund for this line item, excluding taxes. | | `refund_tax` | array | Refunds for tax rates. See [Refund tax parameters](#refund-tax-parameters) | #### Refund tax parameters | Parameter | Type | Description | | -------------- | ------- | ----------------------------------------------- | | `id` | integer | The ID of the tax rate. | | `refund_total` | number | The amount of tax to refund for this line item. | ### Server-computed refunds (compute_totals) Available since WooCommerce 11.1. Set `compute_totals` to `true` to have the server compute per-line refund amounts instead of supplying them. Line items may then send only `id` and `quantity`: the server derives each line's refund amount from the order's stored unit prices and taxes, caps it to the line's remaining refundable amount, and validates the whole request against the order's refund history. The refund `amount` is derived from the line items unless supplied explicitly. ```shell curl -X POST https://example.com/wp-json/wc/v3/orders/723/refunds \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "compute_totals": true, "line_items": [ { "id": 111, "quantity": 1 } ] }' ``` ```json { "id": 726, "date_created": "2026-08-06T17:07:11", "date_created_gmt": "2026-08-06T20:07:11", "amount": "110.00", "reason": "", "refunded_by": 1, "refunded_payment": false, "meta_data": [], "line_items": [ ] } ``` #### Line item parameters with compute_totals | Parameter | Type | Description | | -------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | integer | The ID of the line item in the order. Each line item may appear only once per request. | | `quantity` | integer | The number of units to refund. The server computes the amount for the quantity. | | `refund_total` | number | Optional explicit amount for this line. Tax-inclusive when `refund_tax` is omitted (the server splits the tax portion out); tax-exclusive when `refund_tax` is supplied. | | `refund_tax` | array | Optional explicit tax refunds. See [Refund tax parameters](#refund-tax-parameters) | When `amount` is supplied together with `compute_totals`, it must be at least the computed line items total and no more than the order's remaining refundable amount. Requests that exceed what is still refundable are rejected with HTTP 400 or 422 and error codes such as `woocommerce_rest_invalid_refund_amount`, `woocommerce_rest_refund_exceeds_remaining`, `woocommerce_rest_quantity_exceeds_refundable`, and `woocommerce_rest_duplicate_line_item`. ::::warning Older stores silently ignore compute_totals Stores running WooCommerce below 11.1 drop the unknown `compute_totals` parameter and process the request with the classic behavior. A quantity-only request then creates a refund of `0.00` instead of the intended amount. Before sending computed-form requests, verify that the store supports the flag: - Send `OPTIONS /wp-json/wc/v3/orders//refunds` and check that `compute_totals` is listed in the endpoint arguments, or - Probe `POST /wp-json/wc/v3/orders//refunds/preview`, which returns `rest_no_route` with HTTP 404 on stores without support. :::: ## Preview a refund Available since WooCommerce 11.1. This API computes the totals a refund would have, without creating it. The preview uses the same calculation engine as refund creation with `compute_totals`, so clients do not have to replicate tax, rounding, and currency-precision logic. It requires the same capability as creating a refund. ```http POST /wp-json/wc/v3/orders//refunds/preview ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/orders/723/refunds/preview \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "line_items": [ { "line_item_id": 111, "quantity": 1 } ] }' ``` ```json { "breakdown": { "products": { "items": [ { "id": 111, "name": "T-Shirt", "quantity": 1, "subtotal": "100.00", "tax": "10.00", "total": "110.00", "product_id": 93 } ], "subtotal": "100.00", "tax": "10.00", "total": "110.00" }, "shipping": { "items": [], "subtotal": "0.00", "tax": "0.00", "total": "0.00" }, "fees": { "items": [], "subtotal": "0.00", "tax": "0.00", "total": "0.00" } }, "subtotal": "100.00", "tax": "10.00", "total": "110.00", "max_refundable": "110.00" } ``` #### Preview line item parameters | Parameter | Type | Description | | -------------- | ------- | --------------------------------------------------------------------------------------------------------------------- | | `line_item_id` | integer | The ID of the line item in the order. Note that the preview keys lines by `line_item_id` where the create endpoint uses `id`. | | `quantity` | integer | The number of units to preview. Shipping and fee lines must use a quantity of 1. | | `refund_total` | number | Optional explicit tax-inclusive amount for this line. | #### Preview response properties | Attribute | Type | Description | | ---------------- | ------ | -------------------------------------------------------------------------------------------------------- | | `breakdown` | object | Refund breakdown by item type: `products`, `shipping`, and `fees`, each with `items`, `subtotal`, `tax`, and `total`. `READ-ONLY` | | `subtotal` | string | Grand subtotal of the refund preview, excluding tax. `READ-ONLY` | | `tax` | string | Grand tax total of the refund preview. `READ-ONLY` | | `total` | string | Grand total of the refund preview, tax-inclusive. `READ-ONLY` | | `max_refundable` | string | Maximum refundable amount remaining on the order. `READ-ONLY` | Invalid requests return the same errors as creation with `compute_totals`, for example `woocommerce_rest_invalid_refund_amount` for a non-positive total and `woocommerce_rest_preview_exceeds_max_refundable` with HTTP 422 when the preview exceeds the remaining refundable amount. ## Retrieve a refund This API lets you retrieve and view a specific refund from an order. ```http GET /wp-json/wc/v3/orders//refunds/ ``` ```shell curl https://example.com/wp-json/wc/v3/orders/723/refunds/726 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'orders/723/refunds/726' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('orders/723/refunds/726')); ?> ``` ```python print(wcapi.get("orders/723/refunds/726").json()) ``` ```ruby woocommerce.get("orders/723/refunds/726").parsed_response ``` ```json { "id": 726, "date_created": "2017-03-21T17:07:11", "date_created_gmt": "2017-03-21T20:07:11", "amount": "10.00", "reason": "", "refunded_by": 1, "refunded_payment": false, "meta_data": [], "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds/726" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------- | | `dp` | string | Number of decimal points to use in each resource. | ## List all refunds This API helps you to view all the refunds from an order. Note: To view a list of refunds from your store, regardless of order, check out the [refunds endpoint](../refunds). ```http GET /wp-json/wc/v3/orders//refunds ``` ```shell curl https://example.com/wp-json/wc/v3/orders/723/refunds \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'orders/723/refunds' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('orders/723/refunds')); ?> ``` ```python print(wcapi.get("orders/723/refunds").json()) ``` ```ruby woocommerce.get("orders/723/refunds").parsed_response ``` ```json [ { "id": 726, "date_created": "2017-03-21T17:07:11", "date_created_gmt": "2017-03-21T20:07:11", "amount": "10.00", "reason": "", "refunded_by": 1, "refunded_payment": false, "meta_data": [], "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds/726" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } }, { "id": 724, "date_created": "2017-03-21T16:55:37", "date_created_gmt": "2017-03-21T19:55:37", "amount": "9.00", "reason": "", "refunded_by": 1, "refunded_payment": false, "meta_data": [], "line_items": [ { "id": 314, "name": "Woo Album #2", "product_id": 87, "variation_id": 0, "quantity": -1, "tax_class": "", "subtotal": "-9.00", "subtotal_tax": "0.00", "total": "-9.00", "total_tax": "0.00", "taxes": [], "meta_data": [ { "id": 2076, "key": "_refunded_item_id", "value": "311" } ], "sku": "", "price": -9 } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds/724" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `modified`, `id`, `include`, `title` and `slug`. Default is `date`. | | `parent` | array | Limit result set to those of particular parent IDs. | | `parent_exclude` | array | Limit result set to all items except those of a particular parent ID. | | `dp` | integer | Number of decimal points to use in each resource. Default is `2`. | ## Delete a refund This API helps you delete an order refund. ```http DELETE /wp-json/wc/v3/orders//refunds/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/orders/723/refunds/726?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'orders/723/refunds/726', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('orders/723/refunds/726', ['force' => true])); ?> ``` ```python print(wcapi.delete("orders/723/refunds/726", params={"force": True}).json()) ``` ```ruby woocommerce.delete("orders/723/refunds/726", force: true).parsed_response ``` ```json { "id": 726, "date_created": "2017-03-21T17:07:11", "date_created_gmt": "2017-03-21T20:07:11", "amount": "10.00", "reason": "", "refunded_by": 1, "refunded_payment": false, "meta_data": [], "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds/726" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | --- ## Orders *Source: apis/rest-api/v3/orders.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Orders The orders API allows you to create, view, update, and delete individual, or a batch, of orders. ## Order properties | Attribute | Type | Description | | ---------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `parent_id` | integer | Parent order ID. | | `number` | string | Order number. `READ-ONLY` | | `order_key` | string | Order key. `READ-ONLY` | | `created_via` | string | Shows where the order was created. It can only be set during order creation and cannot be modified afterward. | | `version` | string | Version of WooCommerce which last updated the order. `READ-ONLY` | | `status` | string | Order status. Options: `pending`, `processing`, `on-hold`, `completed`, `cancelled`, `refunded`, `failed` and `trash`. Default is `pending`. | | `currency` | string | Currency the order was created with, in ISO format. Options: `AED`, `AFN`, `ALL`, `AMD`, `ANG`, `AOA`, `ARS`, `AUD`, `AWG`, `AZN`, `BAM`, `BBD`, `BDT`, `BGN`, `BHD`, `BIF`, `BMD`, `BND`, `BOB`, `BRL`, `BSD`, `BTC`, `BTN`, `BWP`, `BYR`, `BZD`, `CAD`, `CDF`, `CHF`, `CLP`, `CNY`, `COP`, `CRC`, `CUC`, `CUP`, `CVE`, `CZK`, `DJF`, `DKK`, `DOP`, `DZD`, `EGP`, `ERN`, `ETB`, `EUR`, `FJD`, `FKP`, `GBP`, `GEL`, `GGP`, `GHS`, `GIP`, `GMD`, `GNF`, `GTQ`, `GYD`, `HKD`, `HNL`, `HRK`, `HTG`, `HUF`, `IDR`, `ILS`, `IMP`, `INR`, `IQD`, `IRR`, `IRT`, `ISK`, `JEP`, `JMD`, `JOD`, `JPY`, `KES`, `KGS`, `KHR`, `KMF`, `KPW`, `KRW`, `KWD`, `KYD`, `KZT`, `LAK`, `LBP`, `LKR`, `LRD`, `LSL`, `LYD`, `MAD`, `MDL`, `MGA`, `MKD`, `MMK`, `MNT`, `MOP`, `MRO`, `MUR`, `MVR`, `MWK`, `MXN`, `MYR`, `MZN`, `NAD`, `NGN`, `NIO`, `NOK`, `NPR`, `NZD`, `OMR`, `PAB`, `PEN`, `PGK`, `PHP`, `PKR`, `PLN`, `PRB`, `PYG`, `QAR`, `RON`, `RSD`, `RUB`, `RWF`, `SAR`, `SBD`, `SCR`, `SDG`, `SEK`, `SGD`, `SHP`, `SLL`, `SOS`, `SRD`, `SSP`, `STD`, `SYP`, `SZL`, `THB`, `TJS`, `TMT`, `TND`, `TOP`, `TRY`, `TTD`, `TWD`, `TZS`, `UAH`, `UGX`, `USD`, `UYU`, `UZS`, `VEF`, `VND`, `VUV`, `WST`, `XAF`, `XCD`, `XOF`, `XPF`, `YER`, `ZAR` and `ZMW`. Default is `USD`. | | `date_created` | date-time | The date the order was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the order was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the order was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the order was last modified, as GMT. `READ-ONLY` | | `discount_total` | string | Total discount amount for the order. `READ-ONLY` | | `discount_tax` | string | Total discount tax amount for the order. `READ-ONLY` | | `shipping_total` | string | Total shipping amount for the order. `READ-ONLY` | | `shipping_tax` | string | Total shipping tax amount for the order. `READ-ONLY` | | `cart_tax` | string | Sum of line item taxes only. `READ-ONLY` | | `total` | string | Grand total. `READ-ONLY` | | `total_tax` | string | Sum of all taxes. `READ-ONLY` | | `prices_include_tax` | boolean | True the prices included tax during checkout. `READ-ONLY` | | `customer_id` | integer | User ID who owns the order. 0 for guests. Default is `0`. | | `customer_ip_address` | string | Customer's IP address. `READ-ONLY` | | `customer_user_agent` | string | User agent of the customer. `READ-ONLY` | | `customer_note` | string | Note left by customer during checkout. | | `billing` | object | Billing address. See [Order - Billing properties](#order---billing-properties) | | `shipping` | object | Shipping address. See [Order - Shipping properties](#order---shipping-properties) | | `payment_method` | string | Payment method ID. | | `payment_method_title` | string | Payment method title. | | `transaction_id` | string | Unique transaction ID. | | `date_paid` | date-time | The date the order was paid, in the site's timezone. `READ-ONLY` | | `date_paid_gmt` | date-time | The date the order was paid, as GMT. `READ-ONLY` | | `date_completed` | date-time | The date the order was completed, in the site's timezone. `READ-ONLY` | | `date_completed_gmt` | date-time | The date the order was completed, as GMT. `READ-ONLY` | | `cart_hash` | string | MD5 hash of cart items to ensure orders are not modified. `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | | `line_items` | array | Line items data. See [Order - Line items properties](#order---line-items-properties) | | `tax_lines` | array | Tax lines data. See [Order - Tax lines properties](#order---tax-lines-properties) `READ-ONLY` | | `shipping_lines` | array | Shipping lines data. See [Order - Shipping lines properties](#order---shipping-lines-properties) | | `fee_lines` | array | Fee lines data. See [Order - Fee lines properties](#order---fee-lines-properties) | | `coupon_lines` | array | Coupons line data. See [Order - Coupon lines properties](#order---coupon-lines-properties) | | `refunds` | array | List of refunds. See [Order - Refunds properties](#order---refunds-properties) `READ-ONLY` | | `set_paid` | boolean | Define if the order is paid. It will set the status to processing and reduce stock items. Default is `false`. `WRITE-ONLY` | ### Order - Billing properties | Attribute | Type | Description | | ------------ | ------ | ---------------------------------------------------- | | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1 | | `address_2` | string | Address line 2 | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | Country code in ISO 3166-1 alpha-2 format. | | `email` | string | Email address. | | `phone` | string | Phone number. | ### Order - Shipping properties | Attribute | Type | Description | | ------------ | ------ | ---------------------------------------------------- | | `first_name` | string | First name. | | `last_name` | string | Last name. | | `company` | string | Company name. | | `address_1` | string | Address line 1 | | `address_2` | string | Address line 2 | | `city` | string | City name. | | `state` | string | ISO code or name of the state, province or district. | | `postcode` | string | Postal code. | | `country` | string | Country code in ISO 3166-1 alpha-2 format. | ### Order - Meta data properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------- | | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ### Order - Line items properties | Attribute | Type | Description | | -------------- | ------- | --------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `name` | string | Product name. | | `parent_name` | string or null | Parent product name if the product is a variation; otherwise `null`. | | `product_id` | integer | Product ID. | | `variation_id` | integer | Variation ID, if applicable. | | `quantity` | integer | Quantity ordered. | | `tax_class` | string | Slug of the tax class of product. | | `subtotal` | string | Line subtotal (before discounts). | | `subtotal_tax` | string | Line subtotal tax (before discounts). `READ-ONLY` | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). `READ-ONLY` | | `taxes` | array | Line taxes. See [Order - Tax lines properties](#order---tax-lines-properties) `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | | `sku` | string | Product SKU. `READ-ONLY` | | `price` | string | Product price. `READ-ONLY` | ### Order - Tax lines properties | Attribute | Type | Description | | -------------------- | ------- | ------------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `rate_code` | string | Tax rate code. `READ-ONLY` | | `rate_id` | integer | Tax rate ID. `READ-ONLY` | | `label` | string | Tax rate label. `READ-ONLY` | | `compound` | boolean | Whether or not this is a compound tax rate. `READ-ONLY` | | `tax_total` | string | Tax total (not including shipping taxes). `READ-ONLY` | | `shipping_tax_total` | string | Shipping tax total. `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | ### Order - Shipping lines properties | Attribute | Type | Description | | -------------- | ------- | --------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `method_title` | string | Shipping method name. | | `method_id` | string | Shipping method ID. | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). `READ-ONLY` | | `taxes` | array | Line taxes. See [Order - Tax lines properties](#order---tax-lines-properties) `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | ### Order - Fee lines properties | Attribute | Type | Description | | ------------ | ------- | --------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `name` | string | Fee name. | | `tax_class` | string | Tax class of fee. | | `tax_status` | string | Tax status of fee. Options: `taxable` and `none`. | | `total` | string | Line total (after discounts). | | `total_tax` | string | Line total tax (after discounts). `READ-ONLY` | | `taxes` | array | Line taxes. See [Order - Tax lines properties](#order---tax-lines-properties) `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | ### Order - Coupon lines properties | Attribute | Type | Description | | -------------- | ------- | -------------------------------------------------------------------------- | | `id` | integer | Item ID. `READ-ONLY` | | `code` | string | Coupon code. | | `discount` | string | Discount total. `READ-ONLY` | | `discount_tax` | string | Discount total tax. `READ-ONLY` | | `meta_data` | array | Meta data. See [Order - Meta data properties](#order---meta-data-properties) | ### Order - Refunds properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------------- | | `id` | integer | Refund ID. `READ-ONLY` | | `reason` | string | Refund reason. `READ-ONLY` | | `total` | string | Refund total. `READ-ONLY` | ## Create an order This API helps you to create a new order. ```http POST /wp-json/wc/v3/orders ``` > Example of create a paid order: ```shell curl -X POST https://example.com/wp-json/wc/v3/orders \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": true, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 93, "quantity": 2 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "10.00" } ] }' ``` ```javascript const data = { payment_method: 'bacs', payment_method_title: 'Direct Bank Transfer', set_paid: true, billing: { first_name: 'John', last_name: 'Doe', address_1: '969 Market', address_2: '', city: 'San Francisco', state: 'CA', postcode: '94103', country: 'US', email: 'john.doe@example.com', phone: '(555) 555-5555', }, shipping: { first_name: 'John', last_name: 'Doe', address_1: '969 Market', address_2: '', city: 'San Francisco', state: 'CA', postcode: '94103', country: 'US', }, line_items: [ { product_id: 93, quantity: 2, }, { product_id: 22, variation_id: 23, quantity: 1, }, ], shipping_lines: [ { method_id: 'flat_rate', method_title: 'Flat Rate', total: '10.00', }, ], }; WooCommerce.post( 'orders', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'bacs', 'payment_method_title' => 'Direct Bank Transfer', 'set_paid' => true, 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ], 'line_items' => [ [ 'product_id' => 93, 'quantity' => 2 ], [ 'product_id' => 22, 'variation_id' => 23, 'quantity' => 1 ] ], 'shipping_lines' => [ [ 'method_id' => 'flat_rate', 'method_title' => 'Flat Rate', 'total' => '10.00' ] ] ]; print_r($woocommerce->post('orders', $data)); ?> ``` ```python data = { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": True, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 93, "quantity": 2 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "10.00" } ] } print(wcapi.post("orders", data).json()) ``` ```ruby data = { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", set_paid: true, billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 93, quantity: 2 }, { product_id: 22, variation_id: 23, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "10.00" } ] } woocommerce.post("orders", data).parsed_response ``` ```json { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "processing", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:28:08", "date_modified_gmt": "2017-03-22T19:28:08", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": null, "date_completed_gmt": null, "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders" } ] } } ``` ## Retrieve an order This API lets you retrieve and view a specific order. ```http GET /wp-json/wc/v3/orders/ ``` ```shell curl https://example.com/wp-json/wc/v3/orders/727 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'orders/727' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('orders/727')); ?> ``` ```python print(wcapi.get("orders/727").json()) ``` ```ruby woocommerce.get("orders/727").parsed_response ``` ```json { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "processing", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:28:08", "date_modified_gmt": "2017-03-22T19:28:08", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": null, "date_completed_gmt": null, "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------- | | `dp` | string | Number of decimal points to use in each resource. | ## List all orders This API helps you to view all the orders. ```http GET /wp-json/wc/v3/orders ``` ```shell curl https://example.com/wp-json/wc/v3/orders \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'orders' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('orders')); ?> ``` ```python print(wcapi.get("orders").json()) ``` ```ruby woocommerce.get("orders").parsed_response ``` ```json [ { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "processing", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:28:08", "date_modified_gmt": "2017-03-22T19:28:08", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": null, "date_completed_gmt": null, "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" }, { "id": 13109, "key": "_order_stock_reduced", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders" } ], "email_templates": [ { "embeddable": true, "href": "http://example.com/wp-json/wc/v3/orders/723/actions/email_templates" } ] } }, { "id": 723, "parent_id": 0, "number": "723", "order_key": "wc_order_58d17c18352", "created_via": "checkout", "version": "3.0.0", "status": "completed", "currency": "USD", "date_created": "2017-03-21T16:16:00", "date_created_gmt": "2017-03-21T19:16:00", "date_modified": "2017-03-21T16:54:51", "date_modified_gmt": "2017-03-21T19:54:51", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "0.00", "total": "39.00", "total_tax": "0.00", "prices_include_tax": false, "customer_id": 26, "customer_ip_address": "127.0.0.1", "customer_user_agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:52.0) gecko/20100101 firefox/52.0", "customer_note": "", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(11) 1111-1111" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "payment_method": "bacs", "payment_method_title": "Direct bank transfer", "transaction_id": "", "date_paid": null, "date_paid_gmt": null, "date_completed": "2017-03-21T16:54:51", "date_completed_gmt": "2017-03-21T19:54:51", "cart_hash": "5040ce7273261e31d8bcf79f9be3d279", "meta_data": [ { "id": 13023, "key": "_download_permissions_granted", "value": "yes" } ], "line_items": [ { "id": 311, "name": "Woo Album #2", "product_id": 87, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "9.00", "subtotal_tax": "0.00", "total": "9.00", "total_tax": "0.00", "taxes": [], "meta_data": [], "sku": "", "price": 9 }, { "id": 313, "name": "Woo Ninja", "product_id": 34, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "20.00", "subtotal_tax": "0.00", "total": "20.00", "total_tax": "0.00", "taxes": [], "meta_data": [], "sku": "", "price": 20 } ], "tax_lines": [], "shipping_lines": [ { "id": 312, "method_title": "Flat rate", "method_id": "flat_rate:25", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [ { "id": 2057, "key": "Items", "value": "Woo Album #2 × 1" } ] } ], "fee_lines": [], "coupon_lines": [], "refunds": [ { "id": 726, "refund": "", "total": "-10.00" }, { "id": 724, "refund": "", "total": "-9.00" } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders" } ], "email_templates": [ { "embeddable": true, "href": "http://example.com/wp-json/wc/v3/orders/723/actions/email_templates" } ], "customer": [ { "href": "https://example.com/wp-json/wc/v3/customers/26" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ----------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `modified_after` | string | Limit response to resources modified after a given ISO8601 compliant date. | | `modified_before` | string | Limit response to resources modified after a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Whether to interpret dates as GMT when limiting response by published or modified date. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `modified`, `id`, `include`, `title` and `slug`. Default is `date`. | | `parent` | array | Limit result set to those of particular parent IDs. | | `parent_exclude` | array | Limit result set to all items except those of a particular parent ID. | | `status` | array | Limit result set to orders assigned a specific status. Options: `any`, `pending`, `processing`, `on-hold`, `completed`, `cancelled`, `refunded`, `failed` and `trash`. Default is `any`. | | `customer` | integer | Limit result set to orders assigned a specific customer. | | `product` | integer | Limit result set to orders assigned a specific product. | | `dp` | integer | Number of decimal points to use in each resource. Default is `2`. | | `created_via` | string | Limit result set to orders created via specific sources (e.g. checkout, store-api). Multiple options can be provided as a comma-separated list. | ## Update an Order This API lets you make changes to an order. ### HTTP Request ```http PUT /wp-json/wc/v3/orders/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/orders/727 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "status": "completed" }' ``` ```javascript const data = { status: 'completed', }; WooCommerce.put( 'orders/727', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'completed' ]; print_r($woocommerce->put('orders/727', $data)); ?> ``` ```python data = { "status": "completed" } print(wcapi.put("orders/727", data).json()) ``` ```ruby data = { status: "completed" } woocommerce.put("orders/727", data).parsed_response ``` ```json { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "completed", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:30:35", "date_modified_gmt": "2017-03-22T19:30:35", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": "2017-03-22T16:30:35", "date_completed_gmt": "2017-03-22T19:30:35", "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" }, { "id": 13109, "key": "_order_stock_reduced", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders" } ] } } ``` ## Delete an order This API helps you delete an order. ```http DELETE /wp-json/wc/v3/orders/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/orders/727?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'orders/727', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('orders/727', ['force' => true])); ?> ``` ```python print(wcapi.delete("orders/727", params={"force": True}).json()) ``` ```ruby woocommerce.delete("orders/727", force: true).parsed_response ``` ```json { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "completed", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:30:35", "date_modified_gmt": "2017-03-22T19:30:35", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": "2017-03-22T16:30:35", "date_completed_gmt": "2017-03-22T19:30:35", "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" }, { "id": 13109, "key": "_order_stock_reduced", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ----------------------------------------------------------------------- | | `force` | string | Use `true` whether to permanently delete the order, Default is `false`. | ## Batch update orders This API helps you to batch create, update and delete multiple orders. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/orders/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/orders/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 79, "quantity": 1 }, { "product_id": 93, "quantity": 1 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "30.00" } ] }, { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": true, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 22, "variation_id": 23, "quantity": 1 }, { "product_id": 22, "variation_id": 24, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "20.00" } ] } ], "update": [ { "id": 727, "shipping_methods": "Local Delivery" } ], "delete": [ 723 ] }' ``` ```javascript const data = { create: [ { payment_method: 'bacs', payment_method_title: 'Direct Bank Transfer', billing: { first_name: 'John', last_name: 'Doe', address_1: '969 Market', address_2: '', city: 'San Francisco', state: 'CA', postcode: '94103', country: 'US', email: 'john.doe@example.com', phone: '(555) 555-5555', }, shipping: { first_name: 'John', last_name: 'Doe', address_1: '969 Market', address_2: '', city: 'San Francisco', state: 'CA', postcode: '94103', country: 'US', }, line_items: [ { product_id: 79, quantity: 1, }, { product_id: 93, quantity: 1, }, { product_id: 22, variation_id: 23, quantity: 1, }, ], shipping_lines: [ { method_id: 'flat_rate', method_title: 'Flat Rate', total: '30.00', }, ], }, { payment_method: 'bacs', payment_method_title: 'Direct Bank Transfer', set_paid: true, billing: { first_name: 'John', last_name: 'Doe', address_1: '969 Market', address_2: '', city: 'San Francisco', state: 'CA', postcode: '94103', country: 'US', email: 'john.doe@example.com', phone: '(555) 555-5555', }, shipping: { first_name: 'John', last_name: 'Doe', address_1: '969 Market', address_2: '', city: 'San Francisco', state: 'CA', postcode: '94103', country: 'US', }, line_items: [ { product_id: 22, variation_id: 23, quantity: 1, }, { product_id: 22, variation_id: 24, quantity: 1, }, ], shipping_lines: [ { method_id: 'flat_rate', method_title: 'Flat Rate', total: '20.00', }, ], }, ], update: [ { id: 727, shipping_methods: 'Local Delivery', }, ], delete: [ 723 ], }; WooCommerce.post( 'orders/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'payment_method' => 'bacs', 'payment_method_title' => 'Direct Bank Transfer', 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ], 'line_items' => [ [ 'product_id' => 79, 'quantity' => 1 ], [ 'product_id' => 93, 'quantity' => 1 ], [ 'product_id' => 22, 'variation_id' => 23, 'quantity' => 1 ] ], 'shipping_lines' => [ [ 'method_id' => 'flat_rate', 'method_title' => 'Flat Rate', 'total' => '30.00' ] ] ], [ 'payment_method' => 'bacs', 'payment_method_title' => 'Direct Bank Transfer', 'set_paid' => true, 'billing' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US', 'email' => 'john.doe@example.com', 'phone' => '(555) 555-5555' ], 'shipping' => [ 'first_name' => 'John', 'last_name' => 'Doe', 'address_1' => '969 Market', 'address_2' => '', 'city' => 'San Francisco', 'state' => 'CA', 'postcode' => '94103', 'country' => 'US' ], 'line_items' => [ [ 'product_id' => 22, 'variation_id' => 23, 'quantity' => 1 ], [ 'product_id' => 22, 'variation_id' => 24, 'quantity' => 1 ] ], 'shipping_lines' => [ [ 'method_id' => 'flat_rate', 'method_title' => 'Flat Rate', 'total' => '20.00' ] ] ] ], 'update' => [ [ 'id' => 727, 'shipping_methods' => 'Local Delivery' ] ], 'delete' => [ 723 ] ]; print_r($woocommerce->post('orders/batch', $data)); ?> ``` ```python data = { "create": [ { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 79, "quantity": 1 }, { "product_id": 93, "quantity": 1 }, { "product_id": 22, "variation_id": 23, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "30.00" } ] }, { "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "set_paid": True, "billing": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "line_items": [ { "product_id": 22, "variation_id": 23, "quantity": 1 }, { "product_id": 22, "variation_id": 24, "quantity": 1 } ], "shipping_lines": [ { "method_id": "flat_rate", "method_title": "Flat Rate", "total": "20.00" } ] } ], "update": [ { "id": 727, "shipping_methods": "Local Delivery" } ], "delete": [ 723 ] } print(wcapi.post("orders/batch", data).json()) ``` ```ruby data = { create: [ { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 79, quantity: 1 }, { product_id: 93, quantity: 1 }, { product_id: 22, variation_id: 23, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "30.00" } ] }, { payment_method: "bacs", payment_method_title: "Direct Bank Transfer", set_paid: true, billing: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US", email: "john.doe@example.com", phone: "(555) 555-5555" }, shipping: { first_name: "John", last_name: "Doe", address_1: "969 Market", address_2: "", city: "San Francisco", state: "CA", postcode: "94103", country: "US" }, line_items: [ { product_id: 22, variation_id: 23, quantity: 1 }, { product_id: 22, variation_id: 24, quantity: 1 } ], shipping_lines: [ { method_id: "flat_rate", method_title: "Flat Rate", total: "20.00" } ] } ], update: [ { id: 727, shipping_methods: "Local Delivery" } ], delete: [ 723 ] } woocommerce.post("orders/batch", data).parsed_response ``` ```json { "create": [ { "id": 728, "parent_id": 0, "number": "728", "order_key": "wc_order_58d2d18e580", "created_via": "rest-api", "version": "3.0.0", "status": "pending", "currency": "USD", "date_created": "2017-03-22T16:33:34", "date_created_gmt": "2017-03-22T19:33:34", "date_modified": "2017-03-22T16:33:34", "date_modified_gmt": "2017-03-22T19:33:34", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "30.00", "shipping_tax": "0.00", "cart_tax": "2.25", "total": "62.25", "total_tax": "2.25", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": null, "date_paid_gmt": null, "date_completed": null, "date_completed_gmt": null, "cart_hash": "", "meta_data": [], "line_items": [ { "id": 319, "name": "Woo Logo", "product_id": 79, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "15.00", "subtotal_tax": "1.13", "total": "15.00", "total_tax": "1.13", "taxes": [ { "id": 75, "total": "1.125", "subtotal": "1.125" } ], "meta_data": [], "sku": "", "price": 15 }, { "id": 320, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "3.00", "subtotal_tax": "0.23", "total": "3.00", "total_tax": "0.23", "taxes": [ { "id": 75, "total": "0.225", "subtotal": "0.225" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 321, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2133, "key": "pa_color", "value": "black" }, { "id": 2134, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 323, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "2.25", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 322, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "30.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/728" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders" } ] } }, { "id": 729, "parent_id": 0, "number": "729", "order_key": "wc_order_58d2d196171", "created_via": "rest-api", "version": "3.0.0", "status": "processing", "currency": "USD", "date_created": "2017-03-22T16:33:42", "date_created_gmt": "2017-03-22T19:33:42", "date_modified": "2017-03-22T16:33:47", "date_modified_gmt": "2017-03-22T19:33:47", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "20.00", "shipping_tax": "0.00", "cart_tax": "2.40", "total": "54.40", "total_tax": "2.40", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:33:47", "date_paid_gmt": "2017-03-22T19:33:47", "date_completed": null, "date_completed_gmt": null, "cart_hash": "", "meta_data": [ { "id": 13198, "key": "_download_permissions_granted", "value": "yes" } ], "line_items": [ { "id": 324, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2153, "key": "pa_color", "value": "black" }, { "id": 2154, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 }, { "id": 325, "name": "Ship Your Idea – Color: Green, Size: S Test", "product_id": 22, "variation_id": 24, "quantity": 1, "tax_class": "", "subtotal": "20.00", "subtotal_tax": "1.50", "total": "20.00", "total_tax": "1.50", "taxes": [ { "id": 75, "total": "1.5", "subtotal": "1.5" } ], "meta_data": [ { "id": 2164, "key": "pa_color", "value": "green" }, { "id": 2165, "key": "size", "value": "S Test" } ], "sku": "", "price": 20 } ], "tax_lines": [ { "id": 327, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "2.40", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 326, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "20.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/729" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders" } ] } } ], "update": [ { "id": 727, "parent_id": 0, "number": "727", "order_key": "wc_order_58d2d042d1d", "created_via": "rest-api", "version": "3.0.0", "status": "completed", "currency": "USD", "date_created": "2017-03-22T16:28:02", "date_created_gmt": "2017-03-22T19:28:02", "date_modified": "2017-03-22T16:30:35", "date_modified_gmt": "2017-03-22T19:30:35", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "1.35", "total": "29.35", "total_tax": "1.35", "prices_include_tax": false, "customer_id": 0, "customer_ip_address": "", "customer_user_agent": "", "customer_note": "", "billing": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US", "email": "john.doe@example.com", "phone": "(555) 555-5555" }, "shipping": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "969 Market", "address_2": "", "city": "San Francisco", "state": "CA", "postcode": "94103", "country": "US" }, "payment_method": "bacs", "payment_method_title": "Direct Bank Transfer", "transaction_id": "", "date_paid": "2017-03-22T16:28:08", "date_paid_gmt": "2017-03-22T19:28:08", "date_completed": "2017-03-22T16:30:35", "date_completed_gmt": "2017-03-22T19:30:35", "cart_hash": "", "meta_data": [ { "id": 13106, "key": "_download_permissions_granted", "value": "yes" }, { "id": 13109, "key": "_order_stock_reduced", "value": "yes" } ], "line_items": [ { "id": 315, "name": "Woo Single #1", "product_id": 93, "variation_id": 0, "quantity": 2, "tax_class": "", "subtotal": "6.00", "subtotal_tax": "0.45", "total": "6.00", "total_tax": "0.45", "taxes": [ { "id": 75, "total": "0.45", "subtotal": "0.45" } ], "meta_data": [], "sku": "", "price": 3 }, { "id": 316, "name": "Ship Your Idea – Color: Black, Size: M Test", "product_id": 22, "variation_id": 23, "quantity": 1, "tax_class": "", "subtotal": "12.00", "subtotal_tax": "0.90", "total": "12.00", "total_tax": "0.90", "taxes": [ { "id": 75, "total": "0.9", "subtotal": "0.9" } ], "meta_data": [ { "id": 2095, "key": "pa_color", "value": "black" }, { "id": 2096, "key": "size", "value": "M Test" } ], "sku": "Bar3", "price": 12 } ], "tax_lines": [ { "id": 318, "rate_code": "US-CA-STATE TAX", "rate_id": 75, "label": "State Tax", "compound": false, "tax_total": "1.35", "shipping_tax_total": "0.00", "meta_data": [] } ], "shipping_lines": [ { "id": 317, "method_title": "Flat Rate", "method_id": "flat_rate", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [] } ], "fee_lines": [], "coupon_lines": [], "refunds": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/727" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders" } ] } } ], "delete": [ { "id": 723, "parent_id": 0, "number": "723", "order_key": "wc_order_58d17c18352", "created_via": "checkout", "version": "3.0.0", "status": "completed", "currency": "USD", "date_created": "2017-03-21T16:16:00", "date_created_gmt": "2017-03-21T19:16:00", "date_modified": "2017-03-21T16:54:51", "date_modified_gmt": "2017-03-21T19:54:51", "discount_total": "0.00", "discount_tax": "0.00", "shipping_total": "10.00", "shipping_tax": "0.00", "cart_tax": "0.00", "total": "39.00", "total_tax": "0.00", "prices_include_tax": false, "customer_id": 26, "customer_ip_address": "127.0.0.1", "customer_user_agent": "mozilla/5.0 (x11; ubuntu; linux x86_64; rv:52.0) gecko/20100101 firefox/52.0", "customer_note": "", "billing": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR", "email": "joao.silva@example.com", "phone": "(11) 1111-1111" }, "shipping": { "first_name": "João", "last_name": "Silva", "company": "", "address_1": "Av. Brasil, 432", "address_2": "", "city": "Rio de Janeiro", "state": "RJ", "postcode": "12345-000", "country": "BR" }, "payment_method": "bacs", "payment_method_title": "Direct bank transfer", "transaction_id": "", "date_paid": null, "date_paid_gmt": null, "date_completed": "2017-03-21T16:54:51", "date_completed_gmt": "2017-03-21T19:54:51", "cart_hash": "5040ce7273261e31d8bcf79f9be3d279", "meta_data": [ { "id": 13023, "key": "_download_permissions_granted", "value": "yes" } ], "line_items": [ { "id": 311, "name": "Woo Album #2", "product_id": 87, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "9.00", "subtotal_tax": "0.00", "total": "9.00", "total_tax": "0.00", "taxes": [], "meta_data": [], "sku": "", "price": 9 }, { "id": 313, "name": "Woo Ninja", "product_id": 34, "variation_id": 0, "quantity": 1, "tax_class": "", "subtotal": "20.00", "subtotal_tax": "0.00", "total": "20.00", "total_tax": "0.00", "taxes": [], "meta_data": [], "sku": "", "price": 20 } ], "tax_lines": [], "shipping_lines": [ { "id": 312, "method_title": "Flat rate", "method_id": "flat_rate:25", "total": "10.00", "total_tax": "0.00", "taxes": [], "meta_data": [ { "id": 2057, "key": "Items", "value": "Woo Album #2 × 1" } ] } ], "fee_lines": [], "coupon_lines": [], "refunds": [ { "id": 726, "refund": "", "total": "-10.00" }, { "id": 724, "refund": "", "total": "-9.00" } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders" } ], "customer": [ { "href": "https://example.com/wp-json/wc/v3/customers/26" } ] } } ] } ``` --- ## Payment gateways *Source: apis/rest-api/v3/payment-gateways.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Payment gateways The payment gateways API allows you to view, and update individual payment gateways. Results are not paginated - all gateways will be returned. ## Payment gateway properties | Attribute | Type | Description | | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------- | | `id` | string | Payment gateway ID. `READ-ONLY` | | `title` | string | Payment gateway title on checkout. | | `description` | string | Payment gateway description on checkout. | | `order` | integer | Payment gateway sort order. | | `enabled` | boolean | Payment gateway enabled status. | | `method_title` | string | Payment gateway method title. `READ-ONLY` | | `method_description` | string | Payment gateway method description. `READ-ONLY` | | `method_supports` | array | Supported features for this payment gateway. `READ-ONLY` | | `settings` | object | Payment gateway settings. See [Payment gateway - Settings properties](#payment-gateway---settings-properties) | ### Payment gateway - Settings properties | Attribute | Type | Description | | ------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | string | A unique identifier for the setting. `READ-ONLY` | | `label` | string | A human readable label for the setting used in interfaces. `READ-ONLY` | | `description` | string | A human readable description for the setting used in interfaces. `READ-ONLY` | | `type` | string | Type of setting. Options: `text`, `email`, `number`, `color`, `password`, `textarea`, `select`, `multiselect`, `radio`, `image_width` and `checkbox`. `READ-ONLY` | | `value` | string | Setting value. | | `default` | string | Default value for the setting. `READ-ONLY` | | `tip` | string | Additional help text shown to the user about the setting. `READ-ONLY` | | `placeholder` | string | Placeholder text to be displayed in text inputs. `READ-ONLY` | ## Retrieve a payment gateway This API lets you retrieve and view a specific payment gateway. ```http GET /wp-json/wc/v3/payment_gateways/ ``` ```shell curl https://example.com/wp-json/wc/v3/payment_gateways/bacs \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'payment_gateways/bacs' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('payment_gateways/bacs')); ?> ``` ```python print(wcapi.get("payment_gateways/bacs").json()) ``` ```ruby woocommerce.get("payment_gateways/bacs").parsed_response ``` ```json { "id": "bacs", "title": "Direct bank transfer", "description": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "order": 0, "enabled": true, "method_title": "BACS", "method_description": "Allows payments by BACS, more commonly known as direct bank/wire transfer.", "method_supports": [ "products" ], "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Direct bank transfer", "default": "Direct bank transfer", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "instructions": { "id": "instructions", "label": "Instructions", "description": "Instructions that will be added to the thank you page and emails.", "type": "textarea", "value": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "default": "", "tip": "Instructions that will be added to the thank you page and emails.", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways/bacs" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways" } ] } } ``` ## List all payment gateways This API helps you to view all the payment gateways. ```http GET /wp-json/wc/v3/payment_gateways ``` ```shell curl https://example.com/wp-json/wc/v3/payment_gateways \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'payment_gateways' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('payment_gateways')); ?> ``` ```python print(wcapi.get("payment_gateways").json()) ``` ```ruby woocommerce.get("payment_gateways").parsed_response ``` ```json [ { "id": "bacs", "title": "Direct bank transfer", "description": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "order": 0, "enabled": true, "method_title": "BACS", "method_description": "Allows payments by BACS, more commonly known as direct bank/wire transfer.", "method_supports": [ "products" ], "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Direct bank transfer", "default": "Direct bank transfer", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "instructions": { "id": "instructions", "label": "Instructions", "description": "Instructions that will be added to the thank you page and emails.", "type": "textarea", "value": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "default": "", "tip": "Instructions that will be added to the thank you page and emails.", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways/bacs" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways" } ] } }, { "id": "cheque", "title": "Check payments", "description": "Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.", "order": 1, "enabled": false, "method_title": "Check payments", "method_description": "Allows check payments. Why would you take checks in this day and age? Well you probably wouldn't but it does allow you to make test purchases for testing order emails and the 'success' pages etc.", "method_supports": [ "products" ], "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Check payments", "default": "Check payments", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "instructions": { "id": "instructions", "label": "Instructions", "description": "Instructions that will be added to the thank you page and emails.", "type": "textarea", "value": "", "default": "", "tip": "Instructions that will be added to the thank you page and emails.", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways/cheque" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways" } ] } }, { "id": "cod", "title": "Cash on delivery", "description": "Pay with cash upon delivery.", "order": 2, "enabled": false, "method_title": "Cash on delivery", "method_description": "Have your customers pay with cash (or by other means) upon delivery.", "method_supports": [ "products" ], "settings": { "title": { "id": "title", "label": "Title", "description": "Payment method description that the customer will see on your checkout.", "type": "text", "value": "Cash on delivery", "default": "Cash on delivery", "tip": "Payment method description that the customer will see on your checkout.", "placeholder": "" }, "instructions": { "id": "instructions", "label": "Instructions", "description": "Instructions that will be added to the thank you page.", "type": "textarea", "value": "", "default": "Pay with cash upon delivery.", "tip": "Instructions that will be added to the thank you page.", "placeholder": "" }, "enable_for_methods": { "id": "enable_for_methods", "label": "Enable for shipping methods", "description": "If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.", "type": "multiselect", "value": "", "default": "", "tip": "If COD is only available for certain methods, set it up here. Leave blank to enable for all methods.", "placeholder": "", "options": { "flat_rate": "Flat rate", "free_shipping": "Free shipping", "local_pickup": "Local pickup" } }, "enable_for_virtual": { "id": "enable_for_virtual", "label": "Accept COD if the order is virtual", "description": "", "type": "checkbox", "value": "yes", "default": "yes", "tip": "", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways/cod" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways" } ] } }, { "id": "paypal", "title": "PayPal", "description": "Pay via PayPal; you can pay with your credit card if you don't have a PayPal account.", "order": 3, "enabled": true, "method_title": "PayPal", "method_description": "PayPal Standard sends customers to PayPal to enter their payment information. PayPal IPN requires fsockopen/cURL support to update order statuses after payment. Check the system status page for more details.", "method_supports": [ "products", "refunds" ], "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "PayPal", "default": "PayPal", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "email": { "id": "email", "label": "PayPal email", "description": "Please enter your PayPal email address; this is needed in order to take payment.", "type": "email", "value": "me@example.com", "default": "me@example.com", "tip": "Please enter your PayPal email address; this is needed in order to take payment.", "placeholder": "you@youremail.com" }, "testmode": { "id": "testmode", "label": "Enable PayPal sandbox", "description": "PayPal sandbox can be used to test payments. Sign up for a developer account.", "type": "checkbox", "value": "yes", "default": "no", "tip": "PayPal sandbox can be used to test payments. Sign up for a developer account.", "placeholder": "" }, "debug": { "id": "debug", "label": "Enable logging", "description": "Log PayPal events, such as IPN requests, inside /var/www/woocommerce/wp-content/uploads/wc-logs/paypal-de01f7c6894774e7ac8e4207bb8bac2f.log", "type": "checkbox", "value": "yes", "default": "no", "tip": "Log PayPal events, such as IPN requests, inside /var/www/woocommerce/wp-content/uploads/wc-logs/paypal-de01f7c6894774e7ac8e4207bb8bac2f.log", "placeholder": "" }, "receiver_email": { "id": "receiver_email", "label": "Receiver email", "description": "If your main PayPal email differs from the PayPal email entered above, input your main receiver email for your PayPal account here. This is used to validate IPN requests.", "type": "email", "value": "me@example.com", "default": "", "tip": "If your main PayPal email differs from the PayPal email entered above, input your main receiver email for your PayPal account here. This is used to validate IPN requests.", "placeholder": "you@youremail.com" }, "identity_token": { "id": "identity_token", "label": "PayPal identity token", "description": "Optionally enable \"Payment Data Transfer\" (Profile > Profile and Settings > My Selling Tools > Website Preferences) and then copy your identity token here. This will allow payments to be verified without the need for PayPal IPN.", "type": "text", "value": "", "default": "", "tip": "Optionally enable \"Payment Data Transfer\" (Profile > Profile and Settings > My Selling Tools > Website Preferences) and then copy your identity token here. This will allow payments to be verified without the need for PayPal IPN.", "placeholder": "" }, "invoice_prefix": { "id": "invoice_prefix", "label": "Invoice prefix", "description": "Please enter a prefix for your invoice numbers. If you use your PayPal account for multiple stores ensure this prefix is unique as PayPal will not allow orders with the same invoice number.", "type": "text", "value": "WC-", "default": "WC-", "tip": "Please enter a prefix for your invoice numbers. If you use your PayPal account for multiple stores ensure this prefix is unique as PayPal will not allow orders with the same invoice number.", "placeholder": "" }, "send_shipping": { "id": "send_shipping", "label": "Send shipping details to PayPal instead of billing.", "description": "PayPal allows us to send one address. If you are using PayPal for shipping labels you may prefer to send the shipping address rather than billing.", "type": "checkbox", "value": "no", "default": "no", "tip": "PayPal allows us to send one address. If you are using PayPal for shipping labels you may prefer to send the shipping address rather than billing.", "placeholder": "" }, "address_override": { "id": "address_override", "label": "Enable \"address_override\" to prevent address information from being changed.", "description": "PayPal verifies addresses therefore this setting can cause errors (we recommend keeping it disabled).", "type": "checkbox", "value": "no", "default": "no", "tip": "PayPal verifies addresses therefore this setting can cause errors (we recommend keeping it disabled).", "placeholder": "" }, "paymentaction": { "id": "paymentaction", "label": "Payment action", "description": "Choose whether you wish to capture funds immediately or authorize payment only.", "type": "select", "value": "sale", "default": "sale", "tip": "Choose whether you wish to capture funds immediately or authorize payment only.", "placeholder": "", "options": { "sale": "Capture", "authorization": "Authorize" } }, "page_style": { "id": "page_style", "label": "Page style", "description": "Optionally enter the name of the page style you wish to use. These are defined within your PayPal account. This affects classic PayPal checkout screens.", "type": "text", "value": "", "default": "", "tip": "Optionally enter the name of the page style you wish to use. These are defined within your PayPal account. This affects classic PayPal checkout screens.", "placeholder": "Optional" }, "image_url": { "id": "image_url", "label": "Image url", "description": "Optionally enter the URL to a 150x50px image displayed as your logo in the upper left corner of the PayPal checkout pages.", "type": "text", "value": "", "default": "", "tip": "Optionally enter the URL to a 150x50px image displayed as your logo in the upper left corner of the PayPal checkout pages.", "placeholder": "Optional" }, "api_username": { "id": "api_username", "label": "API username", "description": "Get your API credentials from PayPal.", "type": "text", "value": "", "default": "", "tip": "Get your API credentials from PayPal.", "placeholder": "Optional" }, "api_password": { "id": "api_password", "label": "API password", "description": "Get your API credentials from PayPal.", "type": "password", "value": "", "default": "", "tip": "Get your API credentials from PayPal.", "placeholder": "Optional" }, "api_signature": { "id": "api_signature", "label": "API signature", "description": "Get your API credentials from PayPal.", "type": "text", "value": "", "default": "", "tip": "Get your API credentials from PayPal.", "placeholder": "Optional" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways/paypal" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways" } ] } } ] ``` ## Update a payment gateway This API lets you make changes to a payment gateway. ```http PUT /wp-json/wc/v3/payment_gateways/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/payment_gateways/bacs \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "enabled": false }' ``` ```javascript const data = { enabled: true, }; WooCommerce.put( 'payment_gateways/bacs', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php true ]; print_r($woocommerce->put('payment_gateways/bacs', $data)); ?> ``` ```python data = { "enabled": True } print(wcapi.put("payment_gateways/bacs", data).json()) ``` ```ruby data = { enabled: true } woocommerce.put("payment_gateways/bacs", data).parsed_response ``` ```json { "id": "bacs", "title": "Direct bank transfer", "description": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "order": 0, "enabled": false, "method_title": "BACS", "method_description": "Allows payments by BACS, more commonly known as direct bank/wire transfer.", "method_supports": [ "products" ], "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Direct bank transfer", "default": "Direct bank transfer", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "instructions": { "id": "instructions", "label": "Instructions", "description": "Instructions that will be added to the thank you page and emails.", "type": "textarea", "value": "Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won't be shipped until the funds have cleared in our account.", "default": "", "tip": "Instructions that will be added to the thank you page and emails.", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways/bacs" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/payment_gateways" } ] } } ``` --- ## Product attribute terms *Source: apis/rest-api/v3/product-attribute-terms.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product attribute terms The product attribute terms API allows you to create, view, update, and delete individual, or a batch, of attribute terms. ## Product attribute term properties | Attribute | Type | Description | | ------------- | ------- | ---------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Term name. `MANDATORY` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `description` | string | HTML description of the resource. | | `menu_order` | integer | Menu order, used to custom sort the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ## Create an attribute term This API helps you to create a new product attribute term. ```http POST /wp-json/wc/v3/products/attributes//terms ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/products/attributes/2/terms \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "XXS" }' ``` ```javascript const data = { name: 'XXS', }; WooCommerce.post( 'products/attributes/2/terms', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'XXS' ]; print_r($woocommerce->post('products/attributes/2/terms', $data)); ?> ``` ```python data = { "name": "XXS" } print(wcapi.post("products/attributes/2/terms", data).json()) ``` ```ruby data = { name: "XXS" } woocommerce.post("products/attributes/2/terms", data).parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } } ``` ## Retrieve an attribute term This API lets you retrieve a product attribute term by ID. ```http GET /wp-json/wc/v3/products/attributes//terms/ ``` ```shell curl https://example.com/wp-json/wc/v3/products/attributes/2/terms/23 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/attributes/2/terms/23' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/attributes/2/terms/23')); ?> ``` ```python print(wcapi.get("products/attributes/2/terms/23").json()) ``` ```ruby woocommerce.get("products/attributes/2/terms/23").parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } } ``` ## List all attribute terms This API lets you retrieve all terms from a product attribute. ```http GET /wp-json/wc/v3/products/attributes//terms ``` ```shell curl https://example.com/wp-json/wc/v3/products/attributes/2/terms \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/attributes/2/terms' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/attributes/2/terms')); ?> ``` ```python print(wcapi.get("products/attributes/2/terms").json()) ``` ```ruby woocommerce.get("products/attributes/2/terms").parsed_response ``` ```json [ { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } }, { "id": 22, "name": "XS", "slug": "xs", "description": "", "menu_order": 2, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/22" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } }, { "id": 17, "name": "S", "slug": "s", "description": "", "menu_order": 3, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/17" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } }, { "id": 18, "name": "M", "slug": "m", "description": "", "menu_order": 4, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/18" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } }, { "id": 19, "name": "L", "slug": "l", "description": "", "menu_order": 5, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/19" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } }, { "id": 20, "name": "XL", "slug": "xl", "description": "", "menu_order": 6, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/20" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } }, { "id": 21, "name": "XXL", "slug": "xxl", "description": "", "menu_order": 7, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/21" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `exclude` | array | Ensure result set excludes specific ids. | | `include` | array | Limit result set to specific ids. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `asc`. | | `orderby` | string | Sort collection by resource attribute. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. Default is `name`. | | `hide_empty` | boolean | Whether to hide resources not assigned to any products. Default is `false`. | | `parent` | integer | Limit result set to resources assigned to a specific parent. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update an attribute term This API lets you make changes to a product attribute term. ```http PUT /wp-json/wc/v3/products/attributes//terms/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/products/attributes/2/terms/23 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "XXS" }' ``` ```javascript const data = { name: 'XXS', }; WooCommerce.put( 'products/attributes/2/terms/23', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'XXS' ]; print_r($woocommerce->put('products/attributes/2/terms/23', $data)); ?> ``` ```python data = { "name": "XXS" } print(wcapi.put("products/attributes/2/terms/23", data).json()) ``` ```ruby data = { name: "XXS" } woocommerce.put("products/attributes/2/terms/23", data).parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } } ``` ## Delete an attribute term This API helps you delete a product attribute term. ```http DELETE /wp-json/wc/v3/products/attributes//terms/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/products/attributes/2/terms/23?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'products/attributes/2/terms/23', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('products/attributes/2/terms/23', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/attributes/2/terms/23", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/attributes/2/terms/23", force: true).parsed_response ``` ```json { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update attribute terms This API helps you to batch create, update and delete multiple product attribute terms. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/products/attributes//terms/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/products/attributes//terms/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "XXS" }, { "name": "S" } ], "update": [ { "id": 19, "menu_order": 6 } ], "delete": [ 21, 20 ] }' ``` ```javascript const data = { create: [ { name: 'XXS', }, { name: 'S', }, ], update: [ { id: 19, menu_order: 6, }, ], delete: [ 21, 20 ], }; WooCommerce.post( 'products/attributes/2/terms/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'name' => 'XXS' ], [ 'name' => 'S' ] ], 'update' => [ [ 'id' => 19, 'menu_order' => 6 ] ], 'delete' => [ 21, 20 ] ]; print_r($woocommerce->post('products/attributes/2/terms/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "XXS" }, { "name": "S" } ], "update": [ { "id": 19, "menu_order": 6 } ], "delete": [ 21, 20 ] } print(wcapi.post("products/attributes/2/terms/batch", data).json()) ``` ```ruby data = { create: [ { name: "XXS" }, { name: "S" } ], update: [ { id: 19, menu_order: 6 } ], delete: [ 21, 20 ] } woocommerce.post("products/attributes/2/terms/batch", data).parsed_response ``` ```json { "create": [ { "id": 23, "name": "XXS", "slug": "xxs", "description": "", "menu_order": 1, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/23" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } }, { "id": 17, "name": "S", "slug": "s", "description": "", "menu_order": 3, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/17" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } } ], "update": [ { "id": 19, "name": "L", "slug": "l", "description": "", "menu_order": 5, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/19" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } } ], "delete": [ { "id": 21, "name": "XXL", "slug": "xxl", "description": "", "menu_order": 7, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/21" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } }, { "id": 20, "name": "XL", "slug": "xl", "description": "", "menu_order": 6, "count": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms/20" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2/terms" } ] } } ] } ``` --- ## Product attributes *Source: apis/rest-api/v3/product-attributes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product attributes The product attributes API allows you to create, view, update, and delete individual, or a batch, of product attributes. ## Product attribute properties | Attribute | Type | Description | | -------------- | ------- | ------------------------------------------------------------------------------------------------ | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Attribute name. `MANDATORY` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `type` | string | Type of attribute. By default only `select` is supported. | | `order_by` | string | Default sort order. Options: `menu_order`, `name`, `name_num` and `id`. Default is `menu_order`. | | `has_archives` | boolean | Enable/Disable attribute archives. Default is `false`. | ## Create a product attribute This API helps you to create a new product attribute. ```http POST /wp-json/wc/v3/products/attributes ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/products/attributes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true }' ``` ```javascript const data = { name: 'Color', slug: 'pa_color', type: 'select', order_by: 'menu_order', has_archives: true, }; WooCommerce.post( 'products/attributes', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'Color', 'slug' => 'pa_color', 'type' => 'select', 'order_by' => 'menu_order', 'has_archives' => true ]; print_r($woocommerce->post('products/attributes', $data)); ?> ``` ```python data = { "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": True } print(wcapi.post("products/attributes", data).json()) ``` ```ruby data = { name: "Color", slug: "pa_color", type: "select", order_by: "menu_order", has_archives: true } woocommerce.post("products/attributes", data).parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/6" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes" } ] } } ``` ## Retrieve a product attribute This API lets you retrieve and view a specific product attribute by ID. ```http GET /wp-json/wc/v3/products/attributes/ ``` ```shell curl https://example.com/wp-json/wc/v3/products/attributes/1 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/attributes/1' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/attributes/1')); ?> ``` ```python print(wcapi.get("products/attributes/1").json()) ``` ```ruby woocommerce.get("products/attributes/1").parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/6" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes" } ] } } ``` ## List all product attributes This API helps you to view all the product attributes. ```http GET /wp-json/wc/v3/products/attributes ``` ```shell curl https://example.com/wp-json/wc/v3/products/attributes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/attributes' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/attributes')); ?> ``` ```python print(wcapi.get("products/attributes").json()) ``` ```ruby woocommerce.get("products/attributes").parsed_response ``` ```json [ { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/6" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes" } ] } }, { "id": 2, "name": "Size", "slug": "pa_size", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ---------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | ## Update a product attribute This API lets you make changes to a product attribute. ```http PUT /wp-json/wc/v3/products/attributes/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/products/attributes/1 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "order_by": "name" }' ``` ```javascript const data = { order_by: 'name', }; WooCommerce.put( 'products/attributes/1', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'name' ]; print_r($woocommerce->put('products/attributes/1', $data)); ?> ``` ```python data = { "order_by": "name" } print(wcapi.put("products/attributes/1", data).json()) ``` ```ruby data = { order_by: "name" } woocommerce.put("products/attributes/1", data).parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "name", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/6" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes" } ] } } ``` ## Delete a product attribute This API helps you delete a product attribute. ```http DELETE /wp-json/wc/v3/products/attributes/ ``` :::warning This also will delete all terms from the selected attribute. ::: ```shell curl -X DELETE https://example.com/wp-json/wc/v3/products/attributes/1?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'products/attributes/1', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('products/attributes/1', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/attributes/1", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/attributes/1", force: true).parsed_response ``` ```json { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/6" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update product attributes This API helps you to batch create, update and delete multiple product attributes. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/products/attributes/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/products/attributes/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Brand" }, { "name": "Publisher" } ], "update": [ { "id": 2, "order_by": "name" } ], "delete": [ 1 ] }' ``` ```javascript const data = { create: [ { name: 'Brand', }, { name: 'Publisher', }, ], update: [ { id: 2, order_by: 'name', }, ], delete: [ 1 ], }; WooCommerce.post( 'products/attributes/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'name' => 'Brand' ], [ 'name' => 'Publisher' ] ], 'update' => [ [ 'id' => 2, 'order_by' => 'name' ] ], 'delete' => [ 1 ] ]; print_r($woocommerce->post('products/attributes/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Brand" }, { "name": "Publisher" } ], "update": [ { "id": 2, "order_by": "name" } ], "delete": [ 1 ] } print(wcapi.post("products/attributes/batch", data).json()) ``` ```ruby data = { create: [ { name: "Round toe" }, { name: "Flat" } ], update: [ { id: 2, order_by: "name" } ], delete: [ 1 ] } woocommerce.post("products/attributes/batch", data).parsed_response ``` ```json { "create": [ { "id": 7, "name": "Brand", "slug": "pa_brand", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/7" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes" } ] } }, { "id": 8, "name": "Publisher", "slug": "pa_publisher", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/8" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes" } ] } } ], "update": [ { "id": 2, "name": "Size", "slug": "pa_size", "type": "select", "order_by": "menu_order", "has_archives": false, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/2" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes" } ] } } ], "delete": [ { "id": 1, "name": "Color", "slug": "pa_color", "type": "select", "order_by": "menu_order", "has_archives": true, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes/6" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/attributes" } ] } } ] } ``` --- ## Product categories *Source: apis/rest-api/v3/product-categories.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product categories The product categories API allows you to create, view, update, and delete individual, or a batch, of categories. ## Product category properties | Attribute | Type | Description | | ------------- | ------- | ---------------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Category name. `MANDATORY` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `parent` | integer | The ID for the parent of the resource. | | `description` | string | HTML description of the resource. | | `display` | string | Category archive display type. Options: `default`, `products`, `subcategories` and `both`. Default is `default`. | | `image` | object | Image data. See [Product category - Image properties](#product-category---image-properties) | | `menu_order` | integer | Menu order, used to custom sort the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ### Product category - Image properties | Attribute | Type | Description | | ------------------- | --------- | ------------------------------------------------------------------------------------------------------- | | `id` | integer | Image ID. | | `date_created` | date-time | The date the image was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the image was created, as GMT `READ-ONLY` | | `date_modified` | date-time | The date the image was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the image was last modified, as GMT. `READ-ONLY` | | `src` | string | Image URL. | | `name` | string | Image name. | | `alt` | string | Image alternative text. | ## Create a product category This API helps you to create a new product category. ```http POST /wp-json/wc/v3/products/categories ``` > Example of how to create a product category: ```shell curl -X POST https://example.com/wp-json/wc/v3/products/categories \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Clothing", "image": { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" } }' ``` ```javascript const data = { name: 'Clothing', image: { src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg', }, }; WooCommerce.post( 'products/categories', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'Clothing', 'image' => [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg' ] ]; print_r($woocommerce->post('products/categories', $data)); ?> ``` ```python data = { "name": "Clothing", "image": { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" } } print(wcapi.post("products/categories", data).json()) ``` ```ruby data = { name: "Clothing", image: { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" } } woocommerce.post("products/categories", data).parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": { "id": 730, "date_created": "2017-03-23T00:01:07", "date_created_gmt": "2017-03-23T03:01:07", "date_modified": "2017-03-23T00:01:07", "date_modified_gmt": "2017-03-23T03:01:07", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg", "name": "", "alt": "" }, "menu_order": 0, "count": 36, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ] } } ``` ## Retrieve a product category This API lets you retrieve a product category by ID. ```http GET /wp-json/wc/v3/products/categories/ ``` ```shell curl https://example.com/wp-json/wc/v3/products/categories/9 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/categories/9' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/categories/9')); ?> ``` ```python print(wcapi.get("products/categories/9").json()) ``` ```ruby woocommerce.get("products/categories/9").parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": { "id": 730, "date_created": "2017-03-23T00:01:07", "date_created_gmt": "2017-03-23T03:01:07", "date_modified": "2017-03-23T00:01:07", "date_modified_gmt": "2017-03-23T03:01:07", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg", "name": "", "alt": "" }, "menu_order": 0, "count": 36, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ] } } ``` ## List all product categories This API lets you retrieve all product categories. ```http GET /wp-json/wc/v3/products/categories ``` ```shell curl https://example.com/wp-json/wc/v3/products/categories \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/categories' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/categories')); ?> ``` ```python print(wcapi.get("products/categories").json()) ``` ```ruby woocommerce.get("products/categories").parsed_response ``` ```json [ { "id": 15, "name": "Albums", "slug": "albums", "parent": 11, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 4, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/15" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/11" } ] } }, { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": { "id": 730, "date_created": "2017-03-23T00:01:07", "date_created_gmt": "2017-03-23T03:01:07", "date_modified": "2017-03-23T00:01:07", "date_modified_gmt": "2017-03-23T03:01:07", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg", "name": "", "alt": "" }, "menu_order": 0, "count": 36, "_links": { "self": [ { "href": "https://example/wp-json/wc/v3/products/categories/9" } ], "collection": [ { "href": "https://example/wp-json/wc/v3/products/categories" } ] } }, { "id": 10, "name": "Hoodies", "slug": "hoodies", "parent": 9, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 6, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/10" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/9" } ] } }, { "id": 11, "name": "Music", "slug": "music", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 7, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/11" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ] } }, { "id": 12, "name": "Posters", "slug": "posters", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 5, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/12" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ] } }, { "id": 13, "name": "Singles", "slug": "singles", "parent": 11, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 3, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/13" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/11" } ] } }, { "id": 14, "name": "T-shirts", "slug": "t-shirts", "parent": 9, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 6, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/14" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/9" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `exclude` | array | Ensure result set excludes specific ids. | | `include` | array | Limit result set to specific ids. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `asc`. | | `orderby` | string | Sort collection by resource attribute. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. Default is `name`. | | `hide_empty` | boolean | Whether to hide resources not assigned to any products. Default is `false`. | | `parent` | integer | Limit result set to resources assigned to a specific parent. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update a product category This API lets you make changes to a product category. ```http PUT /wp-json/wc/v3/products/categories/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/products/categories/9 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "description": "All kinds of clothes." }' ``` ```javascript const data = { description: 'All kinds of clothes.', }; WooCommerce.put( 'products/categories/9', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'All kinds of clothes.' ]; print_r($woocommerce->put('products/categories/9', $data)); ?> ``` ```python data = { "description": "All kinds of clothes." } print(wcapi.put("products/categories/9", data).json()) ``` ```ruby data = { description: "All kinds of clothes." } woocommerce.put("products/categories/9", data).parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "All kinds of clothes.", "display": "default", "image": { "id": 730, "date_created": "2017-03-23T00:01:07", "date_created_gmt": "2017-03-23T03:01:07", "date_modified": "2017-03-23T00:01:07", "date_modified_gmt": "2017-03-23T03:01:07", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg", "name": "", "alt": "" }, "menu_order": 0, "count": 36, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ] } } ``` ## Delete a product category This API helps you delete a product category. ```http DELETE /wp-json/wc/v3/products/categories/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/products/categories/9?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'products/categories/9', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('products/categories/9', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/categories/9", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/categories/9", force: true).parsed_response ``` ```json { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "All kinds of clothes.", "display": "default", "image": { "id": 730, "date_created": "2017-03-23T00:01:07", "date_created_gmt": "2017-03-23T03:01:07", "date_modified": "2017-03-23T00:01:07", "date_modified_gmt": "2017-03-23T03:01:07", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front.jpg", "name": "", "alt": "" }, "menu_order": 0, "count": 36, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update product categories This API helps you to batch create, update and delete multiple product categories. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/products/categories/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/products/categories/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Albums" }, { "name": "Clothing" } ], "update": [ { "id": 10, "description": "Nice hoodies" } ], "delete": [ 11, 12 ] }' ``` ```javascript const data = { create: [ { name: 'Albums', }, { name: 'Clothing', }, ], update: [ { id: 10, description: 'Nice hoodies', }, ], delete: [ 11, 12 ], }; WooCommerce.post( 'products/categories/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'name' => 'Albums' ], [ 'name' => 'Clothing' ] ], 'update' => [ [ 'id' => 10, 'description' => 'Nice hoodies' ] ], 'delete' => [ 11, 12 ] ]; print_r($woocommerce->post('products/categories/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Albums" }, { "name": "Clothing" } ], "update": [ { "id": 10, "description": "Nice hoodies" } ], "delete": [ 11, 12 ] } print(wcapi.post("products/categories/batch", data).json()) ``` ```ruby data = { create: [ { name: "Albums" }, { name: "Clothing" } ], update: [ { id: 10, description: "Nice hoodies" } ], delete: [ 11, 12 ] } woocommerce.post("products/categories/batch", data).parsed_response ``` ```json { "create": [ { "id": 15, "name": "Albums", "slug": "albums", "parent": 11, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/15" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/11" } ] } }, { "id": 9, "name": "Clothing", "slug": "clothing", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/9" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ] } } ], "update": [ { "id": 10, "name": "Hoodies", "slug": "hoodies", "parent": 9, "description": "Nice hoodies", "display": "default", "image": [], "menu_order": 0, "count": 6, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/10" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/9" } ] } } ], "delete": [ { "id": 11, "name": "Music", "slug": "music", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 7, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/11" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ] } }, { "id": 12, "name": "Posters", "slug": "posters", "parent": 0, "description": "", "display": "default", "image": [], "menu_order": 0, "count": 5, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/categories/12" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/categories" } ] } } ] } ``` --- ## Product custom fields *Source: apis/rest-api/v3/product-custom-fields.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product custom fields The product custom fields API allows you to view the custom field names that have been recorded. ## Custom fields available parameters | Parameter | Type | Description | | ---------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | ## Retrieve product custom field names This API lets you retrieve filtered custom field names. ```http GET /wp-json/wc/v3/products/custom-fields/names ``` ```shell curl https://example.com/wp-json/wc/v3/products/custom-fields/names \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/custom-fields/names' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/custom-fields/names')); ?> ``` ```python print(wcapi.get("products/custom-fields/names").json()) ``` ```ruby woocommerce.get("products/custom-fields/names").parsed_response ``` ```json [ "Custom field 1", "Custom field 2", "Custom field 3", "Custom field 4" ] ``` --- ## Product reviews *Source: apis/rest-api/v3/product-reviews.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product reviews The product reviews API allows you to create, view, update, and delete individual, or a batch, of product reviews. ## Product review properties | Attribute | Type | Description | | ------------------ | ------- | ------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | string | The date the review was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | string | The date the review was created, as GMT. `READ-ONLY` | | `product_id` | integer | Unique identifier for the product that the review belongs to. | | `status` | string | Status of the review. Options: `approved`, `hold`, `spam`, `unspam`, `trash` and `untrash`. Defaults to `approved`. | | `reviewer` | string | Reviewer name. | | `reviewer_email` | string | Reviewer email. | | `review` | string | The content of the review. | | `rating` | integer | Review rating (0 to 5). | | `verified` | boolean | Shows if the reviewer bought the product or not. | ## Create a product review This API helps you to create a new product review. ```http POST /wp-json/wc/v3/products/reviews ``` > Example of how to create a product review: ```shell curl -X POST https://example.com/wp-json/wc/v3/products/reviews \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "product_id": 22, "review": "Nice album!", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "rating": 5 }' ``` ```javascript const data = { product_id: 22, review: 'Nice album!', reviewer: 'John Doe', reviewer_email: 'john.doe@example.com', rating: 5, }; WooCommerce.post( 'products/reviews', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 22, 'review' => 'Nice album!', 'reviewer' => 'John Doe', 'reviewer_email' => 'john.doe@example.com', 'rating' => 5 ]; print_r($woocommerce->post('products/reviews', $data)); ?> ``` ```python data = { "product_id": 22, "review": "Nice album!", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "rating": 5, } print(wcapi.post("products/reviews", data).json()) ``` ```ruby data = { product_id: 22, review: "Nice album!", reviewer: "John Doe", reviewer_email: "john.doe@example.com", rating: 5 } woocommerce.post("products/reviews", data).parsed_response ``` ```json { "id": 22, "date_created": "2018-10-18T17:59:17", "date_created_gmt": "2018-10-18T20:59:17", "product_id": 22, "status": "approved", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "review": "Nice album!", "rating": 5, "verified": false, "reviewer_avatar_urls": { "24": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96&d=mm&r=g" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews/22" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } } ``` ## Retrieve a product review This API lets you retrieve a product review by ID. ```http GET /wp-json/wc/v3/products/reviews/ ``` ```shell curl https://example.com/wp-json/wc/v3/products/reviews/22 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/reviews/22' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/reviews/22')); ?> ``` ```python print(wcapi.get("products/reviews/22").json()) ``` ```ruby woocommerce.get("products/reviews/22").parsed_response ``` ```json { "id": 22, "date_created": "2018-10-18T17:59:17", "date_created_gmt": "2018-10-18T20:59:17", "product_id": 22, "status": "approved", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "review": "Nice album!", "rating": 5, "verified": false, "reviewer_avatar_urls": { "24": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96&d=mm&r=g" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews/22" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } } ``` ## List all product reviews This API lets you retrieve all product review. ```http GET /wp-json/wc/v3/products/reviews ``` ```shell curl https://example.com/wp-json/wc/v3/products/reviews \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/reviews' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/reviews')); ?> ``` ```python print(wcapi.get("products/reviews").json()) ``` ```ruby woocommerce.get("products/reviews").parsed_response ``` ```json [ { "id": 22, "date_created": "2018-10-18T17:59:17", "date_created_gmt": "2018-10-18T20:59:17", "product_id": 22, "status": "approved", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "review": "

Nice album!

\n", "rating": 5, "verified": false, "reviewer_avatar_urls": { "24": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96&d=mm&r=g" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews/22" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } }, { "id": 20, "date_created": "2018-09-08T21:47:19", "date_created_gmt": "2018-09-09T00:47:19", "product_id": 31, "status": "approved", "reviewer": "Claudio Sanches", "reviewer_email": "john.doe@example.com", "review": "

Now works just fine.

\n", "rating": 1, "verified": true, "reviewer_avatar_urls": { "24": "https://secure.gravatar.com/avatar/908480753c07509e76322dc17d305c8b?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/908480753c07509e76322dc17d305c8b?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/908480753c07509e76322dc17d305c8b?s=96&d=mm&r=g" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews/20" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/31" } ], "reviewer": [ { "embeddable": true, "href": "https://example.com/wp-json/wp/v2/users/1" } ] } } ] ```
#### Available parameters | Parameter | Type | Description | | ------------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to reviews published after a given ISO8601 compliant date. | | `before` | string | Limit response to reviews published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | array | Ensure result set excludes specific ids. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by resource attribute. Options: `date`, `date_gmt`, `id`, `slug`, `include` and `product`. Default is `date_gmt`. | | `reviewer` | array | Limit result set to reviews assigned to specific user IDs. | | `reviewer_exclude` | array | Ensure result set excludes reviews assigned to specific user IDs. | | `reviewer_email` | array | Limit result set to that from a specific author email. | | `product` | array | Limit result set to reviews assigned to specific product IDs. | | `status` | string | Limit result set to reviews assigned a specific status. Options: `all`, `hold`, `approved`, `spam` and `trash`. Default is `approved`. | ## Update a product review This API lets you make changes to a product review. ```http PUT /wp-json/wc/v3/products/reviews/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/products/reviews/20 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "rating": 5 }' ``` ```javascript const data = { rating: 5, }; WooCommerce.put( 'products/reviews/20', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 5 ]; print_r($woocommerce->put('products/reviews/20', $data)); ?> ``` ```python data = { "rating": 5 } print(wcapi.put("products/reviews/20", data).json()) ``` ```ruby data = { rating: 5 } woocommerce.put("products/reviews/20", data).parsed_response ``` ```json { "id": 20, "date_created": "2018-09-08T21:47:19", "date_created_gmt": "2018-09-09T00:47:19", "product_id": 31, "status": "approved", "reviewer": "Claudio Sanches", "reviewer_email": "john.doe@example.com", "review": "Now works just fine.", "rating": 5, "verified": true, "reviewer_avatar_urls": { "24": "https://secure.gravatar.com/avatar/908480753c07509e76322dc17d305c8b?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/908480753c07509e76322dc17d305c8b?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/908480753c07509e76322dc17d305c8b?s=96&d=mm&r=g" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews/20" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/31" } ], "reviewer": [ { "embeddable": true, "href": "https://example.com/wp-json/wp/v2/users/1" } ] } } ``` ## Delete a product review This API helps you delete a product review. ```http DELETE /wp-json/wc/v3/products/reviews/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/products/reviews/34?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'products/reviews/20', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('products/reviews/20', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/reviews/20", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/reviews/20", force: true).parsed_response ``` ```json { "deleted": true, "previous": { "id": 20, "date_created": "2018-09-08T21:47:19", "date_created_gmt": "2018-09-09T00:47:19", "product_id": 31, "status": "trash", "reviewer": "Claudio Sanches", "reviewer_email": "john.doe@example.com", "review": "Now works just fine.", "rating": 5, "verified": true, "reviewer_avatar_urls": { "24": "https://secure.gravatar.com/avatar/908480753c07509e76322dc17d305c8b?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/908480753c07509e76322dc17d305c8b?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/908480753c07509e76322dc17d305c8b?s=96&d=mm&r=g" } } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update product reviews This API helps you to batch create, update and delete multiple product reviews. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/products/reviews/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/products/reviews/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "product_id": 22, "review": "Looks fine", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "rating": 4 }, { "product_id": 22, "review": "I love this album", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "rating": 5 } ], "update": [ { "id": 7, "reviewer": "John Doe", "reviewer_email": "john.doe@example.com" } ], "delete": [ 22 ] }' ``` ```javascript const data = { create: [ { product_id: 22, review: 'Looks fine', reviewer: 'John Doe', reviewer_email: 'john.doe@example.com', rating: 4, }, { product_id: 22, review: 'I love this album', reviewer: 'John Doe', reviewer_email: 'john.doe@example.com', rating: 5, }, ], update: [ { id: 7, reviewer: 'John Doe', reviewer_email: 'john.doe@example.com', }, ], delete: [ 22 ], }; WooCommerce.post( 'products/reviews/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'product_id' => 22, 'review' => 'Looks fine', 'reviewer' => 'John Doe', 'reviewer_email' => 'john.doe@example.com', 'rating' => 4 ], [ 'product_id' => 22, 'review' => 'I love this album', 'reviewer' => 'John Doe', 'reviewer_email' => 'john.doe@example.com', 'rating' => 5 ] ], 'update' => [ [ 'id' => 7, 'reviewer' => 'John Doe', 'reviewer_email' => 'john.doe@example.com', ] ], 'delete' => [ 22 ] ]; print_r($woocommerce->post('products/reviews/batch', $data)); ?> ``` ```python data = { "create": [ { "product_id": 22, "review": "Looks fine", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "rating": 4 }, { "product_id": 22, "review": "I love this album", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "rating": 5 } ], "update": [ { "id": 7, "reviewer": "John Doe", "reviewer_email": "john.doe@example.com" } ], "delete": [ 22 ] } print(wcapi.post("products/reviews/batch", data).json()) ``` ```ruby data = { create: [ { product_id: "22", review: "Looks fine", reviewer: "John Doe", reviewer_email: "john.doe@example.com", rating: "4" }, { product_id: "22", review: "I love this album", reviewer: "John Doe", reviewer_email: "john.doe@example.com", rating: "5" } ], update: [ { id: 7, reviewer: "John Doe", reviewer_email: "john.doe@example.com" } ], delete: [ 22 ] } woocommerce.post("products/reviews/batch", data).parsed_response ``` ```json { "create": [ { "id": 25, "date_created": "2018-10-18T18:37:35", "date_created_gmt": "2018-10-18T21:37:35", "product_id": 22, "status": "approved", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "review": "Looks fine", "rating": 4, "verified": false, "reviewer_avatar_urls": { "24": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96&d=mm&r=g" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews/25" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } }, { "id": 26, "date_created": "2018-10-18T18:37:35", "date_created_gmt": "2018-10-18T21:37:35", "product_id": 22, "status": "approved", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "review": "I love this album", "rating": 5, "verified": false, "reviewer_avatar_urls": { "24": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96&d=mm&r=g" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } } ], "update": [ { "id": 7, "date_created": "2018-07-26T19:29:21", "date_created_gmt": "2018-07-26T22:29:21", "product_id": 66, "status": "approved", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "review": "Not so bad :(", "rating": 3, "verified": false, "reviewer_avatar_urls": { "24": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96&d=mm&r=g" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews/7" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/reviews" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/66" } ] } } ], "delete": [ { "deleted": true, "previous": { "id": 22, "date_created": "2018-10-18T17:59:17", "date_created_gmt": "2018-10-18T20:59:17", "product_id": 22, "status": "approved", "reviewer": "John Doe", "reviewer_email": "john.doe@example.com", "review": "Nice album!", "rating": 5, "verified": false, "reviewer_avatar_urls": { "24": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/8eb1b522f60d11fa897de1dc6351b7e8?s=96&d=mm&r=g" } } } ] } ``` --- ## Product shipping classes *Source: apis/rest-api/v3/product-shipping-classes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product shipping classes The product shipping class API allows you to create, view, update, and delete individual, or a batch, of shipping classes. ## Product shipping class properties | Attribute | Type | Description | | ------------- | ------- | ---------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Shipping class name. `MANDATORY` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `description` | string | HTML description of the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ## Create a shipping class This API helps you to create a new product shipping class. ```http POST /wp-json/wc/v3/products/shipping_classes ``` > Example of how to create a product shipping class: ```shell curl -X POST https://example.com/wp-json/wc/v3/products/shipping_classes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Priority" }' ``` ```javascript const data = { name: 'Priority', }; WooCommerce.post( 'products/shipping_classes', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'Priority' ]; print_r($woocommerce->post('products/shipping_classes', $data)); ?> ``` ```python data = { "name": "Priority" } print(wcapi.post("products/shipping_classes", data).json()) ``` ```ruby data = { name: "Priority" } woocommerce.post("products/shipping_classes", data).parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes" } ] } } ``` ## Retrieve a shipping class This API lets you retrieve a product shipping class by ID. ```http GET /wp-json/wc/v3/products/shipping_classes/ ``` ```shell curl https://example.com/wp-json/wc/v3/products/shipping_classes/32 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/shipping_classes/32' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/shipping_classes/32')); ?> ``` ```python print(wcapi.get("products/shipping_classes/32").json()) ``` ```ruby woocommerce.get("products/shipping_classes/32").parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes" } ] } } ``` ## List all shipping classes This API lets you retrieve all product shipping classes. ```http GET /wp-json/wc/v3/products/shipping_classes ``` ```shell curl https://example.com/wp-json/wc/v3/products/shipping_classes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/shipping_classes' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/shipping_classes')); ?> ``` ```python print(wcapi.get("products/shipping_classes").json()) ``` ```ruby woocommerce.get("products/shipping_classes").parsed_response ``` ```json [ { "id": 33, "name": "Express", "slug": "express", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes/33" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes" } ] } }, { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `exclude` | array | Ensure result set excludes specific ids. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `asc`. | | `orderby` | string | Sort collection by resource attribute. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. Default is `name`. | | `hide_empty` | boolean | Whether to hide resources not assigned to any products. Default is `false`. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update a shipping class This API lets you make changes to a product shipping class. ```http PUT /wp-json/wc/v3/products/shipping_classes/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/products/shipping_classes/32 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "description": "Priority mail." }' ``` ```javascript const data = { description: 'Priority mail.', }; WooCommerce.put( 'products/shipping_classes/32', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'Priority mail.' ]; print_r($woocommerce->put('products/shipping_classes/32', $data)); ?> ``` ```python data = { "description": "Priority mail." } print(wcapi.put("products/shipping_classes/32", data).json()) ``` ```ruby data = { description: "Priority mail." } woocommerce.put("products/shipping_classes/32", data).parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "Priority mail.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes" } ] } } ``` ## Delete a shipping class This API helps you delete a product shipping class. ```http DELETE /wp-json/wc/v3/products/shipping_classes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/products/shipping_classes/32?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'products/shipping_classes/32', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('products/shipping_classes/32', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/shipping_classes/32", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/shipping_classes/32", force: true).parsed_response ``` ```json { "id": 32, "name": "Priority", "slug": "priority", "description": "Priority mail.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update shipping classes This API helps you to batch create, update and delete multiple product shipping classes. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/products/shipping_classes/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/products/shipping_classes/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Small items" }, { "name": "Large items" } ], "update": [ { "id": 33, "description": "Express shipping" } ], "delete": [ 32 ] }' ``` ```javascript const data = { create: [ { name: 'Small items', }, { name: 'Large items', }, ], update: [ { id: 33, description: 'Express shipping', }, ], delete: [ 32 ], }; WooCommerce.post( 'products/shipping_classes/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'name' => 'Small items' ], [ 'name' => 'Large items' ] ], 'update' => [ [ 'id' => 33, 'description' => 'Express shipping' ] ], 'delete' => [ 32 ] ]; print_r($woocommerce->post('products/shipping_classes/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Small items" }, { "name": "Large items" } ], "update": [ { "id": 33, "description": "Express shipping" } ], "delete": [ 32 ] } print(wcapi.post("products/shipping_classes/batch", data).json()) ``` ```ruby data = { create: [ { name: "Small items" }, { name: "Large items" } ], update: [ { id: 33, description: "Express shipping" } ], delete: [ 32 ] } woocommerce.post("products/shipping_classes/batch", data).parsed_response ``` ```json { "create": [ { "id": 34, "name": "Small items", "slug": "small-items", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes" } ] } }, { "id": 35, "name": "Large items", "slug": "large-items", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes/35" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes" } ] } } ], "update": [ { "id": 33, "name": "Express", "slug": "express", "description": "Express shipping", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes/33" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes" } ] } } ], "delete": [ { "id": 32, "name": "Priority", "slug": "priority", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes/32" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/shipping_classes" } ] } } ] } ``` --- ## Product tags *Source: apis/rest-api/v3/product-tags.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product tags The product tags API allows you to create, view, update, and delete individual, or a batch, of product tags. ## Product tag properties | Attribute | Type | Description | | ------------- | ------- | ---------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Tag name. `MANDATORY` | | `slug` | string | An alphanumeric identifier for the resource unique to its type. | | `description` | string | HTML description of the resource. | | `count` | integer | Number of published products for the resource. `READ-ONLY` | ## Create a product tag This API helps you to create a new product tag. ```http POST /wp-json/wc/v3/products/tags ``` > Example of how to create a product tag: ```shell curl -X POST https://example.com/wp-json/wc/v3/products/tags \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Leather Shoes" }' ``` ```javascript const data = { name: 'Leather Shoes', }; WooCommerce.post( 'products/tags', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'Leather Shoes' ]; print_r($woocommerce->post('products/tags', $data)); ?> ``` ```python data = { "name": "Leather Shoes" } print(wcapi.post("products/tags", data).json()) ``` ```ruby data = { name: "Leather Shoes" } woocommerce.post("products/tags", data).parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/tags" } ] } } ``` ## Retrieve a product tag This API lets you retrieve a product tag by ID. ```http GET /wp-json/wc/v3/products/tags/ ``` ```shell curl https://example.com/wp-json/wc/v3/products/tags/34 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/tags/34' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/tags/34')); ?> ``` ```python print(wcapi.get("products/tags/34").json()) ``` ```ruby woocommerce.get("products/tags/34").parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/tags" } ] } } ``` ## List all product tags This API lets you retrieve all product tag. ```http GET /wp-json/wc/v3/products/tags ``` ```shell curl https://example.com/wp-json/wc/v3/products/tags \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/tags' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/tags')); ?> ``` ```python print(wcapi.get("products/tags").json()) ``` ```ruby woocommerce.get("products/tags").parsed_response ``` ```json [ { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/tags" } ] } }, { "id": 35, "name": "Oxford Shoes", "slug": "oxford-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/tags/35" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/tags" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `exclude` | array | Ensure result set excludes specific ids. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `asc`. | | `orderby` | string | Sort collection by resource attribute. Options: `id`, `include`, `name`, `slug`, `term_group`, `description` and `count`. Default is `name`. | | `hide_empty` | boolean | Whether to hide resources not assigned to any products. Default is `false`. | | `product` | integer | Limit result set to resources assigned to a specific product. | | `slug` | string | Limit result set to resources with a specific slug. | ## Update a product tag This API lets you make changes to a product tag. ```http PUT /wp-json/wc/v3/products/tags/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/products/tags/34 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "description": "Genuine leather." }' ``` ```javascript const data = { description: 'Genuine leather.', }; WooCommerce.put( 'products/tags/34', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php put('products/tags/34', $data)); ?> ``` ```python data = { "description": "Genuine leather." } print(wcapi.put("products/tags/34", data).json()) ``` ```ruby data = { description: "Genuine leather." } woocommerce.put("products/tags/34", data).parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "Genuine leather.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/tags" } ] } } ``` ## Delete a product tag This API helps you delete a product tag. ```http DELETE /wp-json/wc/v3/products/tags/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/products/tags/34?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'products/tags/34', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('products/tags/34', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/tags/34", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/tags/34", force: true).parsed_response ``` ```json { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "Genuine leather.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/tags" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update product tags This API helps you to batch create, update and delete multiple product tags. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/products/tags/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/products/tags/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Round toe" }, { "name": "Flat" } ], "update": [ { "id": 34, "description": "Genuine leather." } ], "delete": [ 35 ] }' ``` ```javascript const data = { create: [ { name: 'Round toe', }, { name: 'Flat', }, ], update: [ { id: 34, description: 'Genuine leather.', }, ], delete: [ 35 ], }; WooCommerce.post( 'products/tags/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'name' => 'Round toe' ], [ 'name' => 'Flat' ] ], 'update' => [ [ 'id' => 34, 'description' => 'Genuine leather.' ] ], 'delete' => [ 35 ] ]; print_r($woocommerce->post('products/tags/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Round toe" }, { "name": "Flat" } ], "update": [ { "id": 34, "description": "Genuine leather." } ], "delete": [ 35 ] } print(wcapi.post("products/tags/batch", data).json()) ``` ```ruby data = { create: [ { name: "Round toe" }, { name: "Flat" } ], update: [ { id: 34, description: "Genuine leather." } ], delete: [ 35 ] } woocommerce.post("products/tags/batch", data).parsed_response ``` ```json { "create": [ { "id": 36, "name": "Round toe", "slug": "round-toe", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/tags/36" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/tags" } ] } }, { "id": 37, "name": "Flat", "slug": "flat", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/tags/37" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/tags" } ] } } ], "update": [ { "id": 34, "name": "Leather Shoes", "slug": "leather-shoes", "description": "Genuine leather.", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/tags/34" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/tags" } ] } } ], "delete": [ { "id": 35, "name": "Oxford Shoes", "slug": "oxford-shoes", "description": "", "count": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/tags/35" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/tags" } ] } } ] } ``` --- ## Product variations *Source: apis/rest-api/v3/product-variations.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Product variations The product variations API allows you to create, view, update, and delete individual, or a batch, of product variations. ## Product variation properties | Attribute | Type | Description | | ----------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `date_created` | date-time | The date the variation was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the variation was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the variation was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the variation was last modified, as GMT. `READ-ONLY` | | `description` | string | Variation description. | | `permalink` | string | Variation URL. `READ-ONLY` | | `sku` | string | Unique identifier. | | `global_unique_id` | string | GTIN, UPC, EAN or ISBN. A global unique identifier for the variation. | | `price` | string | Current variation price. `READ-ONLY` | | `regular_price` | string | Variation regular price. | | `sale_price` | string | Variation sale price. | | `date_on_sale_from` | date-time | Start date of sale price, in the site's timezone. | | `date_on_sale_from_gmt` | date-time | Start date of sale price, as GMT. | | `date_on_sale_to` | date-time | End date of sale price, in the site's timezone. | | `date_on_sale_to_gmt` | date-time | End date of sale price, as GMT. | | `on_sale` | boolean | Shows if the variation is on sale. `READ-ONLY` | | `status` | string | Variation status. Options: `draft`, `pending`, `private` and `publish`. Default is `publish`. | | `purchasable` | boolean | Shows if the variation can be bought. `READ-ONLY` | | `virtual` | boolean | If the variation is virtual. Default is `false`. | | `downloadable` | boolean | If the variation is downloadable. Default is `false`. | | `downloads` | array | List of downloadable files. See [Product variation - Downloads properties](#product-variation---downloads-properties) | | `download_limit` | integer | Number of times downloadable files can be downloaded after purchase. Default is `-1`. | | `download_expiry` | integer | Number of days until access to downloadable files expires. Default is `-1`. | | `tax_status` | string | Tax status. Options: `taxable`, `shipping` and `none`. Default is `taxable`. | | `tax_class` | string | Tax class. | | `manage_stock` | boolean, string | Stock management at variation level. Possible values are either a boolean or `parent`. Default is `false`. | | `stock_quantity` | integer | Stock quantity. | | `stock_status` | string | Controls the stock status of the product. Options: `instock`, `outofstock`, `onbackorder`. Default is `instock`. | | `backorders` | string | If managing stock, this controls if backorders are allowed. Options: `no`, `notify` and `yes`. Default is `no`. | | `backorders_allowed` | boolean | Shows if backorders are allowed. `READ-ONLY` | | `backordered` | boolean | Shows if the variation is on backordered. `READ-ONLY` | | `weight` | string | Variation weight. | | `dimensions` | object | Variation dimensions. See [Product variation - Dimensions properties](#product-variation---dimensions-properties) | | `shipping_class` | string | Shipping class slug. | | `shipping_class_id` | string | Shipping class ID. `READ-ONLY` | | `image` | object | Variation image data. See [Product variation - Image properties](#product-variation---image-properties) | | `gallery_image_ids` | array | Variation gallery image IDs, excluding the featured image (which is set via `image`). | | `attributes` | array | List of attributes. See [Product variation - Attributes properties](#product-variation---attributes-properties) | | `menu_order` | integer | Menu order, used to custom sort products. | | `meta_data` | array | Meta data. See [Product variation - Meta data properties](#product-variation---meta-data-properties) | ### Product variation - Downloads properties | Attribute | Type | Description | | --------- | ------ | ----------- | | `id` | string | File ID. | | `name` | string | File name. | | `file` | string | File URL. | ### Product variation - Dimensions properties | Attribute | Type | Description | | --------- | ------ | ----------------- | | `length` | string | Variation length. | | `width` | string | Variation width. | | `height` | string | Variation height. | ### Product variation - Image properties | Attribute | Type | Description | | ------------------- | --------- | ------------------------------------------------------------------------------------------------------- | | `id` | integer | Image ID. | | `date_created` | date-time | The date the image was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the image was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the image was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the image was last modified, as GMT. `READ-ONLY` | | `src` | string | Image URL. | | `name` | string | Image name. | | `alt` | string | Image alternative text. | ### Product variation - Attributes properties | Attribute | Type | Description | | --------- | ------- | ----------------------------- | | `id` | integer | Attribute ID. | | `name` | string | Attribute name. | | `option` | string | Selected attribute term name. | ### Product variation - Meta data properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------- | | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ## Create a product variation This API helps you to create a new product variation. ```http POST /wp-json/wc/v3/products//variations ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/products/22/variations \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "regular_price": "9.00", "image": { "id": 423 }, "attributes": [ { "id": 6, "option": "Black" } ] }' ``` ```javascript const data = { regular_price: '9.00', image: { id: 423, }, attributes: [ { id: 9, option: 'Black', }, ], }; WooCommerce.post( 'products/22/variations', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php '9.00', 'image' => [ 'id' => 423 ], 'attributes' => [ [ 'id' => 9, 'option' => 'Black' ] ] ]; print_r($woocommerce->post('products/22/variations', $data)); ?> ``` ```python data = { "regular_price": "9.00", "image": { "id": 423 }, "attributes": [ { "id": 9, "option": "Black" } ] } print(wcapi.post("products/22/variations", data).json()) ``` ```ruby data = { regular_price: "9.00", image: { id: 423 }, attributes: [ { id: 9, option: "Black" } ] } woocommerce.post("products/22/variations", data).parsed_response ``` ```json { "id": 732, "date_created": "2017-03-23T00:36:38", "date_created_gmt": "2017-03-23T03:36:38", "date_modified": "2017-03-23T00:36:38", "date_modified_gmt": "2017-03-23T03:36:38", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black", "sku": "", "price": "9.00", "regular_price": "9.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "status": true, "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 423, "date_created": "2016-10-19T12:21:14", "date_created_gmt": "2016-10-19T16:21:14", "date_modified": "2016-10-19T12:21:14", "date_modified_gmt": "2016-10-19T16:21:14", "src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg", "name": "", "alt": "" }, "gallery_image_ids": [], "attributes": [ { "id": 6, "name": "Color", "option": "Black" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations/732" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } } ``` ## Retrieve a product variation This API lets you retrieve and view a specific product variation by ID. ```http GET /wp-json/wc/v3/products//variations/ ``` Optional query parameter: `image_size` (string). Use a specific registered image size for returned variation image `src`. Falls back to the full size when the requested size is not registered. Default is `full`. ```shell curl https://example.com/wp-json/wc/v3/products/22/variations/732 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/22/variations/732' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/22/variations/732')); ?> ``` ```python print(wcapi.get("products/22/variations/732").json()) ``` ```ruby woocommerce.get("products/22/variations/732").parsed_response ``` ```json { "id": 732, "date_created": "2017-03-23T00:36:38", "date_created_gmt": "2017-03-23T03:36:38", "date_modified": "2017-03-23T00:36:38", "date_modified_gmt": "2017-03-23T03:36:38", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black", "sku": "", "price": "9.00", "regular_price": "9.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "status": "publish", "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 423, "date_created": "2016-10-19T12:21:14", "date_created_gmt": "2016-10-19T16:21:14", "date_modified": "2016-10-19T12:21:14", "date_modified_gmt": "2016-10-19T16:21:14", "src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg", "name": "", "alt": "" }, "gallery_image_ids": [], "attributes": [ { "id": 6, "name": "Color", "option": "Black" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations/732" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } } ``` ## List all product variations This API helps you to view all the product variations. ```http GET /wp-json/wc/v3/products//variations ``` ```shell curl https://example.com/wp-json/wc/v3/products/22/variations \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/22/variations' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/22/variations')); ?> ``` ```python print(wcapi.get("products/22/variations").json()) ``` ```ruby woocommerce.get("products/22/variations").parsed_response ``` ```json [ { "id": 733, "date_created": "2017-03-23T00:53:11", "date_created_gmt": "2017-03-23T03:53:11", "date_modified": "2017-03-23T00:53:11", "date_modified_gmt": "2017-03-23T03:53:11", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green", "sku": "", "price": "9.00", "regular_price": "9.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "status": "publish", "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 425, "date_created": "2016-10-19T12:21:16", "date_created_gmt": "2016-10-19T16:21:16", "date_modified": "2016-10-19T12:21:16", "date_modified_gmt": "2016-10-19T16:21:16", "src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg", "name": "", "alt": "" }, "gallery_image_ids": [], "attributes": [ { "id": 6, "name": "Color", "option": "Green" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations/733" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } }, { "id": 732, "date_created": "2017-03-23T00:36:38", "date_created_gmt": "2017-03-23T03:36:38", "date_modified": "2017-03-23T00:36:38", "date_modified_gmt": "2017-03-23T03:36:38", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black", "sku": "", "price": "9.00", "regular_price": "9.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "status": "publish", "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 423, "date_created": "2016-10-19T12:21:14", "date_created_gmt": "2016-10-19T16:21:14", "date_modified": "2016-10-19T12:21:14", "date_modified_gmt": "2016-10-19T16:21:14", "src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg", "name": "", "alt": "" }, "gallery_image_ids": [], "attributes": [ { "id": 6, "name": "Color", "option": "Black" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations/732" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ---------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Interpret `after` and `before` as UTC dates when `true`. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `modified`, `id`, `include`, `title` and `slug`. Default is `date`. | | `parent` | array | Limit result set to those of particular parent IDs. | | `parent_exclude` | array | Limit result set to all items except those of a particular parent ID. | | `slug` | string | Limit result set to products with a specific slug. | | `status` | string | Limit result set to products assigned a specific status. Options: `any`, `draft`, `pending`, `private` and `publish`. Default is `any`. | | `include_status` | string | Limit result set to product variations with any of the specified statuses. Multiple statuses can be provided as a comma-separated list. Takes precedence over the `status` parameter. Options: `any`, `future`, `trash`, `draft`, `pending`, `private`, and `publish`. | | `exclude_status` | string | Exclude product variations from result set with any of the specified statuses. Multiple statuses can be provided as a comma-separated list. Takes precedence over the `include_status` parameter. Options: `future`, `trash`, `draft`, `pending`, `private`, and `publish`. | | `sku` | string | Limit result set to products with a specific SKU. | | `tax_class` | string | Limit result set to products with a specific tax class. Default options: `standard`, `reduced-rate` and `zero-rate`. | | `on_sale` | boolean | Limit result set to products on sale. | | `min_price` | string | Limit result set to products based on a minimum price. | | `max_price` | string | Limit result set to products based on a maximum price. | | `stock_status` | string | Limit result set to products with specified stock status. Options: `instock`, `outofstock` and `onbackorder`. | | `virtual` | boolean | Limit result set to virtual product variations | | `downloadable` | boolean | Limit result set to downloadable product variations. | | `image_size` | string | Use a specific registered image size for the returned variation image `src`. Falls back to the full size if the requested size is not registered. Default is `full`. | ## Update a product variation This API lets you make changes to a product variation. ```http PUT /wp-json/wc/v3/products//variations/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/products/22/variations/733 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "regular_price": "10.00" }' ``` ```javascript const data = { regular_price: '10.00', }; WooCommerce.put( 'products/22/variations/733', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php '10.00' ]; print_r($woocommerce->put('products/22/variations/733', $data)); ?> ``` ```python data = { "regular_price": "10.00" } print(wcapi.put("products/22/variations/733", data).json()) ``` ```ruby data = { regular_price: "10.00" } woocommerce.put("products/22/variations/733", data).parsed_response ``` ```json { "id": 733, "date_created": "2017-03-23T00:53:11", "date_created_gmt": "2017-03-23T03:53:11", "date_modified": "2017-03-23T00:53:11", "date_modified_gmt": "2017-03-23T03:53:11", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green", "sku": "", "price": "10.00", "regular_price": "10.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "status": "publish", "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 425, "date_created": "2016-10-19T12:21:16", "date_created_gmt": "2016-10-19T16:21:16", "date_modified": "2016-10-19T12:21:16", "date_modified_gmt": "2016-10-19T16:21:16", "src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg", "name": "", "alt": "" }, "gallery_image_ids": [], "attributes": [ { "id": 6, "name": "Color", "option": "Green" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations/733" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } } ``` ## Delete a product variation This API helps you delete a product variation. ```http DELETE /wp-json/wc/v3/products//variations/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/products/22/variations/733?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'products/22/variations/733', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('products/22/variations/733', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/22/variations/733", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/22/variations/733", force: true).parsed_response ``` ```json { "id": 733, "date_created": "2017-03-23T00:53:11", "date_created_gmt": "2017-03-23T03:53:11", "date_modified": "2017-03-23T00:53:11", "date_modified_gmt": "2017-03-23T03:53:11", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green", "sku": "", "price": "10.00", "regular_price": "10.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "status": "publish", "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 425, "date_created": "2016-10-19T12:21:16", "date_created_gmt": "2016-10-19T16:21:16", "date_modified": "2016-10-19T12:21:16", "date_modified_gmt": "2016-10-19T16:21:16", "src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg", "name": "", "alt": "" }, "gallery_image_ids": [], "attributes": [ { "id": 6, "name": "Color", "option": "Green" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations/733" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update product variations This API helps you to batch create, update and delete multiple product variations. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/products//variations/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/products/22/variations/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "Blue" } ] }, { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "White" } ] } ], "update": [ { "id": 733, "regular_price": "10.00" } ], "delete": [ 732 ] }' ``` ```javascript const data = { create: [ { regular_price: '10.00', attributes: [ { id: 6, option: 'Blue', }, ], }, { regular_price: '10.00', attributes: [ { id: 6, option: 'White', }, ], }, ], update: [ { id: 733, regular_price: '10.00', }, ], delete: [ 732 ], }; WooCommerce.post( 'products/22/variations/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'regular_price' => '10.00', 'attributes' => [ [ 'id' => 6, 'option' => 'Blue' ] ] ], [ 'regular_price' => '10.00', 'attributes' => [ [ 'id' => 6, 'option' => 'White' ] ] ] ], 'update' => [ [ 'id' => 733, 'regular_price' => '10.00' ] ], 'delete' => [ 732 ] ]; print_r($woocommerce->post('products/22/variations/batch', $data)); ?> ``` ```python data = { "create": [ { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "Blue" } ] }, { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "White" } ] } ], "update": [ { "id": 733, "regular_price": "10.00" } ], "delete": [ 732 ] } print(wcapi.post("products/22/variations/batch", data).json()) ``` ```ruby data = { create: [ { regular_price: "10.00", attributes: [ { id: 6, option: "Blue" } ] }, { regular_price: "10.00", attributes: [ { id: 6, option: "White" } ] } ], update: [ { id: 733, regular_price: "10.00" } ], delete: [ 732 ] } woocommerce.post("products/22/variations/batch", data).parsed_response ``` ```json { "create": [ { "id": 735, "date_created": "2017-03-23T01:19:37", "date_created_gmt": "2017-03-23T04:19:37", "date_modified": "2017-03-23T01:19:37", "date_modified_gmt": "2017-03-23T04:19:37", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=blue", "sku": "", "price": "10.00", "regular_price": "10.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "status": "publish", "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 0, "date_created": "2017-03-22T22:19:40", "date_created_gmt": "2017-03-23T04:19:40", "date_modified": "2017-03-22T22:19:40", "date_modified_gmt": "2017-03-23T04:19:40", "src": "https://example.com/wp-content/plugins/woocommerce/assets/images/placeholder.png", "name": "Placeholder", "alt": "Placeholder" }, "gallery_image_ids": [], "attributes": [ { "id": 6, "name": "Color", "option": "Blue" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations/735" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } }, { "id": 736, "date_created": "2017-03-23T01:19:40", "date_created_gmt": "2017-03-23T04:19:40", "date_modified": "2017-03-23T01:19:40", "date_modified_gmt": "2017-03-23T04:19:40", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=white", "sku": "", "price": "10.00", "regular_price": "10.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "status": "publish", "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 0, "date_created": "2017-03-22T22:19:42", "date_created_gmt": "2017-03-23T04:19:42", "date_modified": "2017-03-22T22:19:42", "date_modified_gmt": "2017-03-23T04:19:42", "src": "https://example.com/wp-content/plugins/woocommerce/assets/images/placeholder.png", "name": "Placeholder", "alt": "Placeholder" }, "gallery_image_ids": [], "attributes": [ { "id": 6, "name": "Color", "option": "White" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations/736" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } } ], "update": [ { "id": 733, "date_created": "2017-03-23T00:53:11", "date_created_gmt": "2017-03-23T03:53:11", "date_modified": "2017-03-23T00:53:11", "date_modified_gmt": "2017-03-23T03:53:11", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green", "sku": "", "price": "10.00", "regular_price": "10.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "status": "publish", "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 425, "date_created": "2016-10-19T12:21:16", "date_created_gmt": "2016-10-19T16:21:16", "date_modified": "2016-10-19T12:21:16", "date_modified_gmt": "2016-10-19T16:21:16", "src": "https://example.com/wp-content/uploads/2016/10/T_3_front-12.jpg", "name": "", "alt": "" }, "gallery_image_ids": [], "attributes": [ { "id": 6, "name": "Color", "option": "Green" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations/733" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } } ], "delete": [ { "id": 732, "date_created": "2017-03-23T00:36:38", "date_created_gmt": "2017-03-23T03:36:38", "date_modified": "2017-03-23T00:36:38", "date_modified_gmt": "2017-03-23T03:36:38", "description": "", "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=black", "sku": "", "price": "9.00", "regular_price": "9.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "on_sale": false, "status": "publish", "purchasable": true, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_class": "", "shipping_class_id": 0, "image": { "id": 423, "date_created": "2016-10-19T12:21:14", "date_created_gmt": "2016-10-19T16:21:14", "date_modified": "2016-10-19T12:21:14", "date_modified_gmt": "2016-10-19T16:21:14", "src": "https://example.com/wp-content/uploads/2016/10/T_4_front-12.jpg", "name": "", "alt": "" }, "gallery_image_ids": [], "attributes": [ { "id": 6, "name": "Color", "option": "Black" } ], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations/732" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products/22/variations" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/products/22" } ] } } ] } ``` --- ## Products *Source: apis/rest-api/v3/products.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Products The products API allows you to create, view, update, and delete individual, or a batch, of products. ## Product properties | Attribute | Type | Description | | ----------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Product name. | | `slug` | string | Product slug. | | `permalink` | string | Product URL. `READ-ONLY` | | `date_created` | date-time | The date the product was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the product was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the product was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the product was last modified, as GMT. `READ-ONLY` | | `type` | string | Product type. Options: `simple`, `grouped`, `external` and `variable`. Default is `simple`. | | `status` | string | Product status (post status). Options: `draft`, `pending`, `private` and `publish`. Default is `publish`. | | `featured` | boolean | Featured product. Default is `false`. | | `catalog_visibility` | string | Catalog visibility. Options: `visible`, `catalog`, `search` and `hidden`. Default is `visible`. | | `description` | string | Product description. | | `short_description` | string | Product short description. | | `sku` | string | Unique identifier. | | `global_unique_id` | string | GTIN, UPC, EAN or ISBN - a unique identifier for each distinct product and service that can be purchased. | | `price` | string | Current product price. `READ-ONLY` | | `regular_price` | string | Product regular price. | | `sale_price` | string | Product sale price. | | `date_on_sale_from` | date-time | Start date of sale price, in the site's timezone. | | `date_on_sale_from_gmt` | date-time | Start date of sale price, as GMT. | | `date_on_sale_to` | date-time | End date of sale price, in the site's timezone. | | `date_on_sale_to_gmt` | date-time | End date of sale price, as GMT. | | `price_html` | string | Price formatted in HTML. `READ-ONLY` | | `on_sale` | boolean | Shows if the product is on sale. `READ-ONLY` | | `purchasable` | boolean | Shows if the product can be bought. `READ-ONLY` | | `total_sales` | integer | Amount of sales. `READ-ONLY` | | `virtual` | boolean | If the product is virtual. Default is `false`. | | `downloadable` | boolean | If the product is downloadable. Default is `false`. | | `downloads` | array | List of downloadable files. See [Product - Downloads properties](#product---downloads-properties) | | `download_limit` | integer | Number of times downloadable files can be downloaded after purchase. Default is `-1`. | | `download_expiry` | integer | Number of days until access to downloadable files expires. Default is `-1`. | | `external_url` | string | Product external URL. Only for external products. | | `button_text` | string | Product external button text. Only for external products. | | `tax_status` | string | Tax status. Options: `taxable`, `shipping` and `none`. Default is `taxable`. | | `tax_class` | string | Tax class. | | `manage_stock` | boolean | Stock management at product level. Default is `false`. | | `stock_quantity` | integer | Stock quantity. | | `stock_status` | string | Controls the stock status of the product. Options: `instock`, `outofstock`, `onbackorder`. Default is `instock`. | | `backorders` | string | If managing stock, this controls if backorders are allowed. Options: `no`, `notify` and `yes`. Default is `no`. | | `backorders_allowed` | boolean | Shows if backorders are allowed. `READ-ONLY` | | `backordered` | boolean | Shows if the product is on backordered. `READ-ONLY` | | `sold_individually` | boolean | Allow one item to be bought in a single order. Default is `false`. | | `weight` | string | Product weight. | | `dimensions` | object | Product dimensions. See [Product - Dimensions properties](#product---dimensions-properties) | | `shipping_required` | boolean | Shows if the product need to be shipped. `READ-ONLY` | | `shipping_taxable` | boolean | Shows whether or not the product shipping is taxable. `READ-ONLY` | | `shipping_class` | string | Shipping class slug. | | `shipping_class_id` | integer | Shipping class ID. `READ-ONLY` | | `reviews_allowed` | boolean | Allow reviews. Default is `true`. | | `average_rating` | string | Reviews average rating. `READ-ONLY` | | `rating_count` | integer | Amount of reviews that the product have. `READ-ONLY` | | `related_ids` | array | List of related products IDs. `READ-ONLY` | | `upsell_ids` | array | List of up-sell products IDs. | | `cross_sell_ids` | array | List of cross-sell products IDs. | | `parent_id` | integer | Product parent ID. | | `purchase_note` | string | Optional note to send the customer after purchase. | | `categories` | array | List of categories. See [Product - Categories properties](#product---categories-properties) | | `tags` | array | List of tags. See [Product - Tags properties](#product---tags-properties) | | `brands` | array | List of product brands. See [Brands Properties](#brands-properties). In write-mode pass an array of brand objects with `id` property ([uses wp_set_object_terms()](http://codex.wordpress.org/Function_Reference/wp_set_object_terms)) | | `images` | array | List of images. See [Product - Images properties](#product---images-properties) | | `attributes` | array | List of attributes. See [Product - Attributes properties](#product---attributes-properties) | | `default_attributes` | array | Defaults variation attributes. See [Product - Default attributes properties](#product---default-attributes-properties) | | `variations` | array | List of variations IDs. `READ-ONLY` | | `grouped_products` | array | List of grouped products ID. | | `menu_order` | integer | Menu order, used to custom sort products. | | `meta_data` | array | Meta data. See [Product - Meta data properties](#product---meta-data-properties) | ### Product - Downloads properties | Attribute | Type | Description | | --------- | ------ | ----------- | | `id` | string | File ID. | | `name` | string | File name. | | `file` | string | File URL. | ### Product - Dimensions properties | Attribute | Type | Description | | --------- | ------ | --------------- | | `length` | string | Product length. | | `width` | string | Product width. | | `height` | string | Product height. | ### Product - Categories properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------------- | | `id` | integer | Category ID. | | `name` | string | Category name. `READ-ONLY` | | `slug` | string | Category slug. `READ-ONLY` | ### Product - Tags properties | Attribute | Type | Description | | --------- | ------- | --------------------------------------------------- | | `id` | integer | Tag ID. | | `name` | string | Tag name. `READ-ONLY` | | `slug` | string | Tag slug. `READ-ONLY` | ### Product - Images properties | Attribute | Type | Description | | ------------------- | --------- | ------------------------------------------------------------------------------------------------------- | | `id` | integer | The attachment ID from the Media Library. | | `date_created` | date-time | The date the image was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the image was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the image was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the image was last modified, as GMT. `READ-ONLY` | | `src` | string | Image URL. | | `name` | string | Image name. | | `alt` | string | Image alternative text. | ### Brands Properties | Attribute | Type | Description | | --------- | ------- | ---------------------------------------------------------------------- | | `id` | integer | Brand ID `REQUIRED FOR WRITE OPERATIONS` | | `name` | string | Brand name `READ-ONLY` | | `slug` | string | Brand slug `READ-ONLY` | ### Product - Attributes properties | Attribute | Type | Description | | ----------- | ------- | ----------------------------------------------------------------------------------------------------------------- | | `id` | integer | Attribute ID. | | `name` | string | Attribute name. | | `position` | integer | Attribute position. | | `visible` | boolean | Define if the attribute is visible on the "Additional information" tab in the product's page. Default is `false`. | | `variation` | boolean | Define if the attribute can be used as variation. Default is `false`. | | `options` | array | List of available term names of the attribute. | ### Product - Default attributes properties | Attribute | Type | Description | | --------- | ------- | ----------------------------- | | `id` | integer | Attribute ID. | | `name` | string | Attribute name. | | `option` | string | Selected attribute term name. | ### Product - Meta data properties | Attribute | Type | Description | | --------- | ------- | -------------------------------------------------- | | `id` | integer | Meta ID. `READ-ONLY` | | `key` | string | Meta key. | | `value` | string | Meta value. | ## Create a product This API helps you to create a new product. ```http POST /wp-json/wc/v3/products ``` > Example of how to create a `simple` product with one existing image and one new image: ```shell curl -X POST https://example.com/wp-json/wc/v3/products \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "id": 42 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg" } ] }' ``` ```javascript const data = { name: 'Premium Quality', type: 'simple', regular_price: '21.99', description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', short_description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', categories: [ { id: 9, }, { id: 14, }, ], images: [ { id: 42, }, { src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg', }, ], }; WooCommerce.post( 'products', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'Premium Quality', 'type' => 'simple', 'regular_price' => '21.99', 'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', 'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'categories' => [ [ 'id' => 9 ], [ 'id' => 14 ] ], 'images' => [ [ 'id': 42 ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg' ] ] ]; print_r($woocommerce->post('products', $data)); ?> ``` ```python data = { "name": "Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "id": 42 }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg" } ] } print(wcapi.post("products", data).json()) ``` ```ruby data = { name: "Premium Quality", type: "simple", regular_price: "21.99", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { id: 42 }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg", } ] } woocommerce.post("products", data).parsed_response ``` ```json { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$21.99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 53, 40, 56, 479, 99 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 42, "date_created": "2017-03-22T14:01:13", "date_created_gmt": "2017-03-22T20:01:13", "date_modified": "2017-03-22T14:01:13", "date_modified_gmt": "2017-03-22T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "" }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "" } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products" } ] } } ```
> Example of how to create a `variable` product with global and non-global attributes: ```shell curl -X POST https://example.com/wp-json/wc/v3/products \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Ship Your Idea", "type": "variable", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg" }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg" }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg" }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg" } ], "attributes": [ { "id": 6, "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "name": "Size", "position": 0, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "option": "Black" }, { "name": "Size", "option": "S" } ] }' ``` ```javascript const data = { name: 'Ship Your Idea', type: 'variable', description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', short_description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', categories: [ { id: 9, }, { id: 14, }, ], images: [ { src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg', }, { src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg', }, { src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg', }, { src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg', }, ], attributes: [ { id: 6, position: 0, visible: true, variation: true, options: [ 'Black', 'Green' ], }, { name: 'Size', position: 0, visible: false, variation: true, options: [ 'S', 'M' ], }, ], default_attributes: [ { id: 6, option: 'Black', }, { name: 'Size', option: 'S', }, ], }; WooCommerce.post( 'products', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'Ship Your Idea', 'type' => 'variable', 'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', 'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'categories' => [ [ 'id' => 9 ], [ 'id' => 14 ] ], 'images' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg' ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg' ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg' ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg' ] ], 'attributes' => [ [ 'id' => 6, 'position' => 0, 'visible' => false, 'variation' => true, 'options' => [ 'Black', 'Green' ] ], [ 'name' => 'Size', 'position' => 0, 'visible' => true, 'variation' => true, 'options' => [ 'S', 'M' ] ] ], 'default_attributes' => [ [ 'id' => 6, 'option' => 'Black' ], [ 'name' => 'Size', 'option' => 'S' ] ] ]; print_r($woocommerce->post('products', $data)); ?> ``` ```python data = { "name": "Ship Your Idea", "type": "variable", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg" }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg" }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg" }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg" } ], "attributes": [ { "id": 6, "position": 0, "visible": False, "variation": True, "options": [ "Black", "Green" ] }, { "name": "Size", "position": 0, "visible": True, "variation": True, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "option": "Black" }, { "name": "Size", "option": "S" } ] } print(wcapi.post("products", data).json()) ``` ```ruby data = { name: "Ship Your Idea", type: "variable", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg" }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg" }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg" }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg" } ], attributes: [ { id: 6, position: 0, visible: false, variation: true, options: [ "Black", "Green" ] }, { name: "Size", position: 0, visible: true, variation: true, options: [ "S", "M" ] } ], default_attributes: [ { id: 6, option: "Black" }, { name: "Size", option: "S" } ] } woocommerce.post("products", data).parsed_response ``` ```json { "id": 799, "name": "Ship Your Idea", "slug": "ship-your-idea-22", "permalink": "https://example.com/product/ship-your-idea-22/", "date_created": "2017-03-23T17:03:12", "date_created_gmt": "2017-03-23T20:03:12", "date_modified": "2017-03-23T17:03:12", "date_modified_gmt": "2017-03-23T20:03:12", "type": "variable", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "", "regular_price": "", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "", "on_sale": false, "purchasable": false, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 472, 387, 19, 53, 396 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 795, "date_created": "2017-03-23T14:03:08", "date_created_gmt": "2017-03-23T20:03:08", "date_modified": "2017-03-23T14:03:08", "date_modified_gmt": "2017-03-23T20:03:08", "src": "https://example.com/wp-content/uploads/2017/03/T_4_front-11.jpg", "name": "", "alt": "" }, { "id": 796, "date_created": "2017-03-23T14:03:09", "date_created_gmt": "2017-03-23T20:03:09", "date_modified": "2017-03-23T14:03:09", "date_modified_gmt": "2017-03-23T20:03:09", "src": "https://example.com/wp-content/uploads/2017/03/T_4_back-10.jpg", "name": "", "alt": "" }, { "id": 797, "date_created": "2017-03-23T14:03:10", "date_created_gmt": "2017-03-23T20:03:10", "date_modified": "2017-03-23T14:03:10", "date_modified_gmt": "2017-03-23T20:03:10", "src": "https://example.com/wp-content/uploads/2017/03/T_3_front-10.jpg", "name": "", "alt": "" }, { "id": 798, "date_created": "2017-03-23T14:03:11", "date_created_gmt": "2017-03-23T20:03:11", "date_modified": "2017-03-23T14:03:11", "date_modified_gmt": "2017-03-23T20:03:11", "src": "https://example.com/wp-content/uploads/2017/03/T_3_back-10.jpg", "name": "", "alt": "" } ], "attributes": [ { "id": 6, "name": "Color", "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "id": 0, "name": "Size", "position": 0, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "name": "Color", "option": "black" }, { "id": 0, "name": "Size", "option": "S" } ], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/799" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products" } ] } } ```
## Retrieve a product This API lets you retrieve and view a specific product by ID. ```http GET /wp-json/wc/v3/products/ ``` Optional query parameter: `image_size` (string). Use a specific registered image size for returned image `src` values. Falls back to the full size when the requested size is not registered. Default is `full`. ```shell curl https://example.com/wp-json/wc/v3/products/794 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products/794' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products/794')); ?> ``` ```python print(wcapi.get("products/794").json()) ``` ```ruby woocommerce.get("products/794").parsed_response ``` ```json { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$21.99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 53, 40, 56, 479, 99 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 792, "date_created": "2017-03-23T14:01:13", "date_created_gmt": "2017-03-23T20:01:13", "date_modified": "2017-03-23T14:01:13", "date_modified_gmt": "2017-03-23T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "" }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "" } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products" } ] } } ```
## List all products This API helps you to view all the products. ```http GET /wp-json/wc/v3/products ``` ```shell curl https://example.com/wp-json/wc/v3/products \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'products' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('products')); ?> ``` ```python print(wcapi.get("products").json()) ``` ```ruby woocommerce.get("products").parsed_response ``` ```json [ { "id": 799, "name": "Ship Your Idea", "slug": "ship-your-idea-22", "permalink": "https://example.com/product/ship-your-idea-22/", "date_created": "2017-03-23T17:03:12", "date_created_gmt": "2017-03-23T20:03:12", "date_modified": "2017-03-23T17:03:12", "date_modified_gmt": "2017-03-23T20:03:12", "type": "variable", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "", "regular_price": "", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "", "on_sale": false, "purchasable": false, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 31, 22, 369, 414, 56 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 795, "date_created": "2017-03-23T14:03:08", "date_created_gmt": "2017-03-23T20:03:08", "date_modified": "2017-03-23T14:03:08", "date_modified_gmt": "2017-03-23T20:03:08", "src": "https://example.com/wp-content/uploads/2017/03/T_4_front-11.jpg", "name": "", "alt": "" }, { "id": 796, "date_created": "2017-03-23T14:03:09", "date_created_gmt": "2017-03-23T20:03:09", "date_modified": "2017-03-23T14:03:09", "date_modified_gmt": "2017-03-23T20:03:09", "src": "https://example.com/wp-content/uploads/2017/03/T_4_back-10.jpg", "name": "", "alt": "" }, { "id": 797, "date_created": "2017-03-23T14:03:10", "date_created_gmt": "2017-03-23T20:03:10", "date_modified": "2017-03-23T14:03:10", "date_modified_gmt": "2017-03-23T20:03:10", "src": "https://example.com/wp-content/uploads/2017/03/T_3_front-10.jpg", "name": "", "alt": "" }, { "id": 798, "date_created": "2017-03-23T14:03:11", "date_created_gmt": "2017-03-23T20:03:11", "date_modified": "2017-03-23T14:03:11", "date_modified_gmt": "2017-03-23T20:03:11", "src": "https://example.com/wp-content/uploads/2017/03/T_3_back-10.jpg", "name": "", "alt": "" } ], "attributes": [ { "id": 6, "name": "Color", "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "id": 0, "name": "Size", "position": 0, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/799" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products" } ] } }, { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$21.99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 463, 47, 31, 387, 458 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 792, "date_created": "2017-03-23T14:01:13", "date_created_gmt": "2017-03-23T20:01:13", "date_modified": "2017-03-23T14:01:13", "date_modified_gmt": "2017-03-23T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "" }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "" } ], "attributes": [], "default_attributes": [ { "id": 6, "name": "Color", "option": "black" }, { "id": 0, "name": "Size", "option": "S" } ], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products" } ] } } ] ```
#### Available parameters | Parameter | Type | Description | | ----------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `search_fields` | array | Fields to search when used with `search` parameter. All search tokens must be found across any of the specified fields. Takes precedence over other search parameters. If empty, uses default `search` behavior. Options: `name`, `sku`, `global_unique_id`, `description`, and `short_description`. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `modified_after` | string | Limit response to resources modified after a given ISO8601 compliant date. | | `modified_before` | string | Limit response to resources modified after a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Whether to interpret dates as GMT when limiting response by published or modified date. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `modified`, `id`, `include`, `title`, `slug`, `price`, `popularity`, `rating`, and `menu_order`. Default is `date`. | | `parent` | array | Limit result set to those of particular parent IDs. | | `parent_exclude` | array | Limit result set to all items except those of a particular parent ID. | | `slug` | string | Limit result set to products with a specific slug. | | `status` | string | Limit result set to products assigned a specific status. Options: `any`, `draft`, `pending`, `private` and `publish`. Default is `any`. | | `include_status` | string | Limit result set to products with any of the specified statuses. Multiple statuses can be provided as a comma-separated list. Takes precedence over the `status` parameter. Options: `any`, `future`, `trash`, `draft`, `pending`, `private`, and `publish`. | | `exclude_status` | string | Exclude products from result set with any of the specified statuses. Multiple statuses can be provided as a comma-separated list. Takes precedence over the `include_status` parameter. Options: `future`, `trash`, `draft`, `pending`, `private`, and `publish`. | | `type` | string | Limit result set to products assigned a specific type. Options: `simple`, `grouped`, `external` and `variable`. | | `include_types` | string | Limit result set to products with any of the types. Multiple statuses can be provided as a comma-separated list. Takes precedence over the `type` parameter. Options: `simple`, `grouped`, `external` and `variable`. | | `exclude_types` | string | Exclude products from result set with any of the specified types. Multiple statuses can be provided as a comma-separated list. Takes precedence over the `include_types` parameter. Options: `simple`, `grouped`, `external` and `variable`. | | `sku` | string | Limit result set to products with a specific SKU. | | `featured` | boolean | Limit result set to featured products. | | `category` | string | Limit result set to products assigned a specific category ID. | | `tag` | string | Limit result set to products assigned a specific tag ID. | | `shipping_class` | string | Limit result set to products assigned a specific shipping class ID. | | `attribute` | string | Limit result set to products with a specific attribute. | | `attribute_term` | string | Limit result set to products with a specific attribute term ID (required an assigned attribute). | | `tax_class` | string | Limit result set to products with a specific tax class. Default options: `standard`, `reduced-rate` and `zero-rate`. | | `on_sale` | boolean | Limit result set to products on sale. | | `min_price` | string | Limit result set to products based on a minimum price. | | `max_price` | string | Limit result set to products based on a maximum price. | | `stock_status` | string | Limit result set to products with specified stock status. Options: `instock`, `outofstock` and `onbackorder`. | | `virtual` | boolean | Limit result set to virtual products. | | `downloadable` | boolean | Limit result set to downloadable products. | | `image_size` | string | Use a specific registered image size for the returned image `src` values. Falls back to the full size if the requested size is not registered. Default is `full`. | ## Duplicate product This API helps you to duplicate a product. ```http POST /wp-json/wc/v3/products//duplicate ``` ```shell curl https://example.com/wp-json/wc/v3/products//duplicate \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.post( 'products/2/duplicate' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php post('products/2/duplicate')); ?> ``` ```python print(wcapi.post("products/2/duplicate").json()) ``` ```ruby woocommerce.post("products/2/duplicate").parsed_response ``` ```json { "id": 824, "name": "Premium Quality (Copy)", "slug": "", "date_created": { "date": "2024-05-30 19:16:39.000000", "timezone_type": 1, "timezone": "+00:00" }, "date_modified": { "date": "2024-03-08 15:03:19.000000", "timezone_type": 1, "timezone": "+00:00" }, "status": "draft", "featured": false, "catalog_visibility": "visible", "description": "", "short_description": "", "sku": "product-22-1", "price": "", "regular_price": "", "sale_price": "", "date_on_sale_from": null, "date_on_sale_to": null, "total_sales": 0, "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "low_stock_amount": "", "sold_individually": false, "weight": "", "length": "", "width": "", "height": "", "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "reviews_allowed": true, "purchase_note": "", "attributes": [], "default_attributes": [], "menu_order": 0, "post_password": "", "virtual": false, "downloadable": false, "category_ids": [ 15 ], "tag_ids": [], "shipping_class_id": 0, "downloads": [], "image_id": "", "gallery_image_ids": [], "download_limit": -1, "download_expiry": -1, "rating_counts": [], "average_rating": "0", "review_count": 0, "meta_data": [] } ``` ## Update a product This API lets you make changes to a product. ```http PUT /wp-json/wc/v3/products/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/products/794 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "regular_price": "24.54" }' ``` ```javascript const data = { regular_price: '24.54', }; WooCommerce.put( 'products/794', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php '24.54' ]; print_r($woocommerce->put('products/794', $data)); ?> ``` ```python data = { "regular_price": "24.54" } print(wcapi.put("products/794", data).json()) ``` ```ruby data = { regular_price: "24.54" } woocommerce.put("products/794", data).parsed_response ``` ```json { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "24.54", "regular_price": "24.54", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$24.54", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 479, 387, 22, 463, 396 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 792, "date_created": "2017-03-23T14:01:13", "date_created_gmt": "2017-03-23T20:01:13", "date_modified": "2017-03-23T14:01:13", "date_modified_gmt": "2017-03-23T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "" }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "" } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products" } ] } } ```
## Delete a product This API helps you delete a product. ```http DELETE /wp-json/wc/v3/products/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/products/794?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'products/794', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('products/794', ['force' => true])); ?> ``` ```python print(wcapi.delete("products/794", params={"force": True}).json()) ``` ```ruby woocommerce.delete("products/794", force: true).parsed_response ``` ```json { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "24.54", "regular_price": "24.54", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$24.54", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 479, 387, 22, 463, 396 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 792, "date_created": "2017-03-23T14:01:13", "date_created_gmt": "2017-03-23T20:01:13", "date_modified": "2017-03-23T14:01:13", "date_modified_gmt": "2017-03-23T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "" }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "" } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products" } ] } } ```
#### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------------------- | | `force` | string | Use `true` whether to permanently delete the product, Default is `false`. | ## Batch update products This API helps you to batch create, update and delete multiple products. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/products/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/products/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Woo Single #1", "type": "simple", "regular_price": "21.99", "virtual": true, "downloadable": true, "downloads": [ { "name": "Woo Single", "file": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], "categories": [ { "id": 11 }, { "id": 13 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ] }, { "name": "New Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg" } ] } ], "update": [ { "id": 799, "default_attributes": [ { "id": 6, "name": "Color", "option": "Green" }, { "id": 0, "name": "Size", "option": "M" } ] } ], "delete": [ 794 ] }' ``` ```javascript const data = { create: [ { name: 'Woo Single #1', type: 'simple', regular_price: '21.99', virtual: true, downloadable: true, downloads: [ { name: 'Woo Single', file: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', }, ], categories: [ { id: 11, }, { id: 13, }, ], images: [ { src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg', }, ], }, { name: 'New Premium Quality', type: 'simple', regular_price: '21.99', description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', short_description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', categories: [ { id: 9, }, { id: 14, }, ], images: [ { src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg', }, { src: 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg', }, ], }, ], update: [ { id: 799, default_attributes: [ { id: 6, name: 'Color', option: 'Green', }, { id: 0, name: 'Size', option: 'M', }, ], }, ], delete: [ 794 ], }; WooCommerce.post( 'products/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'name' => 'Woo Single #1', 'type' => 'simple', 'regular_price' => '21.99', 'virtual' => true, 'downloadable' => true, 'downloads' => [ [ 'name' => 'Woo Single', 'file' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg' ] ], 'categories' => [ [ 'id' => 11 ], [ 'id' => 13 ] ], 'images' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg' ] ] ], [ 'name' => 'New Premium Quality', 'type' => 'simple', 'regular_price' => '21.99', 'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.', 'short_description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.', 'categories' => [ [ 'id' => 9 ], [ 'id' => 14 ] ], 'images' => [ [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg' ], [ 'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg' ] ] ] ], 'update' => [ [ 'id' => 799, 'default_attributes' => [ [ 'id' => 6, 'name' => 'Color', 'option' => 'Green' ], [ 'id' => 0, 'name' => 'Size', 'option' => 'M' ] ] ] ], 'delete' => [ 794 ] ]; print_r($woocommerce->post('products/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Woo Single #1", "type": "simple", "regular_price": "21.99", "virtual": True, "downloadable": True, "downloads": [ { "name": "Woo Single", "file": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], "categories": [ { "id": 11 }, { "id": 13 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ] }, { "name": "New Premium Quality", "type": "simple", "regular_price": "21.99", "description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", "short_description": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", "categories": [ { "id": 9 }, { "id": 14 } ], "images": [ { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" }, { "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg" } ] } ], "update": [ { "id": 799, "default_attributes": [ { "id": 6, "name": "Color", "option": "Green" }, { "id": 0, "name": "Size", "option": "M" } ] } ], "delete": [ 794 ] } print(wcapi.post("products/batch", data).json()) ``` ```ruby data = { create: [ { name: "Woo Single #1", type: "simple", regular_price: "21.99", virtual: true, downloadable: true, downloads: [ { name: "Woo Single", file: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], categories: [ { id: 11 }, { id: 13 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ] }, { name: "New Premium Quality", type: "simple", regular_price: "21.99", description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.", short_description: "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.", categories: [ { id: 9 }, { id: 14 } ], images: [ { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg" }, { src: "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg" } ] } ], update: [ { id: 799, default_attributes: [ { id: 6, name: "Color, option: "Green" }, { id: 0, name: "Size", option: "M" } ] } ], delete: [ 794 ] } woocommerce.post("products/batch", data).parsed_response ``` ```json { "create": [ { "id": 801, "name": "Woo Single #1", "slug": "woo-single-1-4", "permalink": "https://example.com/product/woo-single-1-4/", "date_created": "2017-03-23T17:35:43", "date_created_gmt": "2017-03-23T20:35:43", "date_modified": "2017-03-23T17:35:43", "date_modified_gmt": "2017-03-23T20:35:43", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "", "short_description": "", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$21.99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": true, "downloadable": true, "downloads": [ { "id": 0, "name": "Woo Single", "file": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/cd_4_angle.jpg" } ], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": false, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 588, 87, 573, 96, 329 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 11, "name": "Music", "slug": "music" }, { "id": 13, "name": "Singles", "slug": "singles" } ], "tags": [], "images": [ { "id": 800, "date_created": "2017-03-23T14:35:43", "date_created_gmt": "2017-03-23T20:35:43", "date_modified": "2017-03-23T14:35:43", "date_modified_gmt": "2017-03-23T20:35:43", "src": "https://example.com/wp-content/uploads/2017/03/cd_4_angle.jpg", "name": "", "alt": "" } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/801" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products" } ] } }, { "id": 804, "name": "New Premium Quality", "slug": "new-premium-quality", "permalink": "https://example.com/product/new-premium-quality/", "date_created": "2017-03-23T17:35:48", "date_created_gmt": "2017-03-23T20:35:48", "date_modified": "2017-03-23T17:35:48", "date_modified_gmt": "2017-03-23T20:35:48", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "21.99", "regular_price": "21.99", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$21.99", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 458, 56, 99, 34, 378 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 802, "date_created": "2017-03-23T14:35:47", "date_created_gmt": "2017-03-23T20:35:47", "date_modified": "2017-03-23T14:35:47", "date_modified_gmt": "2017-03-23T20:35:47", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-5.jpg", "name": "", "alt": "" }, { "id": 803, "date_created": "2017-03-23T14:35:48", "date_created_gmt": "2017-03-23T20:35:48", "date_modified": "2017-03-23T14:35:48", "date_modified_gmt": "2017-03-23T20:35:48", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-3.jpg", "name": "", "alt": "" } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/804" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products" } ] } } ], "update": [ { "id": 799, "name": "Ship Your Idea", "slug": "ship-your-idea-22", "permalink": "https://example.com/product/ship-your-idea-22/", "date_created": "2017-03-23T17:03:12", "date_created_gmt": "2017-03-23T20:03:12", "date_modified": "2017-03-23T17:03:12", "date_modified_gmt": "2017-03-23T20:03:12", "type": "variable", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "", "regular_price": "", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "", "on_sale": false, "purchasable": false, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 414, 40, 34, 463, 15 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 795, "date_created": "2017-03-23T14:03:08", "date_created_gmt": "2017-03-23T20:03:08", "date_modified": "2017-03-23T14:03:08", "date_modified_gmt": "2017-03-23T20:03:08", "src": "https://example.com/wp-content/uploads/2017/03/T_4_front-11.jpg", "name": "", "alt": "" }, { "id": 796, "date_created": "2017-03-23T14:03:09", "date_created_gmt": "2017-03-23T20:03:09", "date_modified": "2017-03-23T14:03:09", "date_modified_gmt": "2017-03-23T20:03:09", "src": "https://example.com/wp-content/uploads/2017/03/T_4_back-10.jpg", "name": "", "alt": "" }, { "id": 797, "date_created": "2017-03-23T14:03:10", "date_created_gmt": "2017-03-23T20:03:10", "date_modified": "2017-03-23T14:03:10", "date_modified_gmt": "2017-03-23T20:03:10", "src": "https://example.com/wp-content/uploads/2017/03/T_3_front-10.jpg", "name": "", "alt": "" }, { "id": 798, "date_created": "2017-03-23T14:03:11", "date_created_gmt": "2017-03-23T20:03:11", "date_modified": "2017-03-23T14:03:11", "date_modified_gmt": "2017-03-23T20:03:11", "src": "https://example.com/wp-content/uploads/2017/03/T_3_back-10.jpg", "name": "", "alt": "" } ], "attributes": [ { "id": 6, "name": "Color", "position": 0, "visible": false, "variation": true, "options": [ "Black", "Green" ] }, { "id": 0, "name": "Size", "position": 0, "visible": true, "variation": true, "options": [ "S", "M" ] } ], "default_attributes": [ { "id": 6, "name": "Color", "option": "green" }, { "id": 0, "name": "Size", "option": "M" } ], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/799" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products" } ] } } ], "delete": [ { "id": 794, "name": "Premium Quality", "slug": "premium-quality-19", "permalink": "https://example.com/product/premium-quality-19/", "date_created": "2017-03-23T17:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T17:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

\n", "short_description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

\n", "sku": "", "price": "24.54", "regular_price": "24.54", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "$24.54", "on_sale": false, "purchasable": true, "total_sales": 0, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": { "length": "", "width": "", "height": "" }, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [ 369, 56, 378, 31, 22 ], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [ { "id": 9, "name": "Clothing", "slug": "clothing" }, { "id": 14, "name": "T-shirts", "slug": "t-shirts" } ], "tags": [], "images": [ { "id": 792, "date_created": "2017-03-23T14:01:13", "date_created_gmt": "2017-03-23T20:01:13", "date_modified": "2017-03-23T14:01:13", "date_modified_gmt": "2017-03-23T20:01:13", "src": "https://example.com/wp-content/uploads/2017/03/T_2_front-4.jpg", "name": "", "alt": "" }, { "id": 793, "date_created": "2017-03-23T14:01:14", "date_created_gmt": "2017-03-23T20:01:14", "date_modified": "2017-03-23T14:01:14", "date_modified_gmt": "2017-03-23T20:01:14", "src": "https://example.com/wp-content/uploads/2017/03/T_2_back-2.jpg", "name": "", "alt": "" } ], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/products/794" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/products" } ] } } ] } ```
--- ## Refunds *Source: apis/rest-api/v3/refunds.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Refunds The refunds API is a simple, read-only endpoint that allows you to retrieve a list of refunds outside the context of an existing order. To create, view, and delete individual refunds, check out the [order refunds API](../order-refunds). ## Refund properties All properties are the same as those in the [order refunds endpoint](../order-refunds#order-refund-properties), but with one additional property: | Attribute | Type | Description | | ----------- | ------- | -------------------------------------------------- | | `parent_id` | integer | The ID of the order the refund is associated with. | ## Retrieve a list of refunds This API lets you retrieve and view refunds from your store, regardless of which order they are associated with. ```http GET /wp-json/wc/v3/refunds ``` ```shell curl https://example.com/wp-json/wc/v3/refunds \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'refunds' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('refunds')); ?> ``` ```python print(wcapi.get("refunds").json()) ``` ```ruby woocommerce.get("refunds").parsed_response ``` ```json [ { "id": 726, "parent_id": 124, "date_created": "2017-03-21T17:07:11", "date_created_gmt": "2017-03-21T20:07:11", "amount": "10.00", "reason": "", "refunded_by": 1, "refunded_payment": false, "meta_data": [], "line_items": [], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds/726" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } }, { "id": 724, "parent_id": 63, "date_created": "2017-03-21T16:55:37", "date_created_gmt": "2017-03-21T19:55:37", "amount": "9.00", "reason": "", "refunded_by": 1, "refunded_payment": false, "meta_data": [], "line_items": [ { "id": 314, "name": "Woo Album #2", "product_id": 87, "variation_id": 0, "quantity": -1, "tax_class": "", "subtotal": "-9.00", "subtotal_tax": "0.00", "total": "-9.00", "total_tax": "0.00", "taxes": [], "meta_data": [ { "id": 2076, "key": "_refunded_item_id", "value": "311" } ], "sku": "", "price": -9 } ], "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds/724" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/orders/723/refunds" } ], "up": [ { "href": "https://example.com/wp-json/wc/v3/orders/723" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `modified`, `id`, `include`, `title` and `slug`. Default is `date`. | | `parent` | array | Limit result set to those of particular parent IDs. | | `parent_exclude` | array | Limit result set to all items except those of a particular parent ID. | | `dp` | integer | Number of decimal points to use in each resource. Default is `2`. | --- ## Reports *Source: apis/rest-api/v3/reports.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Reports The reports API allows you to view all types of reports available. ## List all reports This API lets you retrieve and view a simple list of available reports. ```http GET /wp-json/wc/v3/reports ``` ```shell curl https://example.com/wp-json/wc/v3/reports \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'reports' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('reports')); ?> ``` ```python print(wcapi.get("reports").json()) ``` ```ruby woocommerce.get("reports").parsed_response ``` ```json [ { "slug": "sales", "description": "List of sales reports.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/reports/sales" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ] } }, { "slug": "top_sellers", "description": "List of top sellers products.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/reports/top_sellers" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ] } }, { "slug": "orders/totals", "description": "Orders totals.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/reports/orders/totals" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ] } }, { "slug": "products/totals", "description": "Products totals.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/reports/products/totals" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ] } }, { "slug": "customers/totals", "description": "Customers totals.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/reports/customers/totals" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ] } }, { "slug": "coupons/totals", "description": "Coupons totals.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/reports/coupons/totals" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ] } }, { "slug": "reviews/totals", "description": "Reviews totals.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/reports/reviews/totals" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ] } }, { "slug": "categories/totals", "description": "Categories totals.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/reports/categories/totals" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ] } }, { "slug": "tags/totals", "description": "Tags totals.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/reports/tags/totals" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ] } }, { "slug": "attributes/totals", "description": "Attributes totals.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/reports/attributes/totals" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ] } } ] ``` ## Retrieve sales report This API lets you retrieve and view a sales report. ```http GET /wp-json/wc/v3/reports/sales ``` ```shell curl https://example.com/wp-json/wc/v3/reports/sales?date_min=2016-05-03&date_max=2016-05-04 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'reports/sales', { date_min: '2016-05-03', date_max: '2016-05-04', } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php '2016-05-03', 'date_max' => '2016-05-04' ]; print_r($woocommerce->get('reports/sales', $query)); ?> ``` ```python print(wcapi.get("reports/sales?date_min=2016-05-03&date_max=2016-05-04").json()) ``` ```ruby query = { date_min: "2016-05-03", date_max: "2016-05-04" } woocommerce.get("reports/sales", query).parsed_response ``` ```json [ { "total_sales": "14.00", "net_sales": "4.00", "average_sales": "2.00", "total_orders": 3, "total_items": 6, "total_tax": "0.00", "total_shipping": "10.00", "total_refunds": 10, "total_discount": "0.00", "totals_grouped_by": "day", "totals": { "2016-05-03": { "sales": "14.00", "orders": 3, "items": 6, "tax": "0.00", "shipping": "10.00", "discount": "0.00", "refunds": "10.00", "customers": 0 }, "2016-05-04": { "sales": "0.00", "orders": 0, "items": 0, "tax": "0.00", "shipping": "0.00", "discount": "0.00", "refunds": "0.00", "customers": 0 } }, "total_customers": 0, "_links": { "about": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ] } } ] ``` :::note Per-period `refunds` vs `total_refunds` Per-period `refunds` and the top-level `total_refunds` come from different queries and will not always agree. Per-period `refunds` sum each refund record by its own date inside the report range. `total_refunds` instead counts the parent order's full total for any refunded-status order that has *any* refund record falling in the range. When an order's refunds straddle the range boundary (e.g. a partial refund last month and another this month on the same order that ultimately becomes refunded), the two values can diverge. For per-day net sales, prefer `sales - refunds` per bucket. ::: #### Sales report properties | Attribute | Type | Description | | ------------------- | ------- | --------------------------------------------------------------------- | | `total_sales` | string | Gross sales in the period. `READ-ONLY` | | `net_sales` | string | Net sales in the period. `READ-ONLY` | | `average_sales` | string | Average net daily sales. `READ-ONLY` | | `total_orders` | integer | Total of orders placed. `READ-ONLY` | | `total_items` | integer | Total of items purchased. `READ-ONLY` | | `total_tax` | string | Total charged for taxes. `READ-ONLY` | | `total_shipping` | string | Total charged for shipping. `READ-ONLY` | | `total_refunds` | integer | Total of refunded orders. `READ-ONLY` | | `total_discount` | integer | Total of coupons used. `READ-ONLY` | | `totals_grouped_by` | string | Group type. `READ-ONLY` | | `totals` | array | Totals. `READ-ONLY` | #### Available parameters | Parameter | Type | Description | | ---------- | ------ | ----------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Default is `view`. Options: `view`. | | `period` | string | Report period. Default is today's date. Options: `week`, `month`, `last_month` and `year` | | `date_min` | string | Return sales for a specific start date, the date need to be in the YYYY-MM-DD format. | | `date_max` | string | Return sales for a specific end date, the date need to be in the YYYY-MM-DD format. | ## Retrieve top sellers report This API lets you retrieve and view a list of top sellers report. ```http GET /wp-json/wc/v3/reports/top_sellers ``` ```shell curl https://example.com/wp-json/wc/v3/reports/top_sellers?period=last_month \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'reports/top_sellers', { period: 'last_month', } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'last_month' ]; print_r($woocommerce->get('reports/top_sellers', $query)); ?> ``` ```python print(wcapi.get("reports/top_sellers?period=last_month").json()) ``` ```ruby query = { period: "last_month" } woocommerce.get("reports/top_sellers", query).parsed_response ``` ```json [ { "title": "Happy Ninja", "product_id": 37, "quantity": 1, "_links": { "about": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ], "product": [ { "href": "https://example.com/wp-json/wc/v3/products/37" } ] } }, { "title": "Woo Album #4", "product_id": 96, "quantity": 1, "_links": { "about": [ { "href": "https://example.com/wp-json/wc/v3/reports" } ], "product": [ { "href": "https://example.com/wp-json/wc/v3/products/96" } ] } } ] ``` #### Top sellers report properties | Attribute | Type | Description | | ------------ | ------- | -------------------------------------------------------------------- | | `title` | string | Product title. `READ-ONLY` | | `product_id` | integer | Product ID. `READ-ONLY` | | `quantity` | integer | Total number of purchases. `READ-ONLY` | #### Available parameters | Parameter | Type | Description | | ---------- | ------ | ----------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Default is `view`. Options: `view`. | | `period` | string | Report period. Default is `week`. Options: `week`, `month`, `last_month` and `year` | | `date_min` | string | Return sales for a specific start date, the date need to be in the YYYY-MM-DD format. | | `date_max` | string | Return sales for a specific end date, the date need to be in the YYYY-MM-DD format. | ## Retrieve coupons totals This API lets you retrieve and view coupons totals report. ```http GET /wp-json/wc/v3/reports/coupons/totals ``` ```shell curl https://example.com/wp-json/wc/v3/reports/coupons/totals \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'reports/coupons/totals' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('reports/coupons/totals')); ?> ``` ```python print(wcapi.get("reports/coupons/totals").json()) ``` ```ruby woocommerce.get("reports/coupons/totals").parsed_response ``` ```json [ { "slug": "percent", "name": "Percentage discount", "total": 2 }, { "slug": "fixed_cart", "name": "Fixed cart discount", "total": 1 }, { "slug": "fixed_product", "name": "Fixed product discount", "total": 1 } ] ``` #### Coupons totals properties | Attribute | Type | Description | | --------- | ------ | -------------------------------------------------------------------------------------- | | `slug` | string | An alphanumeric identifier for the resource. `READ-ONLY` | | `name` | string | Coupon type name. `READ-ONLY` | | `total` | string | Amount of coupons. `READ-ONLY` | ## Retrieve customers totals This API lets you retrieve and view customers totals report. ```http GET /wp-json/wc/v3/reports/customers/totals ``` ```shell curl https://example.com/wp-json/wc/v3/reports/customers/totals \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'reports/customers/totals' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('reports/customers/totals')); ?> ``` ```python print(wcapi.get("reports/customers/totals").json()) ``` ```ruby woocommerce.get("reports/customers/totals").parsed_response ``` ```json [ { "slug": "paying", "name": "Paying customer", "total": 2 }, { "slug": "non_paying", "name": "Non-paying customer", "total": 1 } ] ``` #### Customers totals properties | Attribute | Type | Description | | --------- | ------ | -------------------------------------------------------------------------------------- | | `slug` | string | An alphanumeric identifier for the resource. `READ-ONLY` | | `name` | string | Customer type name. `READ-ONLY` | | `total` | string | Amount of customers. `READ-ONLY` | ## Retrieve orders totals This API lets you retrieve and view orders totals report. ```http GET /wp-json/wc/v3/reports/orders/totals ``` ```shell curl https://example.com/wp-json/wc/v3/reports/orders/totals \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'reports/orders/totals' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('reports/orders/totals')); ?> ``` ```python print(wcapi.get("reports/orders/totals").json()) ``` ```ruby woocommerce.get("reports/orders/totals").parsed_response ``` ```json [ { "slug": "pending", "name": "Pending payment", "total": 7 }, { "slug": "processing", "name": "Processing", "total": 2 }, { "slug": "on-hold", "name": "On hold", "total": 1 }, { "slug": "completed", "name": "Completed", "total": 3 }, { "slug": "cancelled", "name": "Cancelled", "total": 0 }, { "slug": "refunded", "name": "Refunded", "total": 0 }, { "slug": "failed", "name": "Failed", "total": 0 } ] ``` #### Orders totals properties | Attribute | Type | Description | | --------- | ------ | -------------------------------------------------------------------------------------- | | `slug` | string | An alphanumeric identifier for the resource. `READ-ONLY` | | `name` | string | Orders status name. `READ-ONLY` | | `total` | string | Amount of orders. `READ-ONLY` | ## Retrieve products totals This API lets you retrieve and view products totals report. ```http GET /wp-json/wc/v3/reports/products/totals ``` ```shell curl https://example.com/wp-json/wc/v3/reports/products/totals \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'reports/products/totals' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('reports/products/totals')); ?> ``` ```python print(wcapi.get("reports/products/totals").json()) ``` ```ruby woocommerce.get("reports/products/totals").parsed_response ``` ```json [ { "slug": "external", "name": "External/Affiliate product", "total": 1 }, { "slug": "grouped", "name": "Grouped product", "total": 1 }, { "slug": "simple", "name": "Simple product", "total": 21 }, { "slug": "variable", "name": "Variable product", "total": 3 } ] ``` #### Products totals properties | Attribute | Type | Description | | --------- | ------ | -------------------------------------------------------------------------------------- | | `slug` | string | An alphanumeric identifier for the resource. `READ-ONLY` | | `name` | string | Product type name. `READ-ONLY` | | `total` | string | Amount of products. `READ-ONLY` | ## Retrieve reviews totals This API lets you retrieve and view reviews totals report. ```http GET /wp-json/wc/v3/reports/reviews/totals ``` ```shell curl https://example.com/wp-json/wc/v3/reports/reviews/totals \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'reports/reviews/totals' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('reports/reviews/totals')); ?> ``` ```python print(wcapi.get("reports/reviews/totals").json()) ``` ```ruby woocommerce.get("reports/reviews/totals").parsed_response ``` ```json [ { "slug": "rated_1_out_of_5", "name": "Rated 1 out of 5", "total": 1 }, { "slug": "rated_2_out_of_5", "name": "Rated 2 out of 5", "total": 0 }, { "slug": "rated_3_out_of_5", "name": "Rated 3 out of 5", "total": 3 }, { "slug": "rated_4_out_of_5", "name": "Rated 4 out of 5", "total": 0 }, { "slug": "rated_5_out_of_5", "name": "Rated 5 out of 5", "total": 4 } ] ``` #### Reviews totals properties | Attribute | Type | Description | | --------- | ------ | -------------------------------------------------------------------------------------- | | `slug` | string | An alphanumeric identifier for the resource. `READ-ONLY` | | `name` | string | Review type name. `READ-ONLY` | | `total` | string | Amount of reviews. `READ-ONLY` | --- ## Setting options *Source: apis/rest-api/v3/setting-options.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Setting options ## Setting option properties | Attribute | Type | Description | | ------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | string | A unique identifier for the setting. `READ-ONLY` | | `label` | string | A human readable label for the setting used in interfaces. `READ-ONLY` | | `description` | string | A human readable description for the setting used in interfaces. `READ-ONLY` | | `value` | mixed | Setting value. | | `default` | mixed | Default value for the setting. `READ-ONLY` | | `tip` | string | Additional help text shown to the user about the setting. `READ-ONLY` | | `placeholder` | string | Placeholder text to be displayed in text inputs. `READ-ONLY` | | `type` | string | Type of setting. Options: `text`, `email`, `number`, `color`, `password`, `textarea`, `select`, `multiselect`, `radio`, `image_width` and `checkbox`. `READ-ONLY` | | `options` | object | Array of options (key value pairs) for inputs such as select, multiselect, and radio buttons. `READ-ONLY` | | `group_id` | string | An identifier for the group this setting belongs to. `READ-ONLY` | ## Retrieve a setting option This API lets you retrieve and view a specific setting option. ```http GET /wp-json/wc/v3/settings// ``` ```shell curl https://example.com/wp-json/wc/v3/settings/general/woocommerce_allowed_countries \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'settings/general/woocommerce_allowed_countries' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('settings/general/woocommerce_allowed_countries')); ?> ``` ```python print(wcapi.get("settings/general/woocommerce_allowed_countries").json()) ``` ```ruby woocommerce.get("settings/general/woocommerce_allowed_countries").parsed_response ``` ```json { "id": "woocommerce_allowed_countries", "label": "Selling location(s)", "description": "This option lets you limit which countries you are willing to sell to.", "type": "select", "default": "all", "options": { "all": "Sell to all countries", "all_except": "Sell to all countries, except for…", "specific": "Sell to specific countries" }, "tip": "This option lets you limit which countries you are willing to sell to.", "value": "all", "group_id": "general", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_allowed_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } } ``` ## List all setting options This API helps you to view all the setting options. ```http GET /wp-json/wc/v3/settings/ ``` ```shell curl https://example.com/wp-json/wc/v3/settings/general \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'settings/general' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('settings/general')); ?> ``` ```python print(wcapi.get("settings/general").json()) ``` ```ruby woocommerce.get("settings/general").parsed_response ``` ```json [ { "id": "woocommerce_allowed_countries", "label": "Selling location(s)", "description": "This option lets you limit which countries you are willing to sell to.", "type": "select", "default": "all", "options": { "all": "Sell to all countries", "all_except": "Sell to all countries, except for…", "specific": "Sell to specific countries" }, "tip": "This option lets you limit which countries you are willing to sell to.", "value": "all", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_allowed_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_all_except_countries", "label": "Sell to all countries, except for…", "description": "", "type": "multiselect", "default": "", "value": "", "options": { "AX": "Åland Islands", "AF": "Afghanistan", "AL": "Albania", "DZ": "Algeria", "AS": "American Samoa", "AD": "Andorra", "AO": "Angola", "AI": "Anguilla", "AQ": "Antarctica", "AG": "Antigua and Barbuda", "AR": "Argentina", "AM": "Armenia", "AW": "Aruba", "AU": "Australia", "AT": "Austria", "AZ": "Azerbaijan", "BS": "Bahamas", "BH": "Bahrain", "BD": "Bangladesh", "BB": "Barbados", "BY": "Belarus", "PW": "Belau", "BE": "Belgium", "BZ": "Belize", "BJ": "Benin", "BM": "Bermuda", "BT": "Bhutan", "BO": "Bolivia", "BQ": "Bonaire, Saint Eustatius and Saba", "BA": "Bosnia and Herzegovina", "BW": "Botswana", "BV": "Bouvet Island", "BR": "Brazil", "IO": "British Indian Ocean Territory", "VG": "British Virgin Islands", "BN": "Brunei", "BG": "Bulgaria", "BF": "Burkina Faso", "BI": "Burundi", "KH": "Cambodia", "CM": "Cameroon", "CA": "Canada", "CV": "Cape Verde", "KY": "Cayman Islands", "CF": "Central African Republic", "TD": "Chad", "CL": "Chile", "CN": "China", "CX": "Christmas Island", "CC": "Cocos (Keeling) Islands", "CO": "Colombia", "KM": "Comoros", "CG": "Congo (Brazzaville)", "CD": "Congo (Kinshasa)", "CK": "Cook Islands", "CR": "Costa Rica", "HR": "Croatia", "CU": "Cuba", "CW": "Curaçao", "CY": "Cyprus", "CZ": "Czech Republic", "DK": "Denmark", "DJ": "Djibouti", "DM": "Dominica", "DO": "Dominican Republic", "EC": "Ecuador", "EG": "Egypt", "SV": "El Salvador", "GQ": "Equatorial Guinea", "ER": "Eritrea", "EE": "Estonia", "ET": "Ethiopia", "FK": "Falkland Islands", "FO": "Faroe Islands", "FJ": "Fiji", "FI": "Finland", "FR": "France", "GF": "French Guiana", "PF": "French Polynesia", "TF": "French Southern Territories", "GA": "Gabon", "GM": "Gambia", "GE": "Georgia", "DE": "Germany", "GH": "Ghana", "GI": "Gibraltar", "GR": "Greece", "GL": "Greenland", "GD": "Grenada", "GP": "Guadeloupe", "GU": "Guam", "GT": "Guatemala", "GG": "Guernsey", "GN": "Guinea", "GW": "Guinea-Bissau", "GY": "Guyana", "HT": "Haiti", "HM": "Heard Island and McDonald Islands", "HN": "Honduras", "HK": "Hong Kong", "HU": "Hungary", "IS": "Iceland", "IN": "India", "ID": "Indonesia", "IR": "Iran", "IQ": "Iraq", "IE": "Ireland", "IM": "Isle of Man", "IL": "Israel", "IT": "Italy", "CI": "Ivory Coast", "JM": "Jamaica", "JP": "Japan", "JE": "Jersey", "JO": "Jordan", "KZ": "Kazakhstan", "KE": "Kenya", "KI": "Kiribati", "KW": "Kuwait", "KG": "Kyrgyzstan", "LA": "Laos", "LV": "Latvia", "LB": "Lebanon", "LS": "Lesotho", "LR": "Liberia", "LY": "Libya", "LI": "Liechtenstein", "LT": "Lithuania", "LU": "Luxembourg", "MO": "Macao S.A.R., China", "MK": "Macedonia", "MG": "Madagascar", "MW": "Malawi", "MY": "Malaysia", "MV": "Maldives", "ML": "Mali", "MT": "Malta", "MH": "Marshall Islands", "MQ": "Martinique", "MR": "Mauritania", "MU": "Mauritius", "YT": "Mayotte", "MX": "Mexico", "FM": "Micronesia", "MD": "Moldova", "MC": "Monaco", "MN": "Mongolia", "ME": "Montenegro", "MS": "Montserrat", "MA": "Morocco", "MZ": "Mozambique", "MM": "Myanmar", "NA": "Namibia", "NR": "Nauru", "NP": "Nepal", "NL": "Netherlands", "NC": "New Caledonia", "NZ": "New Zealand", "NI": "Nicaragua", "NE": "Niger", "NG": "Nigeria", "NU": "Niue", "NF": "Norfolk Island", "KP": "North Korea", "MP": "Northern Mariana Islands", "NO": "Norway", "OM": "Oman", "PK": "Pakistan", "PS": "Palestinian Territory", "PA": "Panama", "PG": "Papua New Guinea", "PY": "Paraguay", "PE": "Peru", "PH": "Philippines", "PN": "Pitcairn", "PL": "Poland", "PT": "Portugal", "PR": "Puerto Rico", "QA": "Qatar", "RE": "Reunion", "RO": "Romania", "RU": "Russia", "RW": "Rwanda", "ST": "São Tomé and Príncipe", "BL": "Saint Barthélemy", "SH": "Saint Helena", "KN": "Saint Kitts and Nevis", "LC": "Saint Lucia", "SX": "Saint Martin (Dutch part)", "MF": "Saint Martin (French part)", "PM": "Saint Pierre and Miquelon", "VC": "Saint Vincent and the Grenadines", "WS": "Samoa", "SM": "San Marino", "SA": "Saudi Arabia", "SN": "Senegal", "RS": "Serbia", "SC": "Seychelles", "SL": "Sierra Leone", "SG": "Singapore", "SK": "Slovakia", "SI": "Slovenia", "SB": "Solomon Islands", "SO": "Somalia", "ZA": "South Africa", "GS": "South Georgia/Sandwich Islands", "KR": "South Korea", "SS": "South Sudan", "ES": "Spain", "LK": "Sri Lanka", "SD": "Sudan", "SR": "Suriname", "SJ": "Svalbard and Jan Mayen", "SZ": "Swaziland", "SE": "Sweden", "CH": "Switzerland", "SY": "Syria", "TW": "Taiwan", "TJ": "Tajikistan", "TZ": "Tanzania", "TH": "Thailand", "TL": "Timor-Leste", "TG": "Togo", "TK": "Tokelau", "TO": "Tonga", "TT": "Trinidad and Tobago", "TN": "Tunisia", "TR": "Turkey", "TM": "Turkmenistan", "TC": "Turks and Caicos Islands", "TV": "Tuvalu", "UG": "Uganda", "UA": "Ukraine", "AE": "United Arab Emirates", "GB": "United Kingdom (UK)", "US": "United States (US)", "UM": "United States (US) Minor Outlying Islands", "VI": "United States (US) Virgin Islands", "UY": "Uruguay", "UZ": "Uzbekistan", "VU": "Vanuatu", "VA": "Vatican", "VE": "Venezuela", "VN": "Vietnam", "WF": "Wallis and Futuna", "EH": "Western Sahara", "YE": "Yemen", "ZM": "Zambia", "ZW": "Zimbabwe" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_all_except_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_specific_allowed_countries", "label": "Sell to specific countries", "description": "", "type": "multiselect", "default": "", "value": "", "options": { "AX": "Åland Islands", "AF": "Afghanistan", "AL": "Albania", "DZ": "Algeria", "AS": "American Samoa", "AD": "Andorra", "AO": "Angola", "AI": "Anguilla", "AQ": "Antarctica", "AG": "Antigua and Barbuda", "AR": "Argentina", "AM": "Armenia", "AW": "Aruba", "AU": "Australia", "AT": "Austria", "AZ": "Azerbaijan", "BS": "Bahamas", "BH": "Bahrain", "BD": "Bangladesh", "BB": "Barbados", "BY": "Belarus", "PW": "Belau", "BE": "Belgium", "BZ": "Belize", "BJ": "Benin", "BM": "Bermuda", "BT": "Bhutan", "BO": "Bolivia", "BQ": "Bonaire, Saint Eustatius and Saba", "BA": "Bosnia and Herzegovina", "BW": "Botswana", "BV": "Bouvet Island", "BR": "Brazil", "IO": "British Indian Ocean Territory", "VG": "British Virgin Islands", "BN": "Brunei", "BG": "Bulgaria", "BF": "Burkina Faso", "BI": "Burundi", "KH": "Cambodia", "CM": "Cameroon", "CA": "Canada", "CV": "Cape Verde", "KY": "Cayman Islands", "CF": "Central African Republic", "TD": "Chad", "CL": "Chile", "CN": "China", "CX": "Christmas Island", "CC": "Cocos (Keeling) Islands", "CO": "Colombia", "KM": "Comoros", "CG": "Congo (Brazzaville)", "CD": "Congo (Kinshasa)", "CK": "Cook Islands", "CR": "Costa Rica", "HR": "Croatia", "CU": "Cuba", "CW": "Curaçao", "CY": "Cyprus", "CZ": "Czech Republic", "DK": "Denmark", "DJ": "Djibouti", "DM": "Dominica", "DO": "Dominican Republic", "EC": "Ecuador", "EG": "Egypt", "SV": "El Salvador", "GQ": "Equatorial Guinea", "ER": "Eritrea", "EE": "Estonia", "ET": "Ethiopia", "FK": "Falkland Islands", "FO": "Faroe Islands", "FJ": "Fiji", "FI": "Finland", "FR": "France", "GF": "French Guiana", "PF": "French Polynesia", "TF": "French Southern Territories", "GA": "Gabon", "GM": "Gambia", "GE": "Georgia", "DE": "Germany", "GH": "Ghana", "GI": "Gibraltar", "GR": "Greece", "GL": "Greenland", "GD": "Grenada", "GP": "Guadeloupe", "GU": "Guam", "GT": "Guatemala", "GG": "Guernsey", "GN": "Guinea", "GW": "Guinea-Bissau", "GY": "Guyana", "HT": "Haiti", "HM": "Heard Island and McDonald Islands", "HN": "Honduras", "HK": "Hong Kong", "HU": "Hungary", "IS": "Iceland", "IN": "India", "ID": "Indonesia", "IR": "Iran", "IQ": "Iraq", "IE": "Ireland", "IM": "Isle of Man", "IL": "Israel", "IT": "Italy", "CI": "Ivory Coast", "JM": "Jamaica", "JP": "Japan", "JE": "Jersey", "JO": "Jordan", "KZ": "Kazakhstan", "KE": "Kenya", "KI": "Kiribati", "KW": "Kuwait", "KG": "Kyrgyzstan", "LA": "Laos", "LV": "Latvia", "LB": "Lebanon", "LS": "Lesotho", "LR": "Liberia", "LY": "Libya", "LI": "Liechtenstein", "LT": "Lithuania", "LU": "Luxembourg", "MO": "Macao S.A.R., China", "MK": "Macedonia", "MG": "Madagascar", "MW": "Malawi", "MY": "Malaysia", "MV": "Maldives", "ML": "Mali", "MT": "Malta", "MH": "Marshall Islands", "MQ": "Martinique", "MR": "Mauritania", "MU": "Mauritius", "YT": "Mayotte", "MX": "Mexico", "FM": "Micronesia", "MD": "Moldova", "MC": "Monaco", "MN": "Mongolia", "ME": "Montenegro", "MS": "Montserrat", "MA": "Morocco", "MZ": "Mozambique", "MM": "Myanmar", "NA": "Namibia", "NR": "Nauru", "NP": "Nepal", "NL": "Netherlands", "NC": "New Caledonia", "NZ": "New Zealand", "NI": "Nicaragua", "NE": "Niger", "NG": "Nigeria", "NU": "Niue", "NF": "Norfolk Island", "KP": "North Korea", "MP": "Northern Mariana Islands", "NO": "Norway", "OM": "Oman", "PK": "Pakistan", "PS": "Palestinian Territory", "PA": "Panama", "PG": "Papua New Guinea", "PY": "Paraguay", "PE": "Peru", "PH": "Philippines", "PN": "Pitcairn", "PL": "Poland", "PT": "Portugal", "PR": "Puerto Rico", "QA": "Qatar", "RE": "Reunion", "RO": "Romania", "RU": "Russia", "RW": "Rwanda", "ST": "São Tomé and Príncipe", "BL": "Saint Barthélemy", "SH": "Saint Helena", "KN": "Saint Kitts and Nevis", "LC": "Saint Lucia", "SX": "Saint Martin (Dutch part)", "MF": "Saint Martin (French part)", "PM": "Saint Pierre and Miquelon", "VC": "Saint Vincent and the Grenadines", "WS": "Samoa", "SM": "San Marino", "SA": "Saudi Arabia", "SN": "Senegal", "RS": "Serbia", "SC": "Seychelles", "SL": "Sierra Leone", "SG": "Singapore", "SK": "Slovakia", "SI": "Slovenia", "SB": "Solomon Islands", "SO": "Somalia", "ZA": "South Africa", "GS": "South Georgia/Sandwich Islands", "KR": "South Korea", "SS": "South Sudan", "ES": "Spain", "LK": "Sri Lanka", "SD": "Sudan", "SR": "Suriname", "SJ": "Svalbard and Jan Mayen", "SZ": "Swaziland", "SE": "Sweden", "CH": "Switzerland", "SY": "Syria", "TW": "Taiwan", "TJ": "Tajikistan", "TZ": "Tanzania", "TH": "Thailand", "TL": "Timor-Leste", "TG": "Togo", "TK": "Tokelau", "TO": "Tonga", "TT": "Trinidad and Tobago", "TN": "Tunisia", "TR": "Turkey", "TM": "Turkmenistan", "TC": "Turks and Caicos Islands", "TV": "Tuvalu", "UG": "Uganda", "UA": "Ukraine", "AE": "United Arab Emirates", "GB": "United Kingdom (UK)", "US": "United States (US)", "UM": "United States (US) Minor Outlying Islands", "VI": "United States (US) Virgin Islands", "UY": "Uruguay", "UZ": "Uzbekistan", "VU": "Vanuatu", "VA": "Vatican", "VE": "Venezuela", "VN": "Vietnam", "WF": "Wallis and Futuna", "EH": "Western Sahara", "YE": "Yemen", "ZM": "Zambia", "ZW": "Zimbabwe" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_specific_allowed_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_ship_to_countries", "label": "Shipping location(s)", "description": "Choose which countries you want to ship to, or choose to ship to all locations you sell to.", "type": "select", "default": "", "options": { "": "Ship to all countries you sell to", "all": "Ship to all countries", "specific": "Ship to specific countries only", "disabled": "Disable shipping & shipping calculations" }, "tip": "Choose which countries you want to ship to, or choose to ship to all locations you sell to.", "value": "", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_ship_to_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_specific_ship_to_countries", "label": "Ship to specific countries", "description": "", "type": "multiselect", "default": "", "value": "", "options": { "AX": "Åland Islands", "AF": "Afghanistan", "AL": "Albania", "DZ": "Algeria", "AS": "American Samoa", "AD": "Andorra", "AO": "Angola", "AI": "Anguilla", "AQ": "Antarctica", "AG": "Antigua and Barbuda", "AR": "Argentina", "AM": "Armenia", "AW": "Aruba", "AU": "Australia", "AT": "Austria", "AZ": "Azerbaijan", "BS": "Bahamas", "BH": "Bahrain", "BD": "Bangladesh", "BB": "Barbados", "BY": "Belarus", "PW": "Belau", "BE": "Belgium", "BZ": "Belize", "BJ": "Benin", "BM": "Bermuda", "BT": "Bhutan", "BO": "Bolivia", "BQ": "Bonaire, Saint Eustatius and Saba", "BA": "Bosnia and Herzegovina", "BW": "Botswana", "BV": "Bouvet Island", "BR": "Brazil", "IO": "British Indian Ocean Territory", "VG": "British Virgin Islands", "BN": "Brunei", "BG": "Bulgaria", "BF": "Burkina Faso", "BI": "Burundi", "KH": "Cambodia", "CM": "Cameroon", "CA": "Canada", "CV": "Cape Verde", "KY": "Cayman Islands", "CF": "Central African Republic", "TD": "Chad", "CL": "Chile", "CN": "China", "CX": "Christmas Island", "CC": "Cocos (Keeling) Islands", "CO": "Colombia", "KM": "Comoros", "CG": "Congo (Brazzaville)", "CD": "Congo (Kinshasa)", "CK": "Cook Islands", "CR": "Costa Rica", "HR": "Croatia", "CU": "Cuba", "CW": "Curaçao", "CY": "Cyprus", "CZ": "Czech Republic", "DK": "Denmark", "DJ": "Djibouti", "DM": "Dominica", "DO": "Dominican Republic", "EC": "Ecuador", "EG": "Egypt", "SV": "El Salvador", "GQ": "Equatorial Guinea", "ER": "Eritrea", "EE": "Estonia", "ET": "Ethiopia", "FK": "Falkland Islands", "FO": "Faroe Islands", "FJ": "Fiji", "FI": "Finland", "FR": "France", "GF": "French Guiana", "PF": "French Polynesia", "TF": "French Southern Territories", "GA": "Gabon", "GM": "Gambia", "GE": "Georgia", "DE": "Germany", "GH": "Ghana", "GI": "Gibraltar", "GR": "Greece", "GL": "Greenland", "GD": "Grenada", "GP": "Guadeloupe", "GU": "Guam", "GT": "Guatemala", "GG": "Guernsey", "GN": "Guinea", "GW": "Guinea-Bissau", "GY": "Guyana", "HT": "Haiti", "HM": "Heard Island and McDonald Islands", "HN": "Honduras", "HK": "Hong Kong", "HU": "Hungary", "IS": "Iceland", "IN": "India", "ID": "Indonesia", "IR": "Iran", "IQ": "Iraq", "IE": "Ireland", "IM": "Isle of Man", "IL": "Israel", "IT": "Italy", "CI": "Ivory Coast", "JM": "Jamaica", "JP": "Japan", "JE": "Jersey", "JO": "Jordan", "KZ": "Kazakhstan", "KE": "Kenya", "KI": "Kiribati", "KW": "Kuwait", "KG": "Kyrgyzstan", "LA": "Laos", "LV": "Latvia", "LB": "Lebanon", "LS": "Lesotho", "LR": "Liberia", "LY": "Libya", "LI": "Liechtenstein", "LT": "Lithuania", "LU": "Luxembourg", "MO": "Macao S.A.R., China", "MK": "Macedonia", "MG": "Madagascar", "MW": "Malawi", "MY": "Malaysia", "MV": "Maldives", "ML": "Mali", "MT": "Malta", "MH": "Marshall Islands", "MQ": "Martinique", "MR": "Mauritania", "MU": "Mauritius", "YT": "Mayotte", "MX": "Mexico", "FM": "Micronesia", "MD": "Moldova", "MC": "Monaco", "MN": "Mongolia", "ME": "Montenegro", "MS": "Montserrat", "MA": "Morocco", "MZ": "Mozambique", "MM": "Myanmar", "NA": "Namibia", "NR": "Nauru", "NP": "Nepal", "NL": "Netherlands", "NC": "New Caledonia", "NZ": "New Zealand", "NI": "Nicaragua", "NE": "Niger", "NG": "Nigeria", "NU": "Niue", "NF": "Norfolk Island", "KP": "North Korea", "MP": "Northern Mariana Islands", "NO": "Norway", "OM": "Oman", "PK": "Pakistan", "PS": "Palestinian Territory", "PA": "Panama", "PG": "Papua New Guinea", "PY": "Paraguay", "PE": "Peru", "PH": "Philippines", "PN": "Pitcairn", "PL": "Poland", "PT": "Portugal", "PR": "Puerto Rico", "QA": "Qatar", "RE": "Reunion", "RO": "Romania", "RU": "Russia", "RW": "Rwanda", "ST": "São Tomé and Príncipe", "BL": "Saint Barthélemy", "SH": "Saint Helena", "KN": "Saint Kitts and Nevis", "LC": "Saint Lucia", "SX": "Saint Martin (Dutch part)", "MF": "Saint Martin (French part)", "PM": "Saint Pierre and Miquelon", "VC": "Saint Vincent and the Grenadines", "WS": "Samoa", "SM": "San Marino", "SA": "Saudi Arabia", "SN": "Senegal", "RS": "Serbia", "SC": "Seychelles", "SL": "Sierra Leone", "SG": "Singapore", "SK": "Slovakia", "SI": "Slovenia", "SB": "Solomon Islands", "SO": "Somalia", "ZA": "South Africa", "GS": "South Georgia/Sandwich Islands", "KR": "South Korea", "SS": "South Sudan", "ES": "Spain", "LK": "Sri Lanka", "SD": "Sudan", "SR": "Suriname", "SJ": "Svalbard and Jan Mayen", "SZ": "Swaziland", "SE": "Sweden", "CH": "Switzerland", "SY": "Syria", "TW": "Taiwan", "TJ": "Tajikistan", "TZ": "Tanzania", "TH": "Thailand", "TL": "Timor-Leste", "TG": "Togo", "TK": "Tokelau", "TO": "Tonga", "TT": "Trinidad and Tobago", "TN": "Tunisia", "TR": "Turkey", "TM": "Turkmenistan", "TC": "Turks and Caicos Islands", "TV": "Tuvalu", "UG": "Uganda", "UA": "Ukraine", "AE": "United Arab Emirates", "GB": "United Kingdom (UK)", "US": "United States (US)", "UM": "United States (US) Minor Outlying Islands", "VI": "United States (US) Virgin Islands", "UY": "Uruguay", "UZ": "Uzbekistan", "VU": "Vanuatu", "VA": "Vatican", "VE": "Venezuela", "VN": "Vietnam", "WF": "Wallis and Futuna", "EH": "Western Sahara", "YE": "Yemen", "ZM": "Zambia", "ZW": "Zimbabwe" }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_specific_ship_to_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_default_customer_address", "label": "Default customer location", "description": "", "type": "select", "default": "geolocation", "options": { "": "No location by default", "base": "Shop base address", "geolocation": "Geolocate", "geolocation_ajax": "Geolocate (with page caching support)" }, "tip": "This option determines a customers default location. The MaxMind GeoLite Database will be periodically downloaded to your wp-content directory if using geolocation.", "value": "geolocation", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_default_customer_address" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_calc_taxes", "label": "Enable taxes", "description": "Enable taxes and tax calculations", "type": "checkbox", "default": "no", "value": "yes", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_calc_taxes" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_demo_store", "label": "Store notice", "description": "Enable site-wide store notice text", "type": "checkbox", "default": "no", "value": "no", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_demo_store" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_demo_store_notice", "label": "Store notice text", "description": "", "type": "textarea", "default": "This is a demo store for testing purposes — no orders shall be fulfilled.", "value": "This is a demo store for testing purposes — no orders shall be fulfilled.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_demo_store_notice" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_currency", "label": "Currency", "description": "This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.", "type": "select", "default": "GBP", "options": { "AED": "United Arab Emirates dirham (د.إ)", "AFN": "Afghan afghani (؋)", "ALL": "Albanian lek (L)", "AMD": "Armenian dram (AMD)", "ANG": "Netherlands Antillean guilder (ƒ)", "AOA": "Angolan kwanza (Kz)", "ARS": "Argentine peso ($)", "AUD": "Australian dollar ($)", "AWG": "Aruban florin (ƒ)", "AZN": "Azerbaijani manat (AZN)", "BAM": "Bosnia and Herzegovina convertible mark (KM)", "BBD": "Barbadian dollar ($)", "BDT": "Bangladeshi taka (৳ )", "BGN": "Bulgarian lev (лв.)", "BHD": "Bahraini dinar (.د.ب)", "BIF": "Burundian franc (Fr)", "BMD": "Bermudian dollar ($)", "BND": "Brunei dollar ($)", "BOB": "Bolivian boliviano (Bs.)", "BRL": "Brazilian real (R$)", "BSD": "Bahamian dollar ($)", "BTC": "Bitcoin (฿)", "BTN": "Bhutanese ngultrum (Nu.)", "BWP": "Botswana pula (P)", "BYR": "Belarusian ruble (Br)", "BZD": "Belize dollar ($)", "CAD": "Canadian dollar ($)", "CDF": "Congolese franc (Fr)", "CHF": "Swiss franc (CHF)", "CLP": "Chilean peso ($)", "CNY": "Chinese yuan (¥)", "COP": "Colombian peso ($)", "CRC": "Costa Rican colón (₡)", "CUC": "Cuban convertible peso ($)", "CUP": "Cuban peso ($)", "CVE": "Cape Verdean escudo ($)", "CZK": "Czech koruna (Kč)", "DJF": "Djiboutian franc (Fr)", "DKK": "Danish krone (DKK)", "DOP": "Dominican peso (RD$)", "DZD": "Algerian dinar (د.ج)", "EGP": "Egyptian pound (EGP)", "ERN": "Eritrean nakfa (Nfk)", "ETB": "Ethiopian birr (Br)", "EUR": "Euro (€)", "FJD": "Fijian dollar ($)", "FKP": "Falkland Islands pound (£)", "GBP": "Pound sterling (£)", "GEL": "Georgian lari (ლ)", "GGP": "Guernsey pound (£)", "GHS": "Ghana cedi (₵)", "GIP": "Gibraltar pound (£)", "GMD": "Gambian dalasi (D)", "GNF": "Guinean franc (Fr)", "GTQ": "Guatemalan quetzal (Q)", "GYD": "Guyanese dollar ($)", "HKD": "Hong Kong dollar ($)", "HNL": "Honduran lempira (L)", "HRK": "Croatian kuna (Kn)", "HTG": "Haitian gourde (G)", "HUF": "Hungarian forint (Ft)", "IDR": "Indonesian rupiah (Rp)", "ILS": "Israeli new shekel (₪)", "IMP": "Manx pound (£)", "INR": "Indian rupee (₹)", "IQD": "Iraqi dinar (ع.د)", "IRR": "Iranian rial (﷼)", "IRT": "Iranian toman (تومان)", "ISK": "Icelandic króna (kr.)", "JEP": "Jersey pound (£)", "JMD": "Jamaican dollar ($)", "JOD": "Jordanian dinar (د.ا)", "JPY": "Japanese yen (¥)", "KES": "Kenyan shilling (KSh)", "KGS": "Kyrgyzstani som (сом)", "KHR": "Cambodian riel (៛)", "KMF": "Comorian franc (Fr)", "KPW": "North Korean won (₩)", "KRW": "South Korean won (₩)", "KWD": "Kuwaiti dinar (د.ك)", "KYD": "Cayman Islands dollar ($)", "KZT": "Kazakhstani tenge (KZT)", "LAK": "Lao kip (₭)", "LBP": "Lebanese pound (ل.ل)", "LKR": "Sri Lankan rupee (රු)", "LRD": "Liberian dollar ($)", "LSL": "Lesotho loti (L)", "LYD": "Libyan dinar (ل.د)", "MAD": "Moroccan dirham (د.م.)", "MDL": "Moldovan leu (MDL)", "MGA": "Malagasy ariary (Ar)", "MKD": "Macedonian denar (ден)", "MMK": "Burmese kyat (Ks)", "MNT": "Mongolian tögrög (₮)", "MOP": "Macanese pataca (P)", "MRO": "Mauritanian ouguiya (UM)", "MUR": "Mauritian rupee (₨)", "MVR": "Maldivian rufiyaa (.ރ)", "MWK": "Malawian kwacha (MK)", "MXN": "Mexican peso ($)", "MYR": "Malaysian ringgit (RM)", "MZN": "Mozambican metical (MT)", "NAD": "Namibian dollar ($)", "NGN": "Nigerian naira (₦)", "NIO": "Nicaraguan córdoba (C$)", "NOK": "Norwegian krone (kr)", "NPR": "Nepalese rupee (₨)", "NZD": "New Zealand dollar ($)", "OMR": "Omani rial (ر.ع.)", "PAB": "Panamanian balboa (B/.)", "PEN": "Peruvian nuevo sol (S/.)", "PGK": "Papua New Guinean kina (K)", "PHP": "Philippine peso (₱)", "PKR": "Pakistani rupee (₨)", "PLN": "Polish złoty (zł)", "PRB": "Transnistrian ruble (р.)", "PYG": "Paraguayan guaraní (₲)", "QAR": "Qatari riyal (ر.ق)", "RON": "Romanian leu (lei)", "RSD": "Serbian dinar (дин.)", "RUB": "Russian ruble (₽)", "RWF": "Rwandan franc (Fr)", "SAR": "Saudi riyal (ر.س)", "SBD": "Solomon Islands dollar ($)", "SCR": "Seychellois rupee (₨)", "SDG": "Sudanese pound (ج.س.)", "SEK": "Swedish krona (kr)", "SGD": "Singapore dollar ($)", "SHP": "Saint Helena pound (£)", "SLL": "Sierra Leonean leone (Le)", "SOS": "Somali shilling (Sh)", "SRD": "Surinamese dollar ($)", "SSP": "South Sudanese pound (£)", "STD": "São Tomé and Príncipe dobra (Db)", "SYP": "Syrian pound (ل.س)", "SZL": "Swazi lilangeni (L)", "THB": "Thai baht (฿)", "TJS": "Tajikistani somoni (ЅМ)", "TMT": "Turkmenistan manat (m)", "TND": "Tunisian dinar (د.ت)", "TOP": "Tongan paʻanga (T$)", "TRY": "Turkish lira (₺)", "TTD": "Trinidad and Tobago dollar ($)", "TWD": "New Taiwan dollar (NT$)", "TZS": "Tanzanian shilling (Sh)", "UAH": "Ukrainian hryvnia (₴)", "UGX": "Ugandan shilling (UGX)", "USD": "United States dollar ($)", "UYU": "Uruguayan peso ($)", "UZS": "Uzbekistani som (UZS)", "VEF": "Venezuelan bolívar (Bs F)", "VND": "Vietnamese đồng (₫)", "VUV": "Vanuatu vatu (Vt)", "WST": "Samoan tālā (T)", "XAF": "Central African CFA franc (Fr)", "XCD": "East Caribbean dollar ($)", "XOF": "West African CFA franc (Fr)", "XPF": "CFP franc (Fr)", "YER": "Yemeni rial (﷼)", "ZAR": "South African rand (R)", "ZMW": "Zambian kwacha (K)" }, "tip": "This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.", "value": "USD", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_currency" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_currency_pos", "label": "Currency position", "description": "This controls the position of the currency symbol.", "type": "select", "default": "left", "options": { "left": "Left ($99.99)", "right": "Right (99.99$)", "left_space": "Left with space ($ 99.99)", "right_space": "Right with space (99.99 $)" }, "tip": "This controls the position of the currency symbol.", "value": "left", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_currency_pos" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_price_thousand_sep", "label": "Thousand separator", "description": "This sets the thousand separator of displayed prices.", "type": "text", "default": ",", "tip": "This sets the thousand separator of displayed prices.", "value": ",", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_price_thousand_sep" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_price_decimal_sep", "label": "Decimal separator", "description": "This sets the decimal separator of displayed prices.", "type": "text", "default": ".", "tip": "This sets the decimal separator of displayed prices.", "value": ".", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_price_decimal_sep" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_price_num_decimals", "label": "Number of decimals", "description": "This sets the number of decimal points shown in displayed prices.", "type": "number", "default": "2", "tip": "This sets the number of decimal points shown in displayed prices.", "value": "2", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_price_num_decimals" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } } ] ``` ## Update a setting option This API lets you make changes to a setting option. ```http PUT /wp-json/wc/v3/settings// ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/settings/general/woocommerce_allowed_countries \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "value": "all_except" }' ``` ```javascript const data = { value: 'all_except', }; WooCommerce.put( 'settings/general/woocommerce_allowed_countries', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'all_except' ]; print_r($woocommerce->put('settings/general/woocommerce_allowed_countries', $data)); ?> ``` ```python data = { "value": "all_except" } print(wcapi.put("settings/general/woocommerce_allowed_countries", data).json()) ``` ```ruby data = { value: "all_except" } woocommerce.put("settings/general/woocommerce_allowed_countries", data).parsed_response ``` ```json { "id": "woocommerce_allowed_countries", "label": "Selling location(s)", "description": "This option lets you limit which countries you are willing to sell to.", "type": "select", "default": "all", "options": { "all": "Sell to all countries", "all_except": "Sell to all countries, except for…", "specific": "Sell to specific countries" }, "tip": "This option lets you limit which countries you are willing to sell to.", "value": "all_except", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_allowed_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } } ``` ## Batch update setting options This API helps you to batch update multiple setting options. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/settings//batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/settings/general/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "update": [ { "id": "woocommerce_allowed_countries", "value": "all" }, { "id": "woocommerce_demo_store", "value": "yes" }, { "id": "woocommerce_currency", "value": "GBP" } ] }' ``` ```javascript const data = { create: [ { regular_price: '10.00', attributes: [ { id: 6, option: 'Blue', }, ], }, { regular_price: '10.00', attributes: [ { id: 6, option: 'White', }, ], }, ], update: [ { id: 733, regular_price: '10.00', }, ], delete: [ 732 ], }; WooCommerce.post( 'products/22/settings/general/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'regular_price' => '10.00', 'attributes' => [ [ 'id' => 6, 'option' => 'Blue' ] ] ], [ 'regular_price' => '10.00', 'attributes' => [ [ 'id' => 6, 'option' => 'White' ] ] ] ], 'update' => [ [ 'id' => 733, 'regular_price' => '10.00' ] ], 'delete' => [ 732 ] ]; print_r($woocommerce->post('products/22/settings/general/batch', $data)); ?> ``` ```python data = { "create": [ { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "Blue" } ] }, { "regular_price": "10.00", "attributes": [ { "id": 6, "option": "White" } ] } ], "update": [ { "id": 733, "regular_price": "10.00" } ], "delete": [ 732 ] } print(wcapi.post("products/22/settings/general/batch", data).json()) ``` ```ruby data = { create: [ { regular_price: "10.00", attributes: [ { id: 6, option: "Blue" } ] }, { regular_price: "10.00", attributes: [ { id: 6, option: "White" } ] } ], update: [ { id: 733, regular_price: "10.00" } ], delete: [ 732 ] } woocommerce.post("products/22/settings/general/batch", data).parsed_response ``` ```json { "update": [ { "id": "woocommerce_allowed_countries", "label": "Selling location(s)", "description": "This option lets you limit which countries you are willing to sell to.", "type": "select", "default": "all", "options": { "all": "Sell to all countries", "all_except": "Sell to all countries, except for…", "specific": "Sell to specific countries" }, "tip": "This option lets you limit which countries you are willing to sell to.", "value": "all", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_allowed_countries" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_demo_store", "label": "Store notice", "description": "Enable site-wide store notice text", "type": "checkbox", "default": "no", "value": "yes", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_demo_store" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "woocommerce_currency", "label": "Currency", "description": "This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.", "type": "select", "default": "GBP", "options": { "AED": "United Arab Emirates dirham (د.إ)", "AFN": "Afghan afghani (؋)", "ALL": "Albanian lek (L)", "AMD": "Armenian dram (AMD)", "ANG": "Netherlands Antillean guilder (ƒ)", "AOA": "Angolan kwanza (Kz)", "ARS": "Argentine peso ($)", "AUD": "Australian dollar ($)", "AWG": "Aruban florin (ƒ)", "AZN": "Azerbaijani manat (AZN)", "BAM": "Bosnia and Herzegovina convertible mark (KM)", "BBD": "Barbadian dollar ($)", "BDT": "Bangladeshi taka (৳ )", "BGN": "Bulgarian lev (лв.)", "BHD": "Bahraini dinar (.د.ب)", "BIF": "Burundian franc (Fr)", "BMD": "Bermudian dollar ($)", "BND": "Brunei dollar ($)", "BOB": "Bolivian boliviano (Bs.)", "BRL": "Brazilian real (R$)", "BSD": "Bahamian dollar ($)", "BTC": "Bitcoin (฿)", "BTN": "Bhutanese ngultrum (Nu.)", "BWP": "Botswana pula (P)", "BYR": "Belarusian ruble (Br)", "BZD": "Belize dollar ($)", "CAD": "Canadian dollar ($)", "CDF": "Congolese franc (Fr)", "CHF": "Swiss franc (CHF)", "CLP": "Chilean peso ($)", "CNY": "Chinese yuan (¥)", "COP": "Colombian peso ($)", "CRC": "Costa Rican colón (₡)", "CUC": "Cuban convertible peso ($)", "CUP": "Cuban peso ($)", "CVE": "Cape Verdean escudo ($)", "CZK": "Czech koruna (Kč)", "DJF": "Djiboutian franc (Fr)", "DKK": "Danish krone (DKK)", "DOP": "Dominican peso (RD$)", "DZD": "Algerian dinar (د.ج)", "EGP": "Egyptian pound (EGP)", "ERN": "Eritrean nakfa (Nfk)", "ETB": "Ethiopian birr (Br)", "EUR": "Euro (€)", "FJD": "Fijian dollar ($)", "FKP": "Falkland Islands pound (£)", "GBP": "Pound sterling (£)", "GEL": "Georgian lari (ლ)", "GGP": "Guernsey pound (£)", "GHS": "Ghana cedi (₵)", "GIP": "Gibraltar pound (£)", "GMD": "Gambian dalasi (D)", "GNF": "Guinean franc (Fr)", "GTQ": "Guatemalan quetzal (Q)", "GYD": "Guyanese dollar ($)", "HKD": "Hong Kong dollar ($)", "HNL": "Honduran lempira (L)", "HRK": "Croatian kuna (Kn)", "HTG": "Haitian gourde (G)", "HUF": "Hungarian forint (Ft)", "IDR": "Indonesian rupiah (Rp)", "ILS": "Israeli new shekel (₪)", "IMP": "Manx pound (£)", "INR": "Indian rupee (₹)", "IQD": "Iraqi dinar (ع.د)", "IRR": "Iranian rial (﷼)", "IRT": "Iranian toman (تومان)", "ISK": "Icelandic króna (kr.)", "JEP": "Jersey pound (£)", "JMD": "Jamaican dollar ($)", "JOD": "Jordanian dinar (د.ا)", "JPY": "Japanese yen (¥)", "KES": "Kenyan shilling (KSh)", "KGS": "Kyrgyzstani som (сом)", "KHR": "Cambodian riel (៛)", "KMF": "Comorian franc (Fr)", "KPW": "North Korean won (₩)", "KRW": "South Korean won (₩)", "KWD": "Kuwaiti dinar (د.ك)", "KYD": "Cayman Islands dollar ($)", "KZT": "Kazakhstani tenge (KZT)", "LAK": "Lao kip (₭)", "LBP": "Lebanese pound (ل.ل)", "LKR": "Sri Lankan rupee (රු)", "LRD": "Liberian dollar ($)", "LSL": "Lesotho loti (L)", "LYD": "Libyan dinar (ل.د)", "MAD": "Moroccan dirham (د.م.)", "MDL": "Moldovan leu (MDL)", "MGA": "Malagasy ariary (Ar)", "MKD": "Macedonian denar (ден)", "MMK": "Burmese kyat (Ks)", "MNT": "Mongolian tögrög (₮)", "MOP": "Macanese pataca (P)", "MRO": "Mauritanian ouguiya (UM)", "MUR": "Mauritian rupee (₨)", "MVR": "Maldivian rufiyaa (.ރ)", "MWK": "Malawian kwacha (MK)", "MXN": "Mexican peso ($)", "MYR": "Malaysian ringgit (RM)", "MZN": "Mozambican metical (MT)", "NAD": "Namibian dollar ($)", "NGN": "Nigerian naira (₦)", "NIO": "Nicaraguan córdoba (C$)", "NOK": "Norwegian krone (kr)", "NPR": "Nepalese rupee (₨)", "NZD": "New Zealand dollar ($)", "OMR": "Omani rial (ر.ع.)", "PAB": "Panamanian balboa (B/.)", "PEN": "Peruvian nuevo sol (S/.)", "PGK": "Papua New Guinean kina (K)", "PHP": "Philippine peso (₱)", "PKR": "Pakistani rupee (₨)", "PLN": "Polish złoty (zł)", "PRB": "Transnistrian ruble (р.)", "PYG": "Paraguayan guaraní (₲)", "QAR": "Qatari riyal (ر.ق)", "RON": "Romanian leu (lei)", "RSD": "Serbian dinar (дин.)", "RUB": "Russian ruble (₽)", "RWF": "Rwandan franc (Fr)", "SAR": "Saudi riyal (ر.س)", "SBD": "Solomon Islands dollar ($)", "SCR": "Seychellois rupee (₨)", "SDG": "Sudanese pound (ج.س.)", "SEK": "Swedish krona (kr)", "SGD": "Singapore dollar ($)", "SHP": "Saint Helena pound (£)", "SLL": "Sierra Leonean leone (Le)", "SOS": "Somali shilling (Sh)", "SRD": "Surinamese dollar ($)", "SSP": "South Sudanese pound (£)", "STD": "São Tomé and Príncipe dobra (Db)", "SYP": "Syrian pound (ل.س)", "SZL": "Swazi lilangeni (L)", "THB": "Thai baht (฿)", "TJS": "Tajikistani somoni (ЅМ)", "TMT": "Turkmenistan manat (m)", "TND": "Tunisian dinar (د.ت)", "TOP": "Tongan paʻanga (T$)", "TRY": "Turkish lira (₺)", "TTD": "Trinidad and Tobago dollar ($)", "TWD": "New Taiwan dollar (NT$)", "TZS": "Tanzanian shilling (Sh)", "UAH": "Ukrainian hryvnia (₴)", "UGX": "Ugandan shilling (UGX)", "USD": "United States dollar ($)", "UYU": "Uruguayan peso ($)", "UZS": "Uzbekistani som (UZS)", "VEF": "Venezuelan bolívar (Bs F)", "VND": "Vietnamese đồng (₫)", "VUV": "Vanuatu vatu (Vt)", "WST": "Samoan tālā (T)", "XAF": "Central African CFA franc (Fr)", "XCD": "East Caribbean dollar ($)", "XOF": "West African CFA franc (Fr)", "XPF": "CFP franc (Fr)", "YER": "Yemeni rial (﷼)", "ZAR": "South African rand (R)", "ZMW": "Zambian kwacha (K)" }, "tip": "This controls what currency prices are listed at in the catalog and which currency gateways will take payments in.", "value": "GBP", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/settings/general/woocommerce_currency" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } } ] } ``` --- ## Settings *Source: apis/rest-api/v3/settings.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Settings The settings API allows you to view all groups of settings available. ## Setting group properties | Attribute | Type | Description | | ------------- | ------ | ---------------------------------------------------------------------------------------------------------- | | `id` | string | A unique identifier that can be used to link settings together. `READ-ONLY` | | `label` | string | A human readable label for the setting used in interfaces. `READ-ONLY` | | `description` | string | A human readable description for the setting used in interfaces. `READ-ONLY` | | `parent_id` | string | ID of parent grouping. `READ-ONLY` | | `sub_groups` | string | IDs for settings sub groups. `READ-ONLY` | ## List all settings groups This API helps you to view all the settings groups. ```http GET /wp-json/wc/v3/settings ``` ```shell curl https://example.com/wp-json/wc/v3/settings \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'settings' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('settings')); ?> ``` ```python print(wcapi.get("settings").json()) ``` ```ruby woocommerce.get("settings").parsed_response ``` ```json [ { "id": "general", "label": "General", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/general" } ] } }, { "id": "products", "label": "Products", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/products" } ] } }, { "id": "tax", "label": "Tax", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/tax" } ] } }, { "id": "shipping", "label": "Shipping", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/shipping" } ] } }, { "id": "checkout", "label": "Checkout", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/checkout" } ] } }, { "id": "account", "label": "Accounts", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/account" } ] } }, { "id": "email", "label": "Emails", "description": "", "parent_id": "", "sub_groups": [ "email_new_order", "email_cancelled_order", "email_failed_order", "email_customer_on_hold_order", "email_customer_processing_order", "email_customer_completed_order", "email_customer_refunded_order", "email_customer_invoice", "email_customer_note", "email_customer_reset_password", "email_customer_new_account" ], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email" } ] } }, { "id": "integration", "label": "Integration", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/integration" } ] } }, { "id": "api", "label": "API", "description": "", "parent_id": "", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/api" } ] } }, { "id": "email_new_order", "label": "New order", "description": "New order emails are sent to chosen recipient(s) when a new order is received.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email_new_order" } ] } }, { "id": "email_cancelled_order", "label": "Cancelled order", "description": "Cancelled order emails are sent to chosen recipient(s) when orders have been marked cancelled (if they were previously processing or on-hold).", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email_cancelled_order" } ] } }, { "id": "email_failed_order", "label": "Failed order", "description": "Failed order emails are sent to chosen recipient(s) when orders have been marked failed (if they were previously processing or on-hold).", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email_failed_order" } ] } }, { "id": "email_customer_on_hold_order", "label": "Order on-hold", "description": "This is an order notification sent to customers containing order details after an order is placed on-hold.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email_customer_on_hold_order" } ] } }, { "id": "email_customer_processing_order", "label": "Processing order", "description": "This is an order notification sent to customers containing order details after payment.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email_customer_processing_order" } ] } }, { "id": "email_customer_completed_order", "label": "Completed order", "description": "Order complete emails are sent to customers when their orders are marked completed and usually indicate that their orders have been shipped.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email_customer_completed_order" } ] } }, { "id": "email_customer_refunded_order", "label": "Refunded order", "description": "Order refunded emails are sent to customers when their orders are marked refunded.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email_customer_refunded_order" } ] } }, { "id": "email_customer_invoice", "label": "Customer invoice", "description": "Customer invoice emails can be sent to customers containing their order information and payment links.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email_customer_invoice" } ] } }, { "id": "email_customer_note", "label": "Customer note", "description": "Customer note emails are sent when you add a note to an order.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email_customer_note" } ] } }, { "id": "email_customer_reset_password", "label": "Reset password", "description": "Customer \"reset password\" emails are sent when customers reset their passwords.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email_customer_reset_password" } ] } }, { "id": "email_customer_new_account", "label": "New account", "description": "Customer \"new account\" emails are sent to the customer when a customer signs up via checkout or account pages.", "parent_id": "email", "sub_groups": [], "_links": { "options": [ { "href": "https://example.com/wp-json/wc/v3/settings/email_customer_new_account" } ] } } ] ``` --- ## Shipping methods *Source: apis/rest-api/v3/shipping-methods.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Shipping methods The shipping methods API allows you to view individual shipping methods. ## Shipping method properties | Attribute | Type | Description | | ------------- | ------ | ---------------------------------------------------------------------- | | `id` | string | Method ID. `READ-ONLY` | | `title` | string | Shipping method title. `READ-ONLY` | | `description` | string | Shipping method description. `READ-ONLY` | ## Retrieve a shipping method This API lets you retrieve and view a specific shipping method. ```http GET /wp-json/wc/v3/shipping_methods/ ``` ```shell curl https://example.com/wp-json/wc/v3/shipping_methods/flat_rate \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'shipping_methods/flat_rate' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('shipping_methods/flat_rate')); ?> ``` ```python print(wcapi.get("shipping_methods/flat_rate").json()) ``` ```ruby woocommerce.get("shipping_methods/flat_rate").parsed_response ``` ```json { "id": "flat_rate", "title": "Flat rate", "description": "Lets you charge a fixed rate for shipping.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping_methods/flat_rate" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping_methods" } ] } } ``` ## List all shipping methods This API helps you to view all the shipping methods. ```http GET /wp-json/wc/v3/shipping_methods ``` ```shell curl https://example.com/wp-json/wc/v3/shipping_methods \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'shipping_methods' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('shipping_methods')); ?> ``` ```python print(wcapi.get("shipping_methods").json()) ``` ```ruby woocommerce.get("shipping_methods").parsed_response ``` ```json [ { "id": "flat_rate", "title": "Flat rate", "description": "Lets you charge a fixed rate for shipping.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping_methods/flat_rate" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping_methods" } ] } }, { "id": "free_shipping", "title": "Free shipping", "description": "Free shipping is a special method which can be triggered with coupons and minimum spends.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping_methods/free_shipping" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping_methods" } ] } }, { "id": "local_pickup", "title": "Local pickup", "description": "Allow customers to pick up orders themselves. By default, when using local pickup store base taxes will apply regardless of customer address.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping_methods/local_pickup" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping_methods" } ] } } ] ``` --- ## Shipping zone locations *Source: apis/rest-api/v3/shipping-zone-locations.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Shipping zone locations The shipping zone locations API allows you to view and batch update locations of a shipping zone. ## Shipping location properties | Attribute | Type | Description | | --------- | ------ | ----------------------------------------------------------------------------------------------------------- | | `code` | string | Shipping zone location code. | | `type` | string | Shipping zone location type. Options: `postcode`, `state`, `country` and `continent`. Default is `country`. | ## List all locations of a shipping zone This API helps you to view all the locations of a shipping zone. ```http GET /wp-json/wc/v3/shipping/zones//locations ``` ```shell curl https://example.com/wp-json/wc/v3/shipping/zones/5/locations \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'shipping/zones/5/locations' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('shipping/zones/5/locations')); ?> ``` ```python print(wcapi.get("shipping/zones/5/locations").json()) ``` ```ruby woocommerce.get("shipping/zones/5/locations").parsed_response ``` ```json [ { "code": "BR", "type": "country", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ] } } ] ``` ## Update a locations of a shipping zone This API lets you make changes to locations of a shipping zone. ```http PUT /wp-json/wc/v3/shipping/zones//locations ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/shipping/zones/5/locations \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '[ { "code": "BR:SP", "type": "state" }, { "code": "BR:RJ", "type": "state" } ]' ``` ```javascript var data = [ { code: 'BR:SP', type: 'state', }, { code: 'BR:RJ', type: 'state', }, ]; WooCommerce.put( 'shipping/zones/5/locations', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'BR:SP', 'type' => 'state' ], [ 'code' => 'BR:RJ', 'type' => 'state' ] ]; print_r($woocommerce->put('shipping/zones/5/locations', $data)); ?> ``` ```python data = [ { "code": "BR:SP", "type": "state" }, { "code": "BR:RJ", "type": "state" } ] print(wcapi.put("shipping/zones/5/locations", data).json()) ``` ```ruby data = [ { code: "BR:SP", type: "state" }, { code: "BR:RJ", type: "state" } ] woocommerce.put("shipping/zones/5/locations", data).parsed_response ``` ```json [ { "code": "BR:SP", "type": "state", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ] } }, { "code": "BR:RJ", "type": "state", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ] } } ] ``` --- ## Shipping zone methods *Source: apis/rest-api/v3/shipping-zone-methods.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Shipping zone methods The shipping zone methods API allows you to create, view, update, and delete individual methods of a shipping zone. ## Shipping method properties | Attribute | Type | Description | | -------------------- | ------- | ----------------------------------------------------------------------------------------------------------- | | `instance_id` | integer | Shipping method instance ID. `READ-ONLY` | | `title` | string | Shipping method customer facing title. `READ-ONLY` | | `order` | integer | Shipping method sort order. | | `enabled` | boolean | Shipping method enabled status. | | `method_id` | string | Shipping method ID. `READ-ONLY` `MANDATORY` | | `method_title` | string | Shipping method title. `READ-ONLY` | | `method_description` | string | Shipping method description. `READ-ONLY` | | `settings` | object | Shipping method settings. See [Shipping method - Settings properties](#shipping-method---settings-properties) | ### Shipping method - Settings properties | Attribute | Type | Description | | ------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | string | A unique identifier for the setting. `READ-ONLY` | | `label` | string | A human readable label for the setting used in interfaces. `READ-ONLY` | | `description` | string | A human readable description for the setting used in interfaces. `READ-ONLY` | | `type` | string | Type of setting. Options: `text`, `email`, `number`, `color`, `password`, `textarea`, `select`, `multiselect`, `radio`, `image_width` and `checkbox`. `READ-ONLY` | | `value` | string | Setting value. | | `default` | string | Default value for the setting. `READ-ONLY` | | `tip` | string | Additional help text shown to the user about the setting. `READ-ONLY` | | `placeholder` | string | Placeholder text to be displayed in text inputs. `READ-ONLY` | ## Include a shipping method to a shipping zone This API helps you to create a new shipping method to a shipping zone. ```http POST /wp-json/wc/v3/shipping/zones//methods ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/shipping/zones/5/methods \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "method_id": "flat_rate" }' ``` ```javascript const data = { method_id: 'flat_rate', }; WooCommerce.post( 'shipping/zones/5/methods', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'flat_rate' ]; print_r($woocommerce->post('shipping/zones/5/methods', $data)); ?> ``` ```python data = { "method_id": "flat_rate" } print(wcapi.post("shipping/zones/5/methods", data).json()) ``` ```ruby data = { method_id: "flat_rate" } woocommerce.post("shipping/zones/5/methods", data).parsed_response ``` ```json { "instance_id": 26, "title": "Flat rate", "order": 1, "enabled": true, "method_id": "flat_rate", "method_title": "Flat rate", "method_description": "

Lets you charge a fixed rate for shipping.

\n", "settings": { "title": { "id": "title", "label": "Method title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Flat rate", "default": "Flat rate", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "tax_status": { "id": "tax_status", "label": "Tax status", "description": "", "type": "select", "value": "taxable", "default": "taxable", "tip": "", "placeholder": "", "options": { "taxable": "Taxable", "none": "None" } }, "cost": { "id": "cost", "label": "Cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "0", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "" }, "class_costs": { "id": "class_costs", "label": "Shipping class costs", "description": "These costs can optionally be added based on the product shipping class.", "type": "title", "value": "", "default": "", "tip": "These costs can optionally be added based on the product shipping class.", "placeholder": "" }, "class_cost_92": { "id": "class_cost_92", "label": "\"Express\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "class_cost_91": { "id": "class_cost_91", "label": "\"Priority\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "no_class_cost": { "id": "no_class_cost", "label": "No shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "type": { "id": "type", "label": "Calculation type", "description": "", "type": "select", "value": "class", "default": "class", "tip": "", "placeholder": "", "options": { "class": "Per class: Charge shipping for each shipping class individually", "order": "Per order: Charge shipping for the most expensive shipping class" } } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ] } } ```
## Retrieve a shipping method from a shipping zone This API lets you retrieve and view a specific shipping method from a shipping zone by ID. ```http GET /wp-json/wc/v3/shipping/zones//methods/ ``` ```shell curl https://example.com/wp-json/wc/v3/shipping/zones/5/methods/26 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'shipping/zones/5/methods/26' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('shipping/zones/5/methods/26')); ?> ``` ```python print(wcapi.get("shipping/zones/5/methods/26").json()) ``` ```ruby woocommerce.get("shipping/zones/5/methods/26").parsed_response ``` ```json { "instance_id": 26, "title": "Flat rate", "order": 1, "enabled": true, "method_id": "flat_rate", "method_title": "Flat rate", "method_description": "

Lets you charge a fixed rate for shipping.

\n", "settings": { "title": { "id": "title", "label": "Method title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Flat rate", "default": "Flat rate", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "tax_status": { "id": "tax_status", "label": "Tax status", "description": "", "type": "select", "value": "taxable", "default": "taxable", "tip": "", "placeholder": "", "options": { "taxable": "Taxable", "none": "None" } }, "cost": { "id": "cost", "label": "Cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "0", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "" }, "class_costs": { "id": "class_costs", "label": "Shipping class costs", "description": "These costs can optionally be added based on the product shipping class.", "type": "title", "value": "", "default": "", "tip": "These costs can optionally be added based on the product shipping class.", "placeholder": "" }, "class_cost_92": { "id": "class_cost_92", "label": "\"Express\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "class_cost_91": { "id": "class_cost_91", "label": "\"Priority\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "no_class_cost": { "id": "no_class_cost", "label": "No shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "type": { "id": "type", "label": "Calculation type", "description": "", "type": "select", "value": "class", "default": "class", "tip": "", "placeholder": "", "options": { "class": "Per class: Charge shipping for each shipping class individually", "order": "Per order: Charge shipping for the most expensive shipping class" } } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ] } } ```
## List all shipping methods from a shipping zone This API helps you to view all the shipping methods from a shipping zone. ```http GET /wp-json/wc/v3/shipping/zones//methods ``` ```shell curl https://example.com/wp-json/wc/v3/shipping/zones/5/methods \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'shipping/zones/5/methods' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('shipping/zones/5/methods')); ?> ``` ```python print(wcapi.get("shipping/zones/5/methods").json()) ``` ```ruby woocommerce.get("shipping/zones/5/methods").parsed_response ``` ```json [ { "instance_id": 26, "title": "Flat rate", "order": 1, "enabled": true, "method_id": "flat_rate", "method_title": "Flat rate", "method_description": "

Lets you charge a fixed rate for shipping.

\n", "settings": { "title": { "id": "title", "label": "Method title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Flat rate", "default": "Flat rate", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "tax_status": { "id": "tax_status", "label": "Tax status", "description": "", "type": "select", "value": "taxable", "default": "taxable", "tip": "", "placeholder": "", "options": { "taxable": "Taxable", "none": "None" } }, "cost": { "id": "cost", "label": "Cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "0", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "" }, "class_costs": { "id": "class_costs", "label": "Shipping class costs", "description": "These costs can optionally be added based on the product shipping class.", "type": "title", "value": "", "default": "", "tip": "These costs can optionally be added based on the product shipping class.", "placeholder": "" }, "class_cost_92": { "id": "class_cost_92", "label": "\"Express\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "class_cost_91": { "id": "class_cost_91", "label": "\"Priority\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "no_class_cost": { "id": "no_class_cost", "label": "No shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "type": { "id": "type", "label": "Calculation type", "description": "", "type": "select", "value": "class", "default": "class", "tip": "", "placeholder": "", "options": { "class": "Per class: Charge shipping for each shipping class individually", "order": "Per order: Charge shipping for the most expensive shipping class" } } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ] } }, { "instance_id": 27, "title": "Free shipping", "order": 2, "enabled": true, "method_id": "free_shipping", "method_title": "Free shipping", "method_description": "

Free shipping is a special method which can be triggered with coupons and minimum spends.

\n", "settings": { "title": { "id": "title", "label": "Title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Free shipping", "default": "Free shipping", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "requires": { "id": "requires", "label": "Free shipping requires...", "description": "", "type": "select", "value": "", "default": "", "tip": "", "placeholder": "", "options": { "": "N/A", "coupon": "A valid free shipping coupon", "min_amount": "A minimum order amount", "either": "A minimum order amount OR a coupon", "both": "A minimum order amount AND a coupon" } }, "min_amount": { "id": "min_amount", "label": "Minimum order amount", "description": "Users will need to spend this amount to get free shipping (if enabled above).", "type": "price", "value": "0", "default": "", "tip": "Users will need to spend this amount to get free shipping (if enabled above).", "placeholder": "" } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods/27" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ] } } ] ```
## Update a shipping method of a shipping zone This API lets you make changes to a shipping method of a shipping zone. ```http PUT /wp-json/wc/v3/shipping/zones//methods/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/shipping/zones/5/methods/26 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "settings": { "cost": "20.00" } }' ``` ```javascript const data = { settings: { cost: '20.00', }, }; WooCommerce.put( 'shipping/zones/5/methods/26', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ 'cost' => '20.00' ] ]; print_r($woocommerce->put('shipping/zones/5/methods/26', $data)); ?> ``` ```python data = { "settings": { "cost": "20.00" } } print(wcapi.put("shipping/zones/5/methods/26", data).json()) ``` ```ruby data = { settings: { "cost": "20.00" } } woocommerce.put("shipping/zones/5/methods/26", data).parsed_response ``` ```json { "instance_id": 26, "title": "Flat rate", "order": 1, "enabled": true, "method_id": "flat_rate", "method_title": "Flat rate", "method_description": "

Lets you charge a fixed rate for shipping.

\n", "settings": { "title": { "id": "title", "label": "Method title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Flat rate", "default": "Flat rate", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "tax_status": { "id": "tax_status", "label": "Tax status", "description": "", "type": "select", "value": "taxable", "default": "taxable", "tip": "", "placeholder": "", "options": { "taxable": "Taxable", "none": "None" } }, "cost": { "id": "cost", "label": "Cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "20.00", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "" }, "class_costs": { "id": "class_costs", "label": "Shipping class costs", "description": "These costs can optionally be added based on the product shipping class.", "type": "title", "value": "", "default": "", "tip": "These costs can optionally be added based on the product shipping class.", "placeholder": "" }, "class_cost_92": { "id": "class_cost_92", "label": "\"Express\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "class_cost_91": { "id": "class_cost_91", "label": "\"Priority\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "no_class_cost": { "id": "no_class_cost", "label": "No shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "type": { "id": "type", "label": "Calculation type", "description": "", "type": "select", "value": "class", "default": "class", "tip": "", "placeholder": "", "options": { "class": "Per class: Charge shipping for each shipping class individually", "order": "Per order: Charge shipping for the most expensive shipping class" } } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ] } } ```
## Delete a shipping method from a shipping zone This API helps you delete a shipping method from a shipping zone. ```http DELETE /wp-json/wc/v3/shipping/zones//methods/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/shipping/zones/5/methods/26?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'shipping/zones/5/methods/26', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('shipping/zones/5/methods/26', ['force' => true])); ?> ``` ```python print(wcapi.delete("shipping/zones/5/methods/26", params={"force": True}).json()) ``` ```ruby woocommerce.delete("shipping/zones/5/methods/26", force: true).parsed_response ``` ```json { "instance_id": 26, "title": "Flat rate", "order": 1, "enabled": true, "method_id": "flat_rate", "method_title": "Flat rate", "method_description": "

Lets you charge a fixed rate for shipping.

\n", "settings": { "title": { "id": "title", "label": "Method title", "description": "This controls the title which the user sees during checkout.", "type": "text", "value": "Flat rate", "default": "Flat rate", "tip": "This controls the title which the user sees during checkout.", "placeholder": "" }, "tax_status": { "id": "tax_status", "label": "Tax status", "description": "", "type": "select", "value": "taxable", "default": "taxable", "tip": "", "placeholder": "", "options": { "taxable": "Taxable", "none": "None" } }, "cost": { "id": "cost", "label": "Cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "20.00", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "" }, "class_costs": { "id": "class_costs", "label": "Shipping class costs", "description": "These costs can optionally be added based on the product shipping class.", "type": "title", "value": "", "default": "", "tip": "These costs can optionally be added based on the product shipping class.", "placeholder": "" }, "class_cost_92": { "id": "class_cost_92", "label": "\"Express\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "class_cost_91": { "id": "class_cost_91", "label": "\"Priority\" shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "no_class_cost": { "id": "no_class_cost", "label": "No shipping class cost", "description": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "type": "text", "value": "", "default": "", "tip": "Enter a cost (excl. tax) or sum, e.g. 10.00 * [qty].

Use [qty] for the number of items,
[cost] for the total cost of items, and [fee percent=\"10\" min_fee=\"20\" max_fee=\"\"] for percentage based fees.", "placeholder": "N/A" }, "type": { "id": "type", "label": "Calculation type", "description": "", "type": "select", "value": "class", "default": "class", "tip": "", "placeholder": "", "options": { "class": "Per class: Charge shipping for each shipping class individually", "order": "Per order: Charge shipping for the most expensive shipping class" } } }, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods/26" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/methods" } ], "describes": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ] } } ```
#### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | --- ## Shipping zones *Source: apis/rest-api/v3/shipping-zones.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Shipping zones The shipping zones API allows you to create, view, update, and delete individual shipping zones. ## Shipping zone properties | Attribute | Type | Description | | --------- | ------- | ----------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Shipping zone name. `MANDATORY` | | `order` | integer | Shipping zone order. | ## Create a shipping zone This API helps you to create a new shipping zone. ```http POST /wp-json/wc/v3/shipping/zones ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/shipping/zones \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Brazil" }' ``` ```javascript const data = { name: 'Brazil', }; WooCommerce.post( 'shipping/zones', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'Brazil' ]; print_r($woocommerce->post('shipping/zones', $data)); ?> ``` ```python data = { "name": "Brazil" } print(wcapi.post("shipping/zones", data).json()) ``` ```ruby data = { name: "Brazil" } woocommerce.post("shipping/zones", data).parsed_response ``` ```json { "id": 5, "name": "Brazil", "order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations" } ] } } ``` ## Retrieve a shipping zone This API lets you retrieve and view a specific shipping zone by ID. ```http GET /wp-json/wc/v3/shipping/zones/ ``` ```shell curl https://example.com/wp-json/wc/v3/shipping/zones/5 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'shipping/zones/5' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('shipping/zones/5')); ?> ``` ```python print(wcapi.get("shipping/zones/5").json()) ``` ```ruby woocommerce.get("shipping/zones/5").parsed_response ``` ```json { "id": 5, "name": "Brazil", "order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations" } ] } } ``` ## List all shipping zones This API helps you to view all the shipping zones. ```http GET /wp-json/wc/v3/shipping/zones ``` ```shell curl https://example.com/wp-json/wc/v3/shipping/zones \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'shipping/zones' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('shipping/zones')); ?> ``` ```python print(wcapi.get("shipping/zones").json()) ``` ```ruby woocommerce.get("shipping/zones").parsed_response ``` ```json [ { "id": 0, "name": "Rest of the World", "order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/0" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/0/locations" } ] } }, { "id": 5, "name": "Brazil", "order": 0, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations" } ] } } ] ``` ## Update a shipping zone This API lets you make changes to a shipping zone. ```http PUT /wp-json/wc/v3/shipping/zones/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/shipping/zones/5 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "order": 1 }' ``` ```javascript const data = { order: 1, }; WooCommerce.put( 'shipping/zones/5', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 1 ]; print_r($woocommerce->put('shipping/zones/5', $data)); ?> ``` ```python data = { "order": 1 } print(wcapi.put("shipping/zones/5", data).json()) ``` ```ruby data = { order: 1 } woocommerce.put("shipping/zones/5", data).parsed_response ``` ```json { "id": 5, "name": "Brazil", "order": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations" } ] } } ``` ## Delete a shipping zone This API helps you delete a shipping zone. ```http DELETE /wp-json/wc/v3/shipping/zones/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/shipping/zones/5?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'shipping/zones/5', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('shipping/zones/5', ['force' => true])); ?> ``` ```python print(wcapi.delete("shipping/zones/5", params={"force": True}).json()) ``` ```ruby woocommerce.delete("shipping/zones/5", force: true).parsed_response ``` ```json { "id": 5, "name": "Brazil", "order": 1, "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones" } ], "describedby": [ { "href": "https://example.com/wp-json/wc/v3/shipping/zones/5/locations" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | --- ## System status tools *Source: apis/rest-api/v3/system-status-tools.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # System status tools The system status tools API allows you to view and run tools from system status. ## System status tool properties | Attribute | Type | Description | | ------------- | ------- | ------------------------------------------------------------------------------------------------------------------- | | `id` | string | A unique identifier for the tool. `READ-ONLY` | | `name` | string | Tool name. `READ-ONLY` | | `action` | string | What running the tool will do. `READ-ONLY` | | `description` | string | Tool description. `READ-ONLY` | | `success` | boolean | Did the tool run successfully? `READ-ONLY` `WRITE-ONLY` | | `message` | string | Tool return message. `READ-ONLY` `WRITE-ONLY` | | `confirm` | boolean | Confirm execution of the tool. Default is `false`. `WRITE-ONLY` | ## Retrieve a tool from system status This API lets you retrieve and view a specific tool from system status by ID. ```http GET /wp-json/wc/v3/system_status/tools/ ``` ```shell curl https://example.com/wp-json/wc/v3/system_status/tools/clear_transients \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'system_status/tools/clear_transients' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('system_status/tools/clear_transients')); ?> ``` ```python print(wcapi.get("system_status/tools/clear_transients").json()) ``` ```ruby woocommerce.get("system_status/tools/clear_transients").parsed_response ``` ```json { "id": "clear_transients", "name": "WC transients", "action": "Clear transients", "description": "This tool will clear the product/shop transients cache.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/clear_transients" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } } ``` ## List all tools from system status This API helps you to view all tools from system status. ```http GET /wp-json/wc/v3/system_status/tools ``` ```shell curl https://example.com/wp-json/wc/v3/system_status/tools \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'system_status/tools' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('system_status/tools')); ?> ``` ```python print(wcapi.get("system_status/tools").json()) ``` ```ruby woocommerce.get("system_status/tools").parsed_response ``` ```json [ { "id": "clear_transients", "name": "WC transients", "action": "Clear transients", "description": "This tool will clear the product/shop transients cache.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/clear_transients" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "clear_expired_transients", "name": "Expired transients", "action": "Clear expired transients", "description": "This tool will clear ALL expired transients from WordPress.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/clear_expired_transients" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "delete_orphaned_variations", "name": "Orphaned variations", "action": "Delete orphaned variations", "description": "This tool will delete all variations which have no parent.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/delete_orphaned_variations" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "clear_expired_download_permissions", "name": "Used-up download permissions", "action": "Clean up download permissions", "description": "This tool will delete expired download permissions and permissions with 0 remaining downloads.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/clear_expired_download_permissions" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "regenerate_product_lookup_tables", "name": "Product lookup tables", "action": "Regenerate", "description": "This tool will regenerate product lookup table data. This process may take a while.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/regenerate_product_lookup_tables" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "repair_coupons_lookup_table", "name": "Coupons lookup table", "action": "Repair", "description": "This tool will repair the coupons lookup table data with missing discount amounts. This process may take a while.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/repair_coupons_lookup_table" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "recount_terms", "name": "Term counts", "action": "Recount terms", "description": "This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/recount_terms" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "reset_roles", "name": "Capabilities", "action": "Reset capabilities", "description": "This tool will reset the admin, customer and shop_manager roles to default. Use this if your users cannot access all of the WooCommerce admin pages.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/reset_roles" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "clear_sessions", "name": "Customer sessions", "action": "Clear all sessions", "description": "Note: This tool will delete all customer session data from the database, including any current live carts.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/clear_sessions" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "clear_template_cache", "name": "Clear template cache", "action": "Clear", "description": "Note: This tool will empty the template cache.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/clear_template_cache" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "clear_system_status_theme_info_cache", "name": "Clear system status theme info cache", "action": "Clear", "description": "Note: This tool will empty the system status theme info cache.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/clear_system_status_theme_info_cache" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "install_pages", "name": "Install WooCommerce pages", "action": "Install pages", "description": "Note: This tool will install all the missing WooCommerce pages. Pages already defined and set up will not be replaced.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/install_pages" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "delete_taxes", "name": "Delete all WooCommerce tax rates", "action": "Delete ALL tax rates", "description": "Note: This option will delete ALL of your tax rates, use with caution.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/delete_taxes" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "regenerate_thumbnails", "name": "Regenerate shop thumbnails", "action": "Regenerate", "description": "This will regenerate all shop thumbnails to match your theme and/or image settings.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/regenerate_thumbnails" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "db_update_routine", "name": "Update database", "action": "Update database", "description": "Note: This tool will update your WooCommerce database to the latest version. Please ensure you make sufficient backups before proceeding.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/db_update_routine" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "recreate_order_address_fts_index", "name": "Re-create Order Address FTS index", "action": "Recreate index", "description": "This tool will recreate the full text search index for order addresses. If the index does not exist, it will try to create it.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/recreate_order_address_fts_index" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } }, { "id": "verify_db_tables", "name": "Verify base database tables", "action": "Verify database", "description": "Verify if all base database tables are present.", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/verify_db_tables" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } } ] ``` ## Run a tool from system status This API lets you run a tool from system status. ```http PUT /wp-json/wc/v3/system_status/tools/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/system_status/tools/clear_transients \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "confirm": true }' ``` ```javascript const data = { confirm: true, }; WooCommerce.put( 'system_status/tools/clear_transients', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php true ]; print_r($woocommerce->put('system_status/tools/clear_transients', $data)); ?> ``` ```python data = { "confirm": True } print(wcapi.put("system_status/tools/clear_transients", data).json()) ``` ```ruby data = { confirm: true } woocommerce.put("system_status/tools/clear_transients", data).parsed_response ``` ```json { "id": "clear_transients", "name": "WC transients", "action": "Clear transients", "description": "This tool will clear the product/shop transients cache.", "success": true, "message": "Product transients cleared", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools/clear_transients" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/system_status/tools" } ] } } ``` --- ## System status *Source: apis/rest-api/v3/system-status.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # System status The system status API allows you to view all system status items. ## System status properties | Attribute | Type | Description | | ---------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------ | | `environment` | object | Environment. See [System status - Environment properties](#system-status---environment-properties) `READ-ONLY` | | `database` | object | Database. See [System status - Database properties](#system-status---database-properties) `READ-ONLY` | | `active_plugins` | array | Active plugins. `READ-ONLY` | | `theme` | object | Theme. See [System status - Theme properties](#system-status---theme-properties) `READ-ONLY` | | `settings` | object | Settings. See [System status - Settings properties](#system-status---settings-properties) `READ-ONLY` | | `security` | object | Security. See [System status - Security properties](#system-status---security-properties) `READ-ONLY` | | `pages` | array | WooCommerce pages. `READ-ONLY` | ### System status - Environment properties | Attribute | Type | Description | | --------------------------- | ------- | -------------------------------------------------------------------------- | | `home_url` | string | Home URL. `READ-ONLY` | | `site_url` | string | Site URL. `READ-ONLY` | | `version` | string | WooCommerce version. `READ-ONLY` | | `log_directory` | string | Log directory. `READ-ONLY` | | `log_directory_writable` | boolean | Is log directory writable? `READ-ONLY` | | `wp_version` | string | WordPress version. `READ-ONLY` | | `wp_multisite` | boolean | Is WordPress multisite? `READ-ONLY` | | `wp_memory_limit` | integer | WordPress memory limit. `READ-ONLY` | | `wp_debug_mode` | boolean | Is WordPress debug mode active? `READ-ONLY` | | `wp_cron` | boolean | Are WordPress cron jobs enabled? `READ-ONLY` | | `wp_environment_type` | string | WordPress environment type. `READ-ONLY` | | `language` | string | WordPress language. `READ-ONLY` | | `server_info` | string | Server info. `READ-ONLY` | | `php_version` | string | PHP version. `READ-ONLY` | | `php_post_max_size` | integer | PHP post max size. `READ-ONLY` | | `php_max_execution_time` | integer | PHP max execution time. `READ-ONLY` | | `php_max_input_vars` | integer | PHP max input vars. `READ-ONLY` | | `curl_version` | string | cURL version. `READ-ONLY` | | `suhosin_installed` | boolean | Is SUHOSIN installed? `READ-ONLY` | | `max_upload_size` | integer | Max upload size. `READ-ONLY` | | `mysql_version` | string | MySQL version. `READ-ONLY` | | `default_timezone` | string | Default timezone. `READ-ONLY` | | `fsockopen_or_curl_enabled` | boolean | Is fsockopen/cURL enabled? `READ-ONLY` | | `soapclient_enabled` | boolean | Is SoapClient class enabled? `READ-ONLY` | | `domdocument_enabled` | boolean | Is DomDocument class enabled? `READ-ONLY` | | `gzip_enabled` | boolean | Is GZip enabled? `READ-ONLY` | | `mbstring_enabled` | boolean | Is mbstring enabled? `READ-ONLY` | | `remote_post_successful` | boolean | Remote POST successful? `READ-ONLY` | | `remote_post_response` | string | Remote POST response. `READ-ONLY` | | `remote_get_successful` | boolean | Remote GET successful? `READ-ONLY` | | `remote_get_response` | string | Remote GET response. `READ-ONLY` | ### System status - Database properties | Attribute | Type | Description | | ------------------------ | ------ | ----------------------------------------------------------------- | | `wc_database_version` | string | WC database version. `READ-ONLY` | | `database_prefix` | string | Database prefix. `READ-ONLY` | | `maxmind_geoip_database` | string | MaxMind GeoIP database. `READ-ONLY` | | `database_tables` | array | Database tables. `READ-ONLY` | ### System status - Theme properties | Attribute | Type | Description | | ------------------------- | ------- | ------------------------------------------------------------------------------------- | | `name` | string | Theme name. `READ-ONLY` | | `version` | string | Theme version. `READ-ONLY` | | `version_latest` | string | Latest version of theme. `READ-ONLY` | | `author_url` | string | Theme author URL. `READ-ONLY` | | `is_child_theme` | boolean | Is this theme a child theme? `READ-ONLY` | | `has_woocommerce_support` | boolean | Does the theme declare WooCommerce support? `READ-ONLY` | | `has_woocommerce_file` | boolean | Does the theme have a woocommerce.php file? `READ-ONLY` | | `has_outdated_templates` | boolean | Does this theme have outdated templates? `READ-ONLY` | | `overrides` | array | Template overrides. `READ-ONLY` | | `parent_name` | string | Parent theme name. `READ-ONLY` | | `parent_version` | string | Parent theme version. `READ-ONLY` | | `parent_author_url` | string | Parent theme author URL. `READ-ONLY` | ### System status - Settings properties | Attribute | Type | Description | | --------------------- | ------- | ------------------------------------------------------------------------------------ | | `api_enabled` | boolean | REST API enabled? `READ-ONLY` | | `force_ssl` | boolean | SSL forced? `READ-ONLY` | | `currency` | string | Currency. `READ-ONLY` | | `currency_symbol` | string | Currency symbol. `READ-ONLY` | | `currency_position` | string | Currency position. `READ-ONLY` | | `thousand_separator` | string | Thousand separator. `READ-ONLY` | | `decimal_separator` | string | Decimal separator. `READ-ONLY` | | `number_of_decimals` | integer | Number of decimals. `READ-ONLY` | | `geolocation_enabled` | boolean | Geolocation enabled? `READ-ONLY` | | `taxonomies` | array | Taxonomy terms for product/order statuses. `READ-ONLY` | ### System status - Security properties | Attribute | Type | Description | | ------------------- | ------- | --------------------------------------------------------------------------------- | | `secure_connection` | boolean | Is the connection to your store secure? `READ-ONLY` | | `hide_errors` | boolean | Hide errors from visitors? `READ-ONLY` | ## List all system status items This API helps you to view all the system status items. ```http GET /wp-json/wc/v3/system_status ``` ```shell curl https://example.com/wp-json/wc/v3/system_status \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'system_status' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('system_status')); ?> ``` ```python print(wcapi.get("system_status").json()) ``` ```ruby woocommerce.get("system_status").parsed_response ``` ```json { "environment": { "home_url": "http://example.com", "site_url": "http://example.com", "version": "3.0.0", "log_directory": "/var/www/woocommerce/wp-content/uploads/wc-logs/", "log_directory_writable": true, "wp_version": "4.7.3", "wp_multisite": false, "wp_memory_limit": 134217728, "wp_debug_mode": true, "wp_cron": true, "wp_environment_type": "production", "language": "en_US", "server_info": "Apache/2.4.18 (Ubuntu)", "php_version": "7.1.3-2+deb.sury.org~yakkety+1", "php_post_max_size": 8388608, "php_max_execution_time": 30, "php_max_input_vars": 1000, "curl_version": "7.50.1, OpenSSL/1.0.2g", "suhosin_installed": false, "max_upload_size": 2097152, "mysql_version": "5.7.17", "default_timezone": "UTC", "fsockopen_or_curl_enabled": true, "soapclient_enabled": true, "domdocument_enabled": true, "gzip_enabled": true, "mbstring_enabled": true, "remote_post_successful": true, "remote_post_response": "200", "remote_get_successful": true, "remote_get_response": "200" }, "database": { "wc_database_version": "3.0.0", "database_prefix": "wp_", "maxmind_geoip_database": "/var/www/woocommerce/wp-content/uploads/GeoIP.dat", "database_tables": { "woocommerce_sessions": true, "woocommerce_api_keys": true, "woocommerce_attribute_taxonomies": true, "woocommerce_downloadable_product_permissions": true, "woocommerce_order_items": true, "woocommerce_order_itemmeta": true, "woocommerce_tax_rates": true, "woocommerce_tax_rate_locations": true, "woocommerce_shipping_zones": true, "woocommerce_shipping_zone_locations": true, "woocommerce_shipping_zone_methods": true, "woocommerce_payment_tokens": true, "woocommerce_payment_tokenmeta": true } }, "active_plugins": [ { "plugin": "woocommerce/woocommerce.php", "name": "WooCommerce", "version": "3.0.0-rc.1", "version_latest": "2.6.14", "url": "https://woocommerce.com/", "author_name": "Automattic", "author_url": "https://woocommerce.com", "network_activated": false } ], "theme": { "name": "Twenty Sixteen", "version": "1.3", "version_latest": "1.3", "author_url": "https://wordpress.org/", "is_child_theme": false, "has_woocommerce_support": true, "has_woocommerce_file": false, "has_outdated_templates": false, "overrides": [], "parent_name": "", "parent_version": "", "parent_version_latest": "", "parent_author_url": "" }, "settings": { "api_enabled": true, "force_ssl": false, "currency": "USD", "currency_symbol": "$", "currency_position": "left", "thousand_separator": ",", "decimal_separator": ".", "number_of_decimals": 2, "geolocation_enabled": false, "taxonomies": { "external": "external", "grouped": "grouped", "simple": "simple", "variable": "variable" } }, "security": { "secure_connection": true, "hide_errors": true }, "pages": [ { "page_name": "Shop base", "page_id": "4", "page_set": true, "page_exists": true, "page_visible": true, "shortcode": "", "shortcode_required": false, "shortcode_present": false }, { "page_name": "Cart", "page_id": "5", "page_set": true, "page_exists": true, "page_visible": true, "shortcode": "[woocommerce_cart]", "shortcode_required": true, "shortcode_present": true }, { "page_name": "Checkout", "page_id": "6", "page_set": true, "page_exists": true, "page_visible": true, "shortcode": "[woocommerce_checkout]", "shortcode_required": true, "shortcode_present": true }, { "page_name": "My account", "page_id": "7", "page_set": true, "page_exists": true, "page_visible": true, "shortcode": "[woocommerce_my_account]", "shortcode_required": true, "shortcode_present": true } ] } ``` --- ## Tax classes *Source: apis/rest-api/v3/tax-classes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Tax classes The tax classes API allows you to create, view, and delete individual tax classes. ## Tax class properties | Attribute | Type | Description | | --------- | ------ | ----------------------------------------------------------------------------- | | `slug` | string | Unique identifier for the resource. `READ-ONLY` | | `name` | string | Tax class name. `REQUIRED` | ## Create a tax class This API helps you to create a new tax class. ```http POST /wp-json/wc/v3/taxes/classes ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/taxes/classes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Zero Rate" }' ``` ```javascript const data = { name: 'Zero Rate', }; WooCommerce.post( 'taxes/classes', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'Zero Rate' ]; print_r($woocommerce->post('taxes/classes', $data)); ?> ``` ```python data = { "name": "Zero Rate" } print(wcapi.post("taxes/classes", data).json()) ``` ```ruby data = { name: "Zero Rate" } woocommerce.post("taxes/classes", data).parsed_response ``` ```json { "slug": "zero-rate", "name": "Zero Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes/classes" } ] } } ``` ## List all tax classes This API helps you to view all tax classes. ```http GET /wp-json/wc/v3/taxes/classes ``` ```shell curl https://example.com/wp-json/wc/v3/taxes/classes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'taxes/classes' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('taxes/classes')); ?> ``` ```python print(wcapi.get("taxes/classes").json()) ``` ```ruby woocommerce.get("taxes/classes").parsed_response ``` ```json [ { "slug": "standard", "name": "Standard Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes/classes" } ] } }, { "slug": "reduced-rate", "name": "Reduced Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes/classes" } ] } }, { "slug": "zero-rate", "name": "Zero Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes/classes" } ] } } ] ``` ## Delete a tax class This API helps you delete a tax class. :::warning This also will delete all tax rates from the selected class. ::: ```http DELETE /wp-json/wc/v3/taxes/classes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/taxes/classes/zero-rate?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'taxes/classes/zero-rate', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('taxes/classes/zero-rate', ['force' => true])); ?> ``` ```python print(wcapi.delete("taxes/classes/zero-rate", params={"force": True}).json()) ``` ```ruby woocommerce.delete("taxes/classes/zero-rate", force: true).parsed_response ``` ```json { "slug": "zero-rate", "name": "Zero Rate", "_links": { "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes/classes" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | --------------------------------------------------------------------- | | `force` | string | Required to be `true`, since this resource does not support trashing. | --- ## Tax rates *Source: apis/rest-api/v3/taxes.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Tax rates The taxes API allows you to create, view, update, and delete individual tax rates, or a batch of tax rates. ## Tax rate properties | Attribute | Type | Description | | ----------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `country` | string | Country ISO 3166 code. See [ISO 3166 Codes (Countries)](http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html) for more details | | `state` | string | State code. | | `postcode` | string | Postcode/ZIP, it doesn't support multiple values. Deprecated as of WooCommerce 5.3, `postcodes` should be used instead. | | `city` | string | City name, it doesn't support multiple values. Deprecated as of WooCommerce 5.3, `postcodes` should be used instead. | | `postcodes` | string[] | Postcodes/ZIPs. Introduced in WooCommerce 5.3. | | `cities` | string[] | City names. Introduced in WooCommerce 5.3. | | `rate` | string | Tax rate. | | `name` | string | Tax rate name. | | `priority` | integer | Tax priority. Only 1 matching rate per priority will be used. To define multiple tax rates for a single area you need to specify a different priority per rate. Default is `1`. | | `compound` | boolean | Whether or not this is a compound tax rate. Compound rates are applied on top of other tax rates. Default is `false`. | | `shipping` | boolean | Whether or not this tax rate also gets applied to shipping. Default is `true`. | | `order` | integer | Indicates the order that will appear in queries. | | `class` | string | Tax class. Default is `standard`. | ## Create a tax rate This API helps you to create a new tax rate. ```http POST /wp-json/wc/v3/taxes ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/taxes \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "country": "US", "state": "AL", "cities": ["Alpine", "Brookside", "Cardiff"], "postcodes": ["35014", "35036", "35041"], "rate": "4", "name": "State Tax", "shipping": false }' ``` ```javascript const data = { country: 'US', state: 'AL', cities: [ 'Alpine', 'Brookside', 'Cardiff' ], postcodes: [ '35014', '35036', '35041' ], rate: '4', name: 'State Tax', shipping: false, }; WooCommerce.post( 'taxes', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'US', 'state' => 'AL', 'cities' => ['Alpine', 'Brookside', 'Cardiff'], 'postcodes' => ['35014', '35036', '35041'], 'rate' => '4', 'name' => 'State Tax', 'shipping' => false ]; print_r($woocommerce->post('taxes', $data)); ?> ``` ```python data = { "country": "US", "state": "AL", "cities": ["Alpine", "Brookside", "Cardiff"], "postcodes": ["35014", "35036", "35041"], "rate": "4", "name": "State Tax", "shipping": False } print(wcapi.post("taxes", data).json()) ``` ```ruby data = { country: "US", state: "AL", cities: ["Alpine", "Brookside", "Cardiff"], postcodes: ["35014", "35036", "35041"], rate: "4", name: "State Tax", shipping: false } woocommerce.post("taxes", data).parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "35041", "city": "Cardiff", "postcodes": [ "35014", "35036", "35041" ], "cities": [ "Alpine", "Brookside", "Cardiff" ], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } } ``` ## Retrieve a tax rate This API lets you retrieve and view a specific tax rate by ID. ```http GET /wp-json/wc/v3/taxes/ ``` ```shell curl https://example.com/wp-json/wc/v3/taxes/72 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'taxes/72' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('taxes/72')); ?> ``` ```python print(wcapi.get("taxes/72").json()) ``` ```ruby woocommerce.get("taxes/72").parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "35041", "city": "Cardiff", "postcodes": [ "35014", "35036", "35041" ], "cities": [ "Alpine", "Brookside", "Cardiff" ], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } } ``` ## List all tax rates This API helps you to view all the tax rates. ```http GET /wp-json/wc/v3/taxes ``` ```shell curl https://example.com/wp-json/wc/v3/taxes \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'taxes' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('taxes')); ?> ``` ```python print(wcapi.get("taxes").json()) ``` ```ruby woocommerce.get("taxes").parsed_response ``` ```json [ { "id": 72, "country": "US", "state": "AL", "postcode": "35041", "city": "Cardiff", "postcodes": [ "35014", "35036", "35041" ], "cities": [ "Alpine", "Brookside", "Cardiff" ], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 73, "country": "US", "state": "AZ", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.6000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 2, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/73" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 74, "country": "US", "state": "AR", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 3, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/74" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 75, "country": "US", "state": "CA", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "7.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 4, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/75" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 76, "country": "US", "state": "CO", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "2.9000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 5, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/76" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 77, "country": "US", "state": "CT", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.3500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 6, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/77" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 78, "country": "US", "state": "DC", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 7, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/78" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 79, "country": "US", "state": "FL", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 8, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/79" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 80, "country": "US", "state": "GA", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 9, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/80" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 81, "country": "US", "state": "GU", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 10, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/81" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | ---------- | ------- | --------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. | | `page` | integer | Current page of the collection. | | `per_page` | integer | Maximum number of items to be returned in result set. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Default is `asc`. Options: `asc` and `desc`. | | `orderby` | string | Sort collection by object attribute. Default is `order`. Options: `id`, `order` and `priority`. | | `class` | string | Retrieve only tax rates of this Tax class. | ## Update a tax rate This API lets you make changes to a tax rate. ```http PUT /wp-json/wc/v3/taxes/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/taxes/72 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "US Tax" }' ``` ```javascript const data = { name: 'US Tax', }; WooCommerce.put( 'taxes/72', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'US Tax' ]; print_r($woocommerce->put('taxes/72', $data)); ?> ``` ```python data = { "name": "US Tax" } print(wcapi.put("taxes/72", data).json()) ``` ```ruby data = { name: "US Tax" } woocommerce.put("taxes/72", data).parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "35041", "city": "Cardiff", "postcodes": [ "35014", "35036", "35041" ], "cities": [ "Alpine", "Brookside", "Cardiff" ], "rate": "4.0000", "name": "US Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } } ``` ## Delete a tax rate This API helps you delete a tax rate. ```http DELETE /wp-json/wc/v3/taxes/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/taxes/72?force=true \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'taxes/72', { force: true, } ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('taxes/72', ['force' => true])); ?> ``` ```python print(wcapi.delete("taxes/72", params={"force": True}).json()) ``` ```ruby woocommerce.delete("taxes/72", force: true).parsed_response ``` ```json { "id": 72, "country": "US", "state": "AL", "postcode": "35041", "city": "Cardiff", "postcodes": [ "35014", "35036", "35041" ], "cities": [ "Alpine", "Brookside", "Cardiff" ], "rate": "4.0000", "name": "US Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | ------------------------------------------------------------- | | `force` | string | Required to be `true`, as resource does not support trashing. | ## Batch update tax rates This API helps you to batch create, update and delete multiple tax rates. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/taxes/batch ``` > Example batch creating all US taxes: ```shell curl -X POST https://example.com/wp-json/wc/v3/taxes/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "country": "US", "state": "AL", "rate": "4.0000", "name": "State Tax", "shipping": false, "order": 1 }, { "country": "US", "state": "AZ", "rate": "5.6000", "name": "State Tax", "shipping": false, "order": 2 }, { "country": "US", "state": "AR", "rate": "6.5000", "name": "State Tax", "shipping": true, "order": 3 }, { "country": "US", "state": "CA", "rate": "7.5000", "name": "State Tax", "shipping": false, "order": 4 }, { "country": "US", "state": "CO", "rate": "2.9000", "name": "State Tax", "shipping": false, "order": 5 }, { "country": "US", "state": "CT", "rate": "6.3500", "name": "State Tax", "shipping": true, "order": 6 }, { "country": "US", "state": "DC", "rate": "5.7500", "name": "State Tax", "shipping": true, "order": 7 }, { "country": "US", "state": "FL", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 8 }, { "country": "US", "state": "GA", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 9 }, { "country": "US", "state": "GU", "rate": "4.0000", "name": "State Tax", "shipping": false, "order": 10 }, { "country": "US", "state": "HI", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 11 }, { "country": "US", "state": "ID", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 12 }, { "country": "US", "state": "IL", "rate": "6.2500", "name": "State Tax", "shipping": false, "order": 13 }, { "country": "US", "state": "IN", "rate": "7.0000", "name": "State Tax", "shipping": false, "order": 14 }, { "country": "US", "state": "IA", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 15 }, { "country": "US", "state": "KS", "rate": "6.1500", "name": "State Tax", "shipping": true, "order": 16 }, { "country": "US", "state": "KY", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 17 }, { "country": "US", "state": "LA", "rate": "4.0000", "name": "State Tax", "shipping": false, "order": 18 }, { "country": "US", "state": "ME", "rate": "5.5000", "name": "State Tax", "shipping": false, "order": 19 }, { "country": "US", "state": "MD", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 20 }, { "country": "US", "state": "MA", "rate": "6.2500", "name": "State Tax", "shipping": false, "order": 21 }, { "country": "US", "state": "MI", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 22 }, { "country": "US", "state": "MN", "rate": "6.8750", "name": "State Tax", "shipping": true, "order": 23 }, { "country": "US", "state": "MS", "rate": "7.0000", "name": "State Tax", "shipping": true, "order": 24 }, { "country": "US", "state": "MO", "rate": "4.2250", "name": "State Tax", "shipping": false, "order": 25 }, { "country": "US", "state": "NE", "rate": "5.5000", "name": "State Tax", "shipping": true, "order": 26 }, { "country": "US", "state": "NV", "rate": "6.8500", "name": "State Tax", "shipping": false, "order": 27 }, { "country": "US", "state": "NJ", "rate": "7.0000", "name": "State Tax", "shipping": true, "order": 28 }, { "country": "US", "state": "NM", "rate": "5.1250", "name": "State Tax", "shipping": true, "order": 29 }, { "country": "US", "state": "NY", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 30 }, { "country": "US", "state": "NC", "rate": "4.7500", "name": "State Tax", "shipping": true, "order": 31 }, { "country": "US", "state": "ND", "rate": "5.0000", "name": "State Tax", "shipping": true, "order": 32 }, { "country": "US", "state": "OH", "rate": "5.7500", "name": "State Tax", "shipping": true, "order": 33 }, { "country": "US", "state": "OK", "rate": "4.5000", "name": "State Tax", "shipping": false, "order": 34 }, { "country": "US", "state": "PA", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 35 }, { "country": "US", "state": "PR", "rate": "6.0000", "name": "State Tax", "shipping": false, "order": 36 }, { "country": "US", "state": "RI", "rate": "7.0000", "name": "State Tax", "shipping": false, "order": 37 }, { "country": "US", "state": "SC", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 38 }, { "country": "US", "state": "SD", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 39 }, { "country": "US", "state": "TN", "rate": "7.0000", "name": "State Tax", "shipping": true, "order": 40 }, { "country": "US", "state": "TX", "rate": "6.2500", "name": "State Tax", "shipping": true, "order": 41 }, { "country": "US", "state": "UT", "rate": "5.9500", "name": "State Tax", "shipping": false, "order": 42 }, { "country": "US", "state": "VT", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 43 }, { "country": "US", "state": "VA", "rate": "5.3000", "name": "State Tax", "shipping": false, "order": 44 }, { "country": "US", "state": "WA", "rate": "6.5000", "name": "State Tax", "shipping": true, "order": 45 }, { "country": "US", "state": "WV", "rate": "6.0000", "name": "State Tax", "shipping": true, "order": 46 }, { "country": "US", "state": "WI", "rate": "5.0000", "name": "State Tax", "shipping": true, "order": 47 }, { "country": "US", "state": "WY", "rate": "4.0000", "name": "State Tax", "shipping": true, "order": 48 } ] }' ``` ```javascript const data = { create: [ { country: 'US', state: 'AL', rate: '4.0000', name: 'State Tax', shipping: false, order: 1, }, { country: 'US', state: 'AZ', rate: '5.6000', name: 'State Tax', shipping: false, order: 2, }, { country: 'US', state: 'AR', rate: '6.5000', name: 'State Tax', shipping: true, order: 3, }, { country: 'US', state: 'CA', rate: '7.5000', name: 'State Tax', shipping: false, order: 4, }, { country: 'US', state: 'CO', rate: '2.9000', name: 'State Tax', shipping: false, order: 5, }, { country: 'US', state: 'CT', rate: '6.3500', name: 'State Tax', shipping: true, order: 6, }, { country: 'US', state: 'DC', rate: '5.7500', name: 'State Tax', shipping: true, order: 7, }, { country: 'US', state: 'FL', rate: '6.0000', name: 'State Tax', shipping: true, order: 8, }, { country: 'US', state: 'GA', rate: '4.0000', name: 'State Tax', shipping: true, order: 9, }, { country: 'US', state: 'GU', rate: '4.0000', name: 'State Tax', shipping: false, order: 10, }, { country: 'US', state: 'HI', rate: '4.0000', name: 'State Tax', shipping: true, order: 11, }, { country: 'US', state: 'ID', rate: '6.0000', name: 'State Tax', shipping: false, order: 12, }, { country: 'US', state: 'IL', rate: '6.2500', name: 'State Tax', shipping: false, order: 13, }, { country: 'US', state: 'IN', rate: '7.0000', name: 'State Tax', shipping: false, order: 14, }, { country: 'US', state: 'IA', rate: '6.0000', name: 'State Tax', shipping: false, order: 15, }, { country: 'US', state: 'KS', rate: '6.1500', name: 'State Tax', shipping: true, order: 16, }, { country: 'US', state: 'KY', rate: '6.0000', name: 'State Tax', shipping: true, order: 17, }, { country: 'US', state: 'LA', rate: '4.0000', name: 'State Tax', shipping: false, order: 18, }, { country: 'US', state: 'ME', rate: '5.5000', name: 'State Tax', shipping: false, order: 19, }, { country: 'US', state: 'MD', rate: '6.0000', name: 'State Tax', shipping: false, order: 20, }, { country: 'US', state: 'MA', rate: '6.2500', name: 'State Tax', shipping: false, order: 21, }, { country: 'US', state: 'MI', rate: '6.0000', name: 'State Tax', shipping: true, order: 22, }, { country: 'US', state: 'MN', rate: '6.8750', name: 'State Tax', shipping: true, order: 23, }, { country: 'US', state: 'MS', rate: '7.0000', name: 'State Tax', shipping: true, order: 24, }, { country: 'US', state: 'MO', rate: '4.2250', name: 'State Tax', shipping: false, order: 25, }, { country: 'US', state: 'NE', rate: '5.5000', name: 'State Tax', shipping: true, order: 26, }, { country: 'US', state: 'NV', rate: '6.8500', name: 'State Tax', shipping: false, order: 27, }, { country: 'US', state: 'NJ', rate: '7.0000', name: 'State Tax', shipping: true, order: 28, }, { country: 'US', state: 'NM', rate: '5.1250', name: 'State Tax', shipping: true, order: 29, }, { country: 'US', state: 'NY', rate: '4.0000', name: 'State Tax', shipping: true, order: 30, }, { country: 'US', state: 'NC', rate: '4.7500', name: 'State Tax', shipping: true, order: 31, }, { country: 'US', state: 'ND', rate: '5.0000', name: 'State Tax', shipping: true, order: 32, }, { country: 'US', state: 'OH', rate: '5.7500', name: 'State Tax', shipping: true, order: 33, }, { country: 'US', state: 'OK', rate: '4.5000', name: 'State Tax', shipping: false, order: 34, }, { country: 'US', state: 'PA', rate: '6.0000', name: 'State Tax', shipping: true, order: 35, }, { country: 'US', state: 'PR', rate: '6.0000', name: 'State Tax', shipping: false, order: 36, }, { country: 'US', state: 'RI', rate: '7.0000', name: 'State Tax', shipping: false, order: 37, }, { country: 'US', state: 'SC', rate: '6.0000', name: 'State Tax', shipping: true, order: 38, }, { country: 'US', state: 'SD', rate: '4.0000', name: 'State Tax', shipping: true, order: 39, }, { country: 'US', state: 'TN', rate: '7.0000', name: 'State Tax', shipping: true, order: 40, }, { country: 'US', state: 'TX', rate: '6.2500', name: 'State Tax', shipping: true, order: 41, }, { country: 'US', state: 'UT', rate: '5.9500', name: 'State Tax', shipping: false, order: 42, }, { country: 'US', state: 'VT', rate: '6.0000', name: 'State Tax', shipping: true, order: 43, }, { country: 'US', state: 'VA', rate: '5.3000', name: 'State Tax', shipping: false, order: 44, }, { country: 'US', state: 'WA', rate: '6.5000', name: 'State Tax', shipping: true, order: 45, }, { country: 'US', state: 'WV', rate: '6.0000', name: 'State Tax', shipping: true, order: 46, }, { country: 'US', state: 'WI', rate: '5.0000', name: 'State Tax', shipping: true, order: 47, }, { country: 'US', state: 'WY', rate: '4.0000', name: 'State Tax', shipping: true, order: 48, }, ], }; WooCommerce.post( 'taxes/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'country' => 'US', 'state' => 'AL', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 1 ], [ 'country' => 'US', 'state' => 'AZ', 'rate' => '5.6000', 'name' => 'State Tax', 'shipping' => false, 'order' => 2 ], [ 'country' => 'US', 'state' => 'AR', 'rate' => '6.5000', 'name' => 'State Tax', 'shipping' => true, 'order' => 3 ], [ 'country' => 'US', 'state' => 'CA', 'rate' => '7.5000', 'name' => 'State Tax', 'shipping' => false, 'order' => 4 ], [ 'country' => 'US', 'state' => 'CO', 'rate' => '2.9000', 'name' => 'State Tax', 'shipping' => false, 'order' => 5 ], [ 'country' => 'US', 'state' => 'CT', 'rate' => '6.3500', 'name' => 'State Tax', 'shipping' => true, 'order' => 6 ], [ 'country' => 'US', 'state' => 'DC', 'rate' => '5.7500', 'name' => 'State Tax', 'shipping' => true, 'order' => 7 ], [ 'country' => 'US', 'state' => 'FL', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 8 ], [ 'country' => 'US', 'state' => 'GA', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 9 ], [ 'country' => 'US', 'state' => 'GU', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 10 ], [ 'country' => 'US', 'state' => 'HI', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 11 ], [ 'country' => 'US', 'state' => 'ID', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 12 ], [ 'country' => 'US', 'state' => 'IL', 'rate' => '6.2500', 'name' => 'State Tax', 'shipping' => false, 'order' => 13 ], [ 'country' => 'US', 'state' => 'IN', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 14 ], [ 'country' => 'US', 'state' => 'IA', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 15 ], [ 'country' => 'US', 'state' => 'KS', 'rate' => '6.1500', 'name' => 'State Tax', 'shipping' => true, 'order' => 16 ], [ 'country' => 'US', 'state' => 'KY', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 17 ], [ 'country' => 'US', 'state' => 'LA', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 18 ], [ 'country' => 'US', 'state' => 'ME', 'rate' => '5.5000', 'name' => 'State Tax', 'shipping' => false, 'order' => 19 ], [ 'country' => 'US', 'state' => 'MD', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 20 ], [ 'country' => 'US', 'state' => 'MA', 'rate' => '6.2500', 'name' => 'State Tax', 'shipping' => false, 'order' => 21 ], [ 'country' => 'US', 'state' => 'MI', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 22 ], [ 'country' => 'US', 'state' => 'MN', 'rate' => '6.8750', 'name' => 'State Tax', 'shipping' => true, 'order' => 23 ], [ 'country' => 'US', 'state' => 'MS', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 24 ], [ 'country' => 'US', 'state' => 'MO', 'rate' => '4.2250', 'name' => 'State Tax', 'shipping' => false, 'order' => 25 ], [ 'country' => 'US', 'state' => 'NE', 'rate' => '5.5000', 'name' => 'State Tax', 'shipping' => true, 'order' => 26 ], [ 'country' => 'US', 'state' => 'NV', 'rate' => '6.8500', 'name' => 'State Tax', 'shipping' => false, 'order' => 27 ], [ 'country' => 'US', 'state' => 'NJ', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 28 ], [ 'country' => 'US', 'state' => 'NM', 'rate' => '5.1250', 'name' => 'State Tax', 'shipping' => true, 'order' => 29 ], [ 'country' => 'US', 'state' => 'NY', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 30 ], [ 'country' => 'US', 'state' => 'NC', 'rate' => '4.7500', 'name' => 'State Tax', 'shipping' => true, 'order' => 31 ], [ 'country' => 'US', 'state' => 'ND', 'rate' => '5.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 32 ], [ 'country' => 'US', 'state' => 'OH', 'rate' => '5.7500', 'name' => 'State Tax', 'shipping' => true, 'order' => 33 ], [ 'country' => 'US', 'state' => 'OK', 'rate' => '4.5000', 'name' => 'State Tax', 'shipping' => false, 'order' => 34 ], [ 'country' => 'US', 'state' => 'PA', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 35 ], [ 'country' => 'US', 'state' => 'PR', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 36 ], [ 'country' => 'US', 'state' => 'RI', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => false, 'order' => 37 ], [ 'country' => 'US', 'state' => 'SC', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 38 ], [ 'country' => 'US', 'state' => 'SD', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 39 ], [ 'country' => 'US', 'state' => 'TN', 'rate' => '7.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 40 ], [ 'country' => 'US', 'state' => 'TX', 'rate' => '6.2500', 'name' => 'State Tax', 'shipping' => true, 'order' => 41 ], [ 'country' => 'US', 'state' => 'UT', 'rate' => '5.9500', 'name' => 'State Tax', 'shipping' => false, 'order' => 42 ], [ 'country' => 'US', 'state' => 'VT', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 43 ], [ 'country' => 'US', 'state' => 'VA', 'rate' => '5.3000', 'name' => 'State Tax', 'shipping' => false, 'order' => 44 ], [ 'country' => 'US', 'state' => 'WA', 'rate' => '6.5000', 'name' => 'State Tax', 'shipping' => true, 'order' => 45 ], [ 'country' => 'US', 'state' => 'WV', 'rate' => '6.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 46 ], [ 'country' => 'US', 'state' => 'WI', 'rate' => '5.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 47 ], [ 'country' => 'US', 'state' => 'WY', 'rate' => '4.0000', 'name' => 'State Tax', 'shipping' => true, 'order' => 48 ] ] ]; print_r($woocommerce->post('taxes/batch', $data)); ?> ``` ```python data = { "create": [ { "country": "US", "state": "AL", "rate": "4.0000", "name": "State Tax", "shipping": False, "order": 1 }, { "country": "US", "state": "AZ", "rate": "5.6000", "name": "State Tax", "shipping": False, "order": 2 }, { "country": "US", "state": "AR", "rate": "6.5000", "name": "State Tax", "shipping": True, "order": 3 }, { "country": "US", "state": "CA", "rate": "7.5000", "name": "State Tax", "shipping": False, "order": 4 }, { "country": "US", "state": "CO", "rate": "2.9000", "name": "State Tax", "shipping": False, "order": 5 }, { "country": "US", "state": "CT", "rate": "6.3500", "name": "State Tax", "shipping": True, "order": 6 }, { "country": "US", "state": "DC", "rate": "5.7500", "name": "State Tax", "shipping": True, "order": 7 }, { "country": "US", "state": "FL", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 8 }, { "country": "US", "state": "GA", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 9 }, { "country": "US", "state": "GU", "rate": "4.0000", "name": "State Tax", "shipping": False, "order": 10 }, { "country": "US", "state": "HI", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 11 }, { "country": "US", "state": "ID", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 12 }, { "country": "US", "state": "IL", "rate": "6.2500", "name": "State Tax", "shipping": False, "order": 13 }, { "country": "US", "state": "IN", "rate": "7.0000", "name": "State Tax", "shipping": False, "order": 14 }, { "country": "US", "state": "IA", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 15 }, { "country": "US", "state": "KS", "rate": "6.1500", "name": "State Tax", "shipping": True, "order": 16 }, { "country": "US", "state": "KY", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 17 }, { "country": "US", "state": "LA", "rate": "4.0000", "name": "State Tax", "shipping": False, "order": 18 }, { "country": "US", "state": "ME", "rate": "5.5000", "name": "State Tax", "shipping": False, "order": 19 }, { "country": "US", "state": "MD", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 20 }, { "country": "US", "state": "MA", "rate": "6.2500", "name": "State Tax", "shipping": False, "order": 21 }, { "country": "US", "state": "MI", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 22 }, { "country": "US", "state": "MN", "rate": "6.8750", "name": "State Tax", "shipping": True, "order": 23 }, { "country": "US", "state": "MS", "rate": "7.0000", "name": "State Tax", "shipping": True, "order": 24 }, { "country": "US", "state": "MO", "rate": "4.2250", "name": "State Tax", "shipping": False, "order": 25 }, { "country": "US", "state": "NE", "rate": "5.5000", "name": "State Tax", "shipping": True, "order": 26 }, { "country": "US", "state": "NV", "rate": "6.8500", "name": "State Tax", "shipping": False, "order": 27 }, { "country": "US", "state": "NJ", "rate": "7.0000", "name": "State Tax", "shipping": True, "order": 28 }, { "country": "US", "state": "NM", "rate": "5.1250", "name": "State Tax", "shipping": True, "order": 29 }, { "country": "US", "state": "NY", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 30 }, { "country": "US", "state": "NC", "rate": "4.7500", "name": "State Tax", "shipping": True, "order": 31 }, { "country": "US", "state": "ND", "rate": "5.0000", "name": "State Tax", "shipping": True, "order": 32 }, { "country": "US", "state": "OH", "rate": "5.7500", "name": "State Tax", "shipping": True, "order": 33 }, { "country": "US", "state": "OK", "rate": "4.5000", "name": "State Tax", "shipping": False, "order": 34 }, { "country": "US", "state": "PA", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 35 }, { "country": "US", "state": "PR", "rate": "6.0000", "name": "State Tax", "shipping": False, "order": 36 }, { "country": "US", "state": "RI", "rate": "7.0000", "name": "State Tax", "shipping": False, "order": 37 }, { "country": "US", "state": "SC", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 38 }, { "country": "US", "state": "SD", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 39 }, { "country": "US", "state": "TN", "rate": "7.0000", "name": "State Tax", "shipping": True, "order": 40 }, { "country": "US", "state": "TX", "rate": "6.2500", "name": "State Tax", "shipping": True, "order": 41 }, { "country": "US", "state": "UT", "rate": "5.9500", "name": "State Tax", "shipping": False, "order": 42 }, { "country": "US", "state": "VT", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 43 }, { "country": "US", "state": "VA", "rate": "5.3000", "name": "State Tax", "shipping": False, "order": 44 }, { "country": "US", "state": "WA", "rate": "6.5000", "name": "State Tax", "shipping": True, "order": 45 }, { "country": "US", "state": "WV", "rate": "6.0000", "name": "State Tax", "shipping": True, "order": 46 }, { "country": "US", "state": "WI", "rate": "5.0000", "name": "State Tax", "shipping": True, "order": 47 }, { "country": "US", "state": "WY", "rate": "4.0000", "name": "State Tax", "shipping": True, "order": 48 } ] } print(wcapi.post("taxes/batch", data).json()) ``` ```ruby data = { create: [ { country: "US", state: "AL", rate: "4.0000", name: "State Tax", shipping: false, order: 1 }, { country: "US", state: "AZ", rate: "5.6000", name: "State Tax", shipping: false, order: 2 }, { country: "US", state: "AR", rate: "6.5000", name: "State Tax", shipping: true, order: 3 }, { country: "US", state: "CA", rate: "7.5000", name: "State Tax", shipping: false, order: 4 }, { country: "US", state: "CO", rate: "2.9000", name: "State Tax", shipping: false, order: 5 }, { country: "US", state: "CT", rate: "6.3500", name: "State Tax", shipping: true, order: 6 }, { country: "US", state: "DC", rate: "5.7500", name: "State Tax", shipping: true, order: 7 }, { country: "US", state: "FL", rate: "6.0000", name: "State Tax", shipping: true, order: 8 }, { country: "US", state: "GA", rate: "4.0000", name: "State Tax", shipping: true, order: 9 }, { country: "US", state: "GU", rate: "4.0000", name: "State Tax", shipping: false, order: 10 }, { country: "US", state: "HI", rate: "4.0000", name: "State Tax", shipping: true, order: 11 }, { country: "US", state: "ID", rate: "6.0000", name: "State Tax", shipping: false, order: 12 }, { country: "US", state: "IL", rate: "6.2500", name: "State Tax", shipping: false, order: 13 }, { country: "US", state: "IN", rate: "7.0000", name: "State Tax", shipping: false, order: 14 }, { country: "US", state: "IA", rate: "6.0000", name: "State Tax", shipping: false, order: 15 }, { country: "US", state: "KS", rate: "6.1500", name: "State Tax", shipping: true, order: 16 }, { country: "US", state: "KY", rate: "6.0000", name: "State Tax", shipping: true, order: 17 }, { country: "US", state: "LA", rate: "4.0000", name: "State Tax", shipping: false, order: 18 }, { country: "US", state: "ME", rate: "5.5000", name: "State Tax", shipping: false, order: 19 }, { country: "US", state: "MD", rate: "6.0000", name: "State Tax", shipping: false, order: 20 }, { country: "US", state: "MA", rate: "6.2500", name: "State Tax", shipping: false, order: 21 }, { country: "US", state: "MI", rate: "6.0000", name: "State Tax", shipping: true, order: 22 }, { country: "US", state: "MN", rate: "6.8750", name: "State Tax", shipping: true, order: 23 }, { country: "US", state: "MS", rate: "7.0000", name: "State Tax", shipping: true, order: 24 }, { country: "US", state: "MO", rate: "4.2250", name: "State Tax", shipping: false, order: 25 }, { country: "US", state: "NE", rate: "5.5000", name: "State Tax", shipping: true, order: 26 }, { country: "US", state: "NV", rate: "6.8500", name: "State Tax", shipping: false, order: 27 }, { country: "US", state: "NJ", rate: "7.0000", name: "State Tax", shipping: true, order: 28 }, { country: "US", state: "NM", rate: "5.1250", name: "State Tax", shipping: true, order: 29 }, { country: "US", state: "NY", rate: "4.0000", name: "State Tax", shipping: true, order: 30 }, { country: "US", state: "NC", rate: "4.7500", name: "State Tax", shipping: true, order: 31 }, { country: "US", state: "ND", rate: "5.0000", name: "State Tax", shipping: true, order: 32 }, { country: "US", state: "OH", rate: "5.7500", name: "State Tax", shipping: true, order: 33 }, { country: "US", state: "OK", rate: "4.5000", name: "State Tax", shipping: false, order: 34 }, { country: "US", state: "PA", rate: "6.0000", name: "State Tax", shipping: true, order: 35 }, { country: "US", state: "PR", rate: "6.0000", name: "State Tax", shipping: false, order: 36 }, { country: "US", state: "RI", rate: "7.0000", name: "State Tax", shipping: false, order: 37 }, { country: "US", state: "SC", rate: "6.0000", name: "State Tax", shipping: true, order: 38 }, { country: "US", state: "SD", rate: "4.0000", name: "State Tax", shipping: true, order: 39 }, { country: "US", state: "TN", rate: "7.0000", name: "State Tax", shipping: true, order: 40 }, { country: "US", state: "TX", rate: "6.2500", name: "State Tax", shipping: true, order: 41 }, { country: "US", state: "UT", rate: "5.9500", name: "State Tax", shipping: false, order: 42 }, { country: "US", state: "VT", rate: "6.0000", name: "State Tax", shipping: true, order: 43 }, { country: "US", state: "VA", rate: "5.3000", name: "State Tax", shipping: false, order: 44 }, { country: "US", state: "WA", rate: "6.5000", name: "State Tax", shipping: true, order: 45 }, { country: "US", state: "WV", rate: "6.0000", name: "State Tax", shipping: true, order: 46 }, { country: "US", state: "WI", rate: "5.0000", name: "State Tax", shipping: true, order: 47 }, { country: "US", state: "WY", rate: "4.0000", name: "State Tax", shipping: true, order: 48 } ] } woocommerce.post("taxes/batch", data).parsed_response ``` ```json { "create": [ { "id": 72, "country": "US", "state": "AL", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 1, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/72" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 73, "country": "US", "state": "AZ", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.6000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 2, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/73" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 74, "country": "US", "state": "AR", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 3, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/74" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 75, "country": "US", "state": "CA", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "7.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 4, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/75" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 76, "country": "US", "state": "CO", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "2.9000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 5, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/76" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 77, "country": "US", "state": "CT", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.3500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 6, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/77" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 78, "country": "US", "state": "DC", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 7, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/78" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 79, "country": "US", "state": "FL", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 8, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/79" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 80, "country": "US", "state": "GA", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 9, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/80" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 81, "country": "US", "state": "GU", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 10, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/81" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 82, "country": "US", "state": "HI", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 11, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/82" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 83, "country": "US", "state": "ID", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 12, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/83" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 84, "country": "US", "state": "IL", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.2500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 13, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/84" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 85, "country": "US", "state": "IN", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 14, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/85" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 86, "country": "US", "state": "IA", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 15, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/86" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 87, "country": "US", "state": "KS", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.1500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 16, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/87" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 88, "country": "US", "state": "KY", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 17, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/88" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 89, "country": "US", "state": "LA", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 18, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/89" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 90, "country": "US", "state": "ME", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 19, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/90" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 91, "country": "US", "state": "MD", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 20, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/91" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 92, "country": "US", "state": "MA", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.2500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 21, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/92" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 93, "country": "US", "state": "MI", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 22, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/93" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 94, "country": "US", "state": "MN", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.8750", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 23, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/94" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 95, "country": "US", "state": "MS", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 24, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/95" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 96, "country": "US", "state": "MO", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.2250", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 25, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/96" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 97, "country": "US", "state": "NE", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 26, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/97" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 98, "country": "US", "state": "NV", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.8500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 27, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/98" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 99, "country": "US", "state": "NJ", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 28, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/99" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 100, "country": "US", "state": "NM", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.1250", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 29, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/100" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 101, "country": "US", "state": "NY", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 30, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/101" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 102, "country": "US", "state": "NC", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 31, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/102" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 103, "country": "US", "state": "ND", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 32, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/103" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 104, "country": "US", "state": "OH", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.7500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 33, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/104" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 105, "country": "US", "state": "OK", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 34, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/105" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 106, "country": "US", "state": "PA", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 35, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/106" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 107, "country": "US", "state": "PR", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 36, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/107" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 108, "country": "US", "state": "RI", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 37, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/108" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 109, "country": "US", "state": "SC", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 38, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/109" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 110, "country": "US", "state": "SD", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 39, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/110" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 111, "country": "US", "state": "TN", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "7.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 40, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/111" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 112, "country": "US", "state": "TX", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.2500", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 41, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/112" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 113, "country": "US", "state": "UT", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.9500", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 42, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/113" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 114, "country": "US", "state": "VT", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 43, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/114" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 115, "country": "US", "state": "VA", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.3000", "name": "State Tax", "priority": 0, "compound": false, "shipping": false, "order": 44, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/115" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 116, "country": "US", "state": "WA", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.5000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 45, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/116" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 117, "country": "US", "state": "WV", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "6.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 46, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/117" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 118, "country": "US", "state": "WI", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "5.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 47, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/118" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } }, { "id": 119, "country": "US", "state": "WY", "postcode": "", "city": "", "postcodes": [], "cities": [], "rate": "4.0000", "name": "State Tax", "priority": 0, "compound": false, "shipping": true, "order": 48, "class": "standard", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/taxes/119" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/taxes" } ] } } ] } ``` --- ## Webhooks *Source: apis/rest-api/v3/webhooks.mdx* import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; # Webhooks The webhooks API allows you to create, view, update, and delete individual, or a batch, of webhooks. Webhooks can be managed via the WooCommerce settings screen or by using the REST API endpoints. The `WC_Webhook` class manages all data storage and retrieval of the webhook custom post type, as well as enqueuing webhook actions and processing/delivering/logging webhooks. On `woocommerce_init`, active webhooks are loaded. Each webhook has: - `status`: active (delivers payload), paused (delivery paused by admin), disabled (delivery paused by failure). - `topic`: determines which resource events the webhook is triggered for. - `delivery URL`: URL where the payload is delivered, must be HTTP or HTTPS. - `secret`: an optional secret key that is used to generate a HMAC-SHA256 hash of the request body so the receiver can verify authenticity of the webhook. - `hooks`: an array of hook names that are added and bound to the webhook for processing. ### Topics The topic is a combination resource (e.g. order) and event (e.g. created) and maps to one or more hook names (e.g. `woocommerce_checkout_order_processed`). Webhooks can be created using the topic name and the appropriate hooks are automatically added. Core topics are: - Coupons: `coupon.created`, `coupon.updated` and `coupon.deleted`. - Customers: `customer.created`, `customer.updated` and `customer.deleted`. - Orders: `order.created`, `order.updated` and `order.deleted`. - Products: `product.created`, `product.updated` and `product.deleted`. Custom topics can also be used which map to a single hook name, for example you could add a webhook with topic `action.woocommerce_add_to_cart` that is triggered on that event. Custom topics pass the first hook argument to the payload, so in this example the `cart_item_key` would be included in the payload. ### Delivery/payload Delivery is performed using `wp_remote_post()` (HTTP POST) and processed in the background by default using wp-cron. A few custom headers are added to the request to help the receiver process the webhook: - `X-WC-Webhook-Source`: `http://example.com/`. - `X-WC-Webhook-Topic` - e.g. `order.updated`. - `X-WC-Webhook-Resource` - e.g. `order`. - `X-WC-Webhook-Event` - e.g. `updated`. - `X-WC-Webhook-Signature` - a base64 encoded HMAC-SHA256 hash of the payload. - `X-WC-Webhook-ID` - webhook's post ID. - `X-WC-Webhook-Delivery-ID` - delivery log ID (a comment). The payload is JSON encoded and for API resources (coupons, customers, orders, products), the response is exactly the same as if requested via the REST API. ### Logging Requests/responses are logged using the WooCommerce logging system. Each delivery log includes: - Request duration. - Request URL, method, headers, and body. - Response Code, message, headers, and body. After 5 consecutive failed deliveries (as defined by a non HTTP 2xx response code), the webhook is disabled and must be edited via the REST API to re-enable. Delivery logs can be accessed in "WooCommerce" > "Status" > "Logs". ### Visual interface You can find the Webhooks interface going to "WooCommerce" > "Settings" > "Advanced" > "Webhooks", see our [Visual Webhooks docs](https://docs.woocommerce.com/document/webhooks/) for more details. ## Webhook properties | Attribute | Type | Description | | ------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | | `id` | integer | Unique identifier for the resource. `READ-ONLY` | | `name` | string | A friendly name for the webhook. | | `status` | string | Webhook status. Options: `active`, `paused` and `disabled`. Default is `active`. | | `topic` | string | Webhook topic. `MANDATORY` | | `resource` | string | Webhook resource. `READ-ONLY` | | `event` | string | Webhook event. `READ-ONLY` | | `hooks` | array | WooCommerce action names associated with the webhook. `READ-ONLY` | | `delivery_url` | string | The URL where the webhook payload is delivered. `READ-ONLY` `MANDATORY` | | `secret` | string | Secret key used to generate a hash of the delivered webhook and provided in the request headers. This will default is a MD5 hash from the current user's ID | username if not provided. `WRITE-ONLY` `MANDATORY` | | `date_created` | date-time | The date the webhook was created, in the site's timezone. `READ-ONLY` | | `date_created_gmt` | date-time | The date the webhook was created, as GMT. `READ-ONLY` | | `date_modified` | date-time | The date the webhook was last modified, in the site's timezone. `READ-ONLY` | | `date_modified_gmt` | date-time | The date the webhook was last modified, as GMT. `READ-ONLY` | ## Create a webhook This API helps you to create a new webhook. ```http POST /wp-json/wc/v3/webhooks ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/webhooks \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "name": "Order updated", "topic": "order.updated", "delivery_url": "http://requestb.in/1g0sxmo1" }' ``` ```javascript const data = { name: 'Order updated', topic: 'order.updated', delivery_url: 'http://requestb.in/1g0sxmo1', }; WooCommerce.post( 'webhooks', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'Order updated', 'topic' => 'order.updated', 'delivery_url' => 'http://requestb.in/1g0sxmo1' ]; print_r($woocommerce->post('webhooks', $data)); ?> ``` ```python data = { "name": "Order updated", "topic": "order.updated", "delivery_url": "http://requestb.in/1g0sxmo1" } print(wcapi.post("webhooks", data).json()) ``` ```ruby data = { name: "Order updated", topic: "order.updated", delivery_url: "http://requestb.in/1g0sxmo1" } woocommerce.post("webhooks", data).parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "active", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:17:52", "date_modified_gmt": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/webhooks" } ] } } ``` ## Retrieve a webhook This API lets you retrieve and view a specific webhook. ```http GET /wp-json/wc/v3/webhooks/ ``` ```shell curl https://example.com/wp-json/wc/v3/webhooks/142 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'webhooks/142' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('webhooks/142')); ?> ``` ```python print(wcapi.get("webhooks/142").json()) ``` ```ruby woocommerce.get("webhooks/142").parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "active", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:17:52", "date_modified_gmt": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/webhooks" } ] } } ``` ## List all webhooks This API helps you to view all the webhooks. ```http GET /wp-json/wc/v3/webhooks ``` ```shell curl https://example.com/wp-json/wc/v3/webhooks \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.get( 'webhooks' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php get('webhooks')); ?> ``` ```python print(wcapi.get("webhooks").json()) ``` ```ruby woocommerce.get("webhooks").parsed_response ``` ```json [ { "id": 143, "name": "Customer created", "status": "active", "topic": "customer.created", "resource": "customer", "event": "created", "hooks": [ "user_register", "woocommerce_created_customer", "woocommerce_api_create_customer" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:17:52", "date_modified_gmt": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/webhooks/143" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/webhooks" } ] } }, { "id": 142, "name": "Order updated", "status": "active", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:17:52", "date_modified_gmt": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/webhooks" } ] } } ] ``` #### Available parameters | Parameter | Type | Description | | --------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------- | | `context` | string | Scope under which the request is made; determines fields present in response. Options: `view` and `edit`. Default is `view`. | | `page` | integer | Current page of the collection. Default is `1`. | | `per_page` | integer | Maximum number of items to be returned in result set. Default is `10`. | | `search` | string | Limit results to those matching a string. | | `after` | string | Limit response to resources published after a given ISO8601 compliant date. | | `before` | string | Limit response to resources published before a given ISO8601 compliant date. | | `dates_are_gmt` | boolean | Whether to interpret dates as GMT dates when limiting response by published date. | | `exclude` | array | Ensure result set excludes specific IDs. | | `include` | array | Limit result set to specific ids. | | `offset` | integer | Offset the result set by a specific number of items. | | `order` | string | Order sort attribute ascending or descending. Options: `asc` and `desc`. Default is `desc`. | | `orderby` | string | Sort collection by object attribute. Options: `date`, `id`, `include`, `title` and `slug`. Default is `date`. | | `status` | string | Limit result set to webhooks assigned a specific status. Options: `all`, `active`, `paused` and `disabled`. Default is `all`. | ## Update a webhook This API lets you make changes to a webhook. ```http PUT /wp-json/wc/v3/webhooks/ ``` ```shell curl -X PUT https://example.com/wp-json/wc/v3/webhooks/142 \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "status": "paused" }' ``` ```javascript const data = { status: 'paused', }; WooCommerce.put( 'webhooks/142', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php 'paused' ]; print_r($woocommerce->put('webhooks/142', $data)); ?> ``` ```python data = { "status": "paused" } print(wcapi.put("webhooks/142", data).json()) ``` ```ruby data = { status: "paused" } woocommerce.put("webhooks/142", data).parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "paused", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T17:30:12", "date_modified_gmt": "2016-05-15T20:30:12", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/webhooks" } ] } } ``` ## Delete a webhook This API helps you delete a webhook. ```http DELETE /wp-json/wc/v3/webhooks/ ``` ```shell curl -X DELETE https://example.com/wp-json/wc/v3/webhooks/142 \ -u consumer_key:consumer_secret ``` ```javascript WooCommerce.delete( 'webhooks/142' ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php delete('webhooks/142')); ?> ``` ```python print(wcapi.delete("webhooks/142").json()) ``` ```ruby woocommerce.delete("webhooks/142").parsed_response ``` ```json { "id": 142, "name": "Order updated", "status": "paused", "topic": "order.updated", "resource": "order", "event": "updated", "hooks": [ "woocommerce_process_shop_order_meta", "woocommerce_api_edit_order", "woocommerce_order_edit_status", "woocommerce_order_status_changed" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:30:12", "date_modified_gmt": "2016-05-15T20:30:12", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/webhooks/142" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/webhooks" } ] } } ``` #### Available parameters | Parameter | Type | Description | | --------- | ------ | -------------------------------------------------------------------------- | | `force` | string | Use `true` whether to permanently delete the webhook, Defaults is `false`. | ## Batch update webhooks This API helps you to batch create, update and delete multiple webhooks. :::note Note: By default it's limited to up to 100 objects to be created, updated or deleted. ::: ```http POST /wp-json/wc/v3/webhooks/batch ``` ```shell curl -X POST https://example.com/wp-json/wc/v3/webhooks/batch \ -u consumer_key:consumer_secret \ -H "Content-Type: application/json" \ -d '{ "create": [ { "name": "Coupon created", "topic": "coupon.created", "delivery_url": "http://requestb.in/1g0sxmo1" }, { "name": "Customer deleted", "topic": "customer.deleted", "delivery_url": "http://requestb.in/1g0sxmo1" } ], "delete": [ 143 ] }' ``` ```javascript const data = { create: [ { name: 'Round toe', topic: 'coupon.created', delivery_url: 'http://requestb.in/1g0sxmo1', }, { name: 'Customer deleted', topic: 'customer.deleted', delivery_url: 'http://requestb.in/1g0sxmo1', }, ], delete: [ 143 ], }; WooCommerce.post( 'webhooks/batch', data ) .then( ( response ) => { console.log( response.data ); } ) .catch( ( error ) => { console.log( error.response.data ); } ); ``` ```php [ [ 'name' => 'Round toe', 'topic' => 'coupon.created', 'delivery_url' => 'http://requestb.in/1g0sxmo1' ], [ 'name' => 'Customer deleted', 'topic' => 'customer.deleted', 'delivery_url' => 'http://requestb.in/1g0sxmo1' ] ], 'delete' => [ 143 ] ]; print_r($woocommerce->post('webhooks/batch', $data)); ?> ``` ```python data = { "create": [ { "name": "Round toe", "topic": "coupon.created", "delivery_url": "http://requestb.in/1g0sxmo1" }, { "name": "Customer deleted", "topic": "customer.deleted", "delivery_url": "http://requestb.in/1g0sxmo1" } ], "delete": [ 143 ] } print(wcapi.post("webhooks/batch", data).json()) ``` ```ruby data = { create: [ { name: "Round toe", topic: "coupon.created", delivery_url: "http://requestb.in/1g0sxmo1" }, { name: "Customer deleted", topic: "customer.deleted", delivery_url: "http://requestb.in/1g0sxmo1" } ], delete: [ 143 ] } woocommerce.post("webhooks/batch", data).parsed_response ``` ```json { "create": [ { "id": 146, "name": "Coupon created", "status": "active", "topic": "coupon.created", "resource": "coupon", "event": "created", "hooks": [ "woocommerce_process_shop_coupon_meta", "woocommerce_api_create_coupon" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-25T01:56:26", "date_created_gmt": "2016-05-24T22:56:26", "date_modified": "2016-05-25T01:56:26", "date_modified_gmt": "2016-05-24T22:56:26", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/webhooks/146" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/webhooks" } ] } }, { "id": 147, "name": "Customer deleted", "status": "active", "topic": "customer.deleted", "resource": "customer", "event": "deleted", "hooks": [ "delete_user" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-25T01:56:30", "date_created_gmt": "2016-05-24T22:56:30", "date_modified": "2016-05-25T01:56:30", "date_modified_gmt": "2016-05-24T22:56:30", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/webhooks/147" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/webhooks" } ] } } ], "delete": [ { "id": 143, "name": "Webhook created on May 24, 2016 @ 03:20 AM", "status": "active", "topic": "customer.created", "resource": "customer", "event": "created", "hooks": [ "user_register", "woocommerce_created_customer", "woocommerce_api_create_customer" ], "delivery_url": "http://requestb.in/1g0sxmo1", "date_created": "2016-05-15T23:17:52", "date_created_gmt": "2016-05-15T20:17:52", "date_modified": "2016-05-15T23:17:52", "date_modified_gmt": "2016-05-15T20:17:52", "_links": { "self": [ { "href": "https://example.com/wp-json/wc/v3/webhooks/143" } ], "collection": [ { "href": "https://example.com/wp-json/wc/v3/webhooks" } ] } } ] } ``` --- ## WooCommerce Store API *Source: apis/store-api/README.md* # WooCommerce Store API **The Store API provides public Rest API endpoints for the development of customer-facing cart, checkout, and product functionality. It follows many of the patterns used in the [WordPress REST API](https://developer.wordpress.org/rest-api/key-concepts/).** In contrast to the WooCommerce REST API, the Store API is unauthenticated and does not provide access to sensitive store data or other customer information. Example of a valid API request using cURL: ```sh curl "https://example-store.com/wp-json/wc/store/v1/products" ``` Possible uses of the Store API include: 1. Obtaining a list of products to display that can be searched or filtered 2. Adding products to the cart and returning an updated cart object for display 3. Obtaining shipping rates for a cart 4. Converting a customer’s cart to an Order, collecting addresses, and then facilitating payment ## Requirements and limitations * This is an unauthenticated API. It does not require API keys or authentication tokens for access. * All API responses return JSON-formatted data. * Data returned from the API is reflective of the current user (customer). Customer sessions in WooCommerce are cookie-based. * Store API cannot be used to look up other customers and orders by ID; only data belonging to the current user. * Likewise, Store API cannot be used to write store data e.g. settings. For more extensive access, use the authenticated [WC REST API.](/docs/apis/rest-api/) * Endpoints that do allow writes, for example, updating the current customer address, require a [nonce-token](https://developer.wordpress.org/plugins/security/nonces/). * Store API is render-target agnostic and should not make assumptions about where content will be displayed. For example, returning HTML would be discouraged unless the data type itself is HTML. ## Store API Namespace Resources in the Store API are all found within the `wc/store/v1` namespace, and since this API extends the WordPress API, accessing it requires the `/wp-json/` base. Currently, the only version is `v1`. If the version is omitted, `v1` will be served. Examples: ```http GET /wp-json/wc/store/v1/products GET /wp-json/wc/store/v1/cart ``` The API uses JSON to serialize data. You don’t need to specify `.json` at the end of an API URL. ## Resources and endpoints Available resources in the Store API are listed below, with links to more detailed documentation. | Resource | Methods | Endpoints | | --- | --- | --- | | [`Cart`](/docs/apis/store-api/resources-endpoints/cart) | `GET` | [`/wc/store/v1/cart`](/docs/apis/store-api/resources-endpoints/cart#get-cart) | | | `POST` | [`/wc/store/v1/cart/add-item`](/docs/apis/store-api/resources-endpoints/cart#add-item) | | | `POST` | [`/wc/store/v1/cart/remove-item`](/docs/apis/store-api/resources-endpoints/cart#remove-item) | | | `POST` | [`/wc/store/v1/cart/update-item`](/docs/apis/store-api/resources-endpoints/cart#update-item) | | | `POST` | [`/wc/store/v1/cart/apply-coupon`](/docs/apis/store-api/resources-endpoints/cart#apply-coupon) | | | `POST` | [`/wc/store/v1/cart/remove-coupon`](/docs/apis/store-api/resources-endpoints/cart#remove-coupon) | | | `POST` | [`/wc/store/v1/cart/update-customer`](/docs/apis/store-api/resources-endpoints/cart#update-customer) | | | `POST` | [`/wc/store/v1/cart/select-shipping-rate`](/docs/apis/store-api/resources-endpoints/cart#select-shipping-rate) | | [`Cart Items`](/docs/apis/store-api/resources-endpoints/cart-items) | `GET`, `POST`, `DELETE` | [`/wc/store/v1/cart/items`](/docs/apis/store-api/resources-endpoints/cart-items#list-cart-items) | | | `GET`, `POST`, `PUT`, `DELETE` | [`/wc/store/v1/cart/items/:key`](/docs/apis/store-api/resources-endpoints/cart-items#single-cart-item) | | [`Cart Coupons`](/docs/apis/store-api/resources-endpoints/cart-coupons) | `GET`, `POST`, `DELETE` | [`/wc/store/v1/cart/coupons`](/docs/apis/store-api/resources-endpoints/cart-coupons#list-cart-coupons) | | | `GET`, `DELETE` | [`/wc/store/v1/cart/coupon/:code`](/docs/apis/store-api/resources-endpoints/cart-coupons#single-cart-coupon) | | [`Checkout`](/docs/apis/store-api/resources-endpoints/checkout) | `GET`, `POST`, `PUT` | [`/wc/store/v1/checkout`](/docs/apis/store-api/resources-endpoints/checkout) | | [`Checkout order`](/docs/apis/store-api/resources-endpoints/checkout-order) | `POST` | [`/wc/store/v1/checkout/:id`](/docs/apis/store-api/resources-endpoints/checkout-order) | | [`Order`](/docs/apis/store-api/resources-endpoints/order) | `GET` | [`/wc/store/v1/order/:id`](/docs/apis/store-api/resources-endpoints/order) | | [`Products`](/docs/apis/store-api/resources-endpoints/products) | `GET` | [`/wc/store/v1/products`](/docs/apis/store-api/resources-endpoints/products#list-products) | | | `GET` | [`/wc/store/v1/products/:id`](/docs/apis/store-api/resources-endpoints/products#single-product-by-id) | | [`Product Collection Data`](/docs/apis/store-api/resources-endpoints/product-collection-data) | `GET` | [`/wc/store/v1/products/collection-data`](/docs/apis/store-api/resources-endpoints/product-collection-data) | | [`Product Attributes`](/docs/apis/store-api/resources-endpoints/product-attributes) | `GET` | [`/wc/store/v1/products/attributes`](/docs/apis/store-api/resources-endpoints/product-attributes#list-product-attributes) | | | `GET` | [`/wc/store/v1/products/attributes/:id`](/docs/apis/store-api/resources-endpoints/product-attributes#single-product-attribute) | | [`Product Attribute Terms`](/docs/apis/store-api/resources-endpoints/product-attribute-terms) | `GET` | [`/wc/store/v1/products/attributes/:id/terms`](/docs/apis/store-api/resources-endpoints/product-attribute-terms) | | [`Product Categories`](/docs/apis/store-api/resources-endpoints/product-categories) | `GET` | [`/wc/store/v1/products/categories`](/docs/apis/store-api/resources-endpoints/product-categories) | | [`Product Brands`](/docs/apis/store-api/resources-endpoints/product-brands) | `GET` | [`/wc/store/v1/products/brands`](/docs/apis/store-api/resources-endpoints/product-brands) | | [`Product Reviews`](/docs/apis/store-api/resources-endpoints/product-reviews) | `GET` | [`/wc/store/v1/products/reviews`](/docs/apis/store-api/resources-endpoints/product-reviews) | | [`Product Tags`](/docs/apis/store-api/resources-endpoints/product-tags) | `GET` | [`/wc/store/v1/products/tags`](/docs/apis/store-api/resources-endpoints/product-tags) | ## Pagination If collections contain many results, they may be paginated. When listing resources you can pass the following parameters: | Parameter | Description | | :--------- | :------------------------------------------------------------------------------------- | | `page` | Current page of the collection. Defaults to `1`. | | `per_page` | Maximum number of items to be returned in result set. Defaults to `10`. Maximum `100`. | In the example below, we list 20 products per page and return page 2. ```sh curl "https://example-store.com/wp-json/wc/store/v1/products?page=2&per_page=20" ``` Additional pagination headers are also sent back with extra information. | Header | Description | | :---------------- | :------------------------------------------------------------------------ | | `X-WP-Total` | The total number of items in the collection. | | `X-WP-TotalPages` | The total number of pages in the collection. | | `Link` | Contains links to other pages; `next`, `prev`, and `up` where applicable. | ## Status codes The following table gives an overview of how the API functions generally behave. | Request type | Description | | :----------- | :---------------------------------------------------------------------------------------------------------- | | `GET` | Access one or more resources and return `200 OK` and the result as JSON. | | `POST` | Return `201 Created` if the resource is successfully created and return the newly created resource as JSON. | | `PUT` | Return `200 OK` if the resource is modified successfully. The modified result is returned as JSON. | | `DELETE` | Returns `204 No Content` if the resource was deleted successfully. | The following table shows the possible return codes for API requests. | Response code | Description | | :----------------------- | :------------------------------------------------------------------------------------------------------------------------------------------ | | `200 OK` | The request was successful, the resource(s) itself is returned as JSON. | | `204 No Content` | The server has successfully fulfilled the request and that there is no additional content to send in the response payload body. | | `201 Created` | The POST request was successful and the resource is returned as JSON. | | `400 Bad Request` | A required attribute of the API request is missing. | | `403 Forbidden` | The request is not allowed. | | `404 Not Found` | A resource could not be accessed, for example it doesn't exist. | | `405 Method Not Allowed` | The request is not supported. | | `409 Conflict` | The request could not be completed due to a conflict with the current state of the target resource. The current state may also be returned. | | `500 Server Error` | While handling the request something went wrong server-side. | ## Contributing There are 3 main parts to each route in the Store API: 1. Route - Responsible for mapping requests to endpoints. Routes in the Store API extend the `AbstractRoute` class; this class contains shared functionality for handling requests and returning JSON responses. Routes ensure a valid response is returned and handle collections, errors, and pagination. 2. Schema - Routes do not format resources. Instead we use _Schema_ classes that represent each type of resource, for example, a Product, a Cart, or a Cart Item. Schema classes in the Store API should extend the `AbstractSchema` class. 3. Utility - In more advanced cases where the Store API needs to access complex data from WooCommerce core, or where multiple routes need access to the same data, routes should use a Controller or Utility class. For example, the Store API has an Order Controller and a Cart Controller for looking up order and cart data respectfully. Typically, routes handle the following types of requests: * `GET` requests to read product, cart, or checkout data. * `POST` and `PUT` requests to update cart and checkout data. * `DELETE` requests to remove cart data. * `OPTIONS` requests to retrieve the JSON schema for the current route. Please review the [Store API Guiding principles](/docs/apis/store-api/guiding-principles). This covers our approach to development, and topics such as versioning, what data is safe to include, and how to build new routes. ## Extensibility The approach to extensibility within the Store API is to expose certain routes and schema to the ExtendSchema class. [Documentation for contributors on this can be found here](/docs/apis/store-api/extending-store-api/). If a route includes the extensibility interface, 3rd party developers can use the shared `ExtendSchema::class` instance to register additional endpoint data and additional schema. This differs from the traditional filter hook approach in that it is more limiting, but it reduces the likelihood of a 3rd party extension breaking routes and endpoints or overwriting returned data which other apps may rely upon. If new schema is required, and any of the following statements are true, choose to _extend_ the Store API rather than introducing new schema to existing Store API schemas: * The data is part of an extension, not core * The data is related to a resource, but not technically part of it * The data is difficult to query (performance wise) or has a very narrow or niche use-case If the data is sensitive (for example, a core setting that should be private), or not related to the current user (for example, looking up an order by order ID), [choose to use the authenticated WC REST API](/docs/apis/rest-api/). If you're looking to add _new routes and endpoints_, rather than extending the Store API _schema_, extending the Store API is not necessary. You can instead utilize core WordPress functionality to create new routes, choosing to use the same pattern of Store API if you wish. See: * [`register_rest_route()`](https://developer.wordpress.org/reference/functions/register_rest_route/) * [Rest API Permissions Callbacks](https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/#permissions-callback) --- ## Cart Tokens *Source: apis/store-api/cart-tokens.md* # Cart Tokens Cart tokens can be used instead of cookies based sessions for headless interaction with carts. When using a `Cart-Token` a [Nonce Token](/docs/apis/store-api/nonce-tokens) is not required. ## Obtaining a Cart Token Requests to `/cart` endpoints return a `Cart-Token` header alongside the response. This contains a token which can later be sent as a request header to the Store API Cart and Checkout endpoints to identify the cart. The quickest method of obtaining a Cart Token is to make a GET request `/wp-json/wc/store/v1/cart` and observe the response headers. You should see a `Cart-Token` header there. ## How to use a Cart-Token To use a `Cart-Token`, include it as a header with your request. The response will contain the current cart state from the session associated with the `Cart-Token`. **Example:** ```sh curl --header "Cart-Token: 12345" --request GET https://example-store.com/wp-json/wc/store/v1/cart ``` The same method will allow you to checkout using a `Cart-Token` on the `/checkout` route. --- ## Extending the Store API *Source: apis/store-api/extending-store-api/README.md* # Extending the Store API Your application can change the way the Store API works by extending certain endpoints. It can add data to certain endpoints to make your server-side data available to the client-side. You can also use the Store API trigger a server-side cart update from the client which will then update the client-side cart with the data returned by the API. The documents listed below contain further details on how to achieve the above. | Document | Description | |----------|-------------| | [Exposing your data](./extend-store-api-add-data/) | Explains how you can add additional data to Store API endpoints. | | [Available extensible endpoints](./available-endpoints-to-extend/) | A list of all available endpoints to extend. | | [Available Formatters](./extend-store-api-formatters/) | Available `Formatters` to format data for use in the Store API. | | [Updating the cart on-demand](./extend-store-api-update-cart/) | Update the server-side cart following an action from the front-end. | | [Adding fields and passing values](./extend-store-api-add-custom-fields/) | How to add custom fields to Store API endpoints. | --- ## Available extensible endpoints *Source: apis/store-api/extending-store-api/available-endpoints-to-extend.md* # Available extensible endpoints Some endpoints of the Store API are extensible via a class called `ExtendSchema`. This allows you to customise the data (including the schema) that is returned by the Store API so that it can be consumed by your application or plugin. For more information about extending the Store API, you may also be interested in: - [How to add your data to Store API using `ExtendSchema`](./extend-store-api-add-data.md) - [How to add a new endpoint](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/docs/internal-developers/rest-api/extend-rest-api-new-endpoint.md) Below is a list of available endpoints that you can extend using `ExtendSchema`, as well as some example use-cases. ## Products The main `wc/store/products` endpoint is extensible via ExtendSchema. The data is available via the `extensions` key for each `product` in the response array. This endpoint can be extended using the `ProductSchema::IDENTIFIER` key. For this endpoint, your `data_callback` callback function is passed `$product` as a parameter. Your `schema_callback` function is passed no additional parameters; all products should share the same schema. ### Use Cases This endpoint is useful for adding additional data about individual products. This could be some meta data, additional pricing, or anything else to support custom blocks or components on the products page. ### Example ```php woocommerce_store_api_register_endpoint_data( array( 'endpoint' => ProductSchema::IDENTIFIER, 'namespace' => 'my_plugin_namespace', 'data_callback' => function( $product ) { return array( 'my_meta_data' => get_post_meta( $product->get_id(), 'my_meta_data', true ), ); }, 'schema_callback' => function() { return array( 'properties' => array( 'my_meta_data' => array( 'type' => 'string', ), ), ); }, 'schema_type' => ARRAY_A, ) ); ``` ## Cart The main `wc/store/cart` endpoint is extensible via ExtendSchema. The data is available via the `extensions` key in the response. This endpoint can be extended using the `CartSchema::IDENTIFIER` key. For this endpoint, your `data_callback` and `schema_callback` functions are passed no additional parameters. ### Use Cases This endpoint is useful for adding additional data to the cart page, for example, extra data about the cart items, or anything else needed to support custom blocks displayed on the cart page. ### Example ```php woocommerce_store_api_register_endpoint_data( array( 'endpoint' => CartSchema::IDENTIFIER, 'namespace' => 'my_plugin_namespace', 'data_callback' => function() { return array( 'foo' => 'bar', ); }, 'schema_callback' => function() { return array( 'properties' => array( 'foo' => array( 'type' => 'string', ), ), ); }, 'schema_type' => ARRAY_A, ) ); ``` ## Cart Items The `wc/store/cart/items` endpoint, which is also available on `wc/store/cart` inside the `items` key. The data would be available inside each item of the `items` array. This endpoint can be extended using the `CartItemSchema::IDENTIFIER` key. For this endpoint, your `data_callback` callback function is passed `$cart_item` as a parameter. Your `schema_callback` function is passed no additional parameters; all cart items should share the same schema. ### Use Cases This endpoint is useful for adding additional data about individual cart items. This could be some meta data, additional pricing, or anything else to support custom blocks or components on the cart page. ### Example ```php woocommerce_store_api_register_endpoint_data( array( 'endpoint' => CartItemSchema::IDENTIFIER, 'namespace' => 'my_plugin_namespace', 'data_callback' => function( $cart_item ) { $product = $cart_item['data']; return array( 'my_meta_data' => get_post_meta( $product->get_id(), 'my_meta_data', true ), ); }, 'schema_callback' => function() { return array( 'properties' => array( 'my_meta_data' => array( 'type' => 'string', ), ), ); }, 'schema_type' => ARRAY_A, ) ); ``` ## Checkout The `wc/store/checkout` endpoint is extensible via ExtendSchema. Additional data is available via the `extensions` key in the response. This endpoint can be extended using the `CheckoutSchema::IDENTIFIER` key. For this endpoint, your `data_callback` and `schema_callback` functions are passed no additional parameters. ### Use Cases This endpoint is useful for adding additional data to the checkout page, such as a custom payment method which requires additional data to be collected from the user or server. ⚠ **Important: Do **not** reveal any sensitive data in this endpoint, as it is publicly accessible. This includes private keys for payment services.** ### Example ```php woocommerce_store_api_register_endpoint_data( array( 'endpoint' => CheckoutSchema::IDENTIFIER, 'namespace' => 'my_plugin_namespace', 'data_callback' => function() { return array( 'foo' => 'bar', ); }, 'schema_callback' => function() { return array( 'properties' => array( 'foo' => array( 'type' => 'string', ), ), ); }, 'schema_type' => ARRAY_A, ) ); ``` --- ## Adding fields and passing values *Source: apis/store-api/extending-store-api/extend-store-api-add-custom-fields.md* # Adding fields and passing values This document describes how a developer can insert an input field into the Checkout block and have its value passed to the Store API so it's available when processing the checkout. ## Overview Developers can extend the Checkout block to add new inner blocks and process additional data through the checkout POST request. This involves leveraging the extensibility interfaces provided by Gutenberg and WooCommerce Blocks. This is demonstrated in more detail in our tutorial: [Tutorial: Extending the WooCommerce Checkout Block ](https://developer.woocommerce.com/2023/08/07/extending-the-woocommerce-checkout-block-to-add-custom-shipping-options/). ## Prerequisites - Basic understanding of React and the Gutenberg block editor. - Familiarity with WooCommerce Blocks' extensibility interfaces and the Store API. ## Step-by-Step Guide ### 1. Set Up Your Development Environment Ensure you have the following files in your project: - `index.js`: Entry point for Webpack, imports, and registers the block type. - `edit.js`: Handles the rendering of the block in the editor interface. - `block.json`: Provides metadata and configurations for the block. - `block.js`: Manages the block's state and user interactions. - `frontend.js`: Registers the checkout block component for the frontend. Refer to [this tutorial](https://developer.woocommerce.com/2023/08/07/extending-the-woocommerce-checkout-block-to-add-custom-shipping-options/) for an example of adding a custom shipping option to the checkout block. ### 2. Add a new field block to the Checkout Block To add a field block to the Checkout Block you will need to add the following entries to the `block.json` file of your block: ```json "parent": [ "woocommerce/checkout-shipping-methods-block" ], "attributes": { "lock": { "type": "object", "default": { "remove": true, "move": true } } } ``` - The [lock attribute](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-templates/#individual-block-locking) is an object that controls whether the block can be removed or moved. By default, the lock attribute is set to allow the block to be removed and moved. However, by modifying the lock attribute, you can “force” the block to be non-removable. For example, you can set both remove and move properties to false in order to prevent the block from being removed or moved. - The [parent attribute](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#parent) specifies the parent block that this block should be nested within it. It determines where the block will render. In our example, the block is a child of the `woocommerce/checkout-shipping-methods-block`. This means that your block will be rendered within the `woocommerce/checkout-shipping-methods-block`. If the shipping methods block is not required, your block will not be rendered. ### 3. Setting custom checkout data We can set the added field data to send it to the `wc/store/checkout` endpoint when processing orders using the function `setExtensionData`: ```JavaScript setExtensionData( 'namespace-of-your-block', 'key-of-your-data', value ); ``` #### Parameters - namespace `string` - The namespace of your block. - key `string` - The key of your data. - value `any` - The value of your data. #### How it works 1. `setExtensionData` is passed to inner blocks via props. 2. It updates the `extensionData` key of the `wc/store/checkout` data store. 3. This key is passed as part of the request body when POSTing to the checkout endpoint. #### Code Example ```JavaScript // block.js export const Block = ( { checkoutExtensionData, extensions } ) => { /** * setExtensionData will update the wc/store/checkout data store with the values supplied. It * can be used to pass data from the client to the server when submitting the checkout form. */ const { setExtensionData } = checkoutExtensionData; } // ... Some code here useEffect( () => { /** * This code should use `setExtensionData` to update the `key-of-your-data` key * in the `namespace-of-your-block` namespace of the checkout data store. */ setExtensionData( 'namespace-of-your-block', 'key-of-your-data', value ); }, [ setExtensionData, value ] ); ``` #### Screenshots Screenshots of Redux Dev tool showing the data store before and after the setExtensionData call: | Before | After | | ------ | ----- | | ![Redux Dev tool before setExtensionData call](https://github.com/woocommerce/woocommerce-blocks/assets/14235870/948581f5-fdc2-4df1-963f-9aeb4b18b042) | ![Redux Dev tool after setExtensionData call](https://github.com/woocommerce/woocommerce-blocks/assets/14235870/ddc7dbe7-3fad-44cd-bd19-ce78bc49b951) | ### 4. Processing the Checkout POST Request To process the added field data, we'll need extend the Store API to tell it to expect additional data. See more details in the [Exposing your data in the Store API](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/rest-api/extend-store-api-add-data.md) #### Code Example We will use the following PHP files in our example: - The `custom-inner-block-blocks-integration.php` file: Enqueue scripts, styles, and data on the frontend when the Checkout blocks is being used. See more details in the [IntegrationInterface](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/checkout-block/integration-interface.md) documentation. ```php use Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface; /** * Class for integrating with WooCommerce Blocks */ class Custom_Inner_Block_Blocks_Integration implements IntegrationInterface { /** * The name of the integration. * * @return string */ public function get_name() { return 'new-field-block'; } /** * When called invokes any initialization/setup for the integration. */ public function initialize() { // ... Some code here: (e.g. init functions that registers scripts and styles, and other instructions) } // ... Other functions here } ``` - The `custom-inner-block-extend-store-endpoint.php` file: extends the [Store API](https://github.com/woocommerce/woocommerce-blocks/tree/trunk/src/StoreApi) and adds hooks to save and display your new field block instructions. This doesn't save the data from the custom block anywhere by default, but you can add your own logic to save the data to the database. ```php use Automattic\WooCommerce\Blocks\Package; use Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartSchema; use Automattic\WooCommerce\Blocks\StoreApi\Schemas\CheckoutSchema; /** * Your New Field Block Extend Store API. */ class Custom_Inner_Block_Extend_Store_Endpoint { /** * Stores Rest Extending instance. * * @var ExtendRestApi */ private static $extend; /** * Plugin Identifier, unique to each plugin. * * @var string */ const IDENTIFIER = 'new-field-block'; /** * Bootstraps the class and hooks required data. * */ public static function init() { self::$extend = Automattic\WooCommerce\StoreApi\StoreApi::container()->get( Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::class ); self::extend_store(); } /** * Registers the actual data into each endpoint. */ public static function extend_store() { if ( is_callable( [ self::$extend, 'register_endpoint_data' ] ) ) { self::$extend->register_endpoint_data( [ 'endpoint' => CheckoutSchema::IDENTIFIER, 'namespace' => self::IDENTIFIER, 'schema_callback' => [ 'Custom_Inner_Block_Extend_Store_Endpoint', 'extend_checkout_schema' ], 'schema_type' => ARRAY_A, ] ); } } /** * Register the new field block schema into the Checkout endpoint. * * @return array Registered schema. * */ public static function extend_checkout_schema() { return [ 'Value_1' => [ 'description' => 'A description of the field', 'type' => 'string', // ... type of the field, this should be a string 'context' => [ 'view', 'edit' ], // ... context of the field, this should be an array containing 'view' and 'edit' 'readonly' => true, // ... whether the field is readonly or not, this should be a boolean 'optional' => true, // ... whether the field is optional or not, this should be a boolean ], // ... other values ]; } } ``` - The `new-field-block.php` file: the main plugin file that loads the `custom-inner-block-blocks-integration.php` and `custom-inner-block-extend-store-endpoint.php` files. ```php register( new Custom_Inner_Block_Blocks_Integration() ); } ); } ); // ... Some code here ``` Here is an example from our [tutorial](https://developer.woocommerce.com/2023/08/07/extending-the-woocommerce-checkout-block-to-add-custom-shipping-options/) of how to get this custom field's data while processing the checkout. This example is from the `shipping-workshop-blocks-integration.php` file. The complete code can be found in this [GitHub repository](https://github.com/woocommerce/wceu23-shipping-workshop-final/blob/main/shipping-workshop-blocks-integration.php#L42-L83). ```php private function save_shipping_instructions() { /** * We write a hook, using the `woocommerce_store_api_checkout_update_order_from_request` action * that will update the order metadata with the shipping-workshop alternate shipping instruction. * * The documentation for this hook is at: https://github.com/woocommerce/woocommerce-blocks/blob/b73fbcacb68cabfafd7c3e7557cf962483451dc1/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_store_api_checkout_update_order_from_request */ add_action( 'woocommerce_store_api_checkout_update_order_from_request', function( \WC_Order $order, \WP_REST_Request $request ) { $shipping_workshop_request_data = $request['extensions'][$this->get_name()]; $alternate_shipping_instruction = $shipping_workshop_request_data['alternateShippingInstruction']; $other_shipping_value = $shipping_workshop_request_data['otherShippingValue']; $order->update_meta_data( 'shipping_workshop_alternate_shipping_instruction', $alternate_shipping_instruction ); $order->save(); }, 10, 2 ); } ``` ## Conclusion By following the steps above, you can add and process new field blocks in the WooCommerce checkout block. For complete implementation and additional examples, refer to the provided [tutorial](https://developer.woocommerce.com/2023/08/07/extending-the-woocommerce-checkout-block-to-add-custom-shipping-options/) and the corresponding [GitHub repository](https://github.com/woocommerce/wceu23-shipping-workshop-final/). --- ## Exposing your data *Source: apis/store-api/extending-store-api/extend-store-api-add-data.md* # Exposing your data ## The problem You want to extend the Mini-Cart, Cart and Checkout blocks, but you want to use some custom data not available on Store API or the context. You don't want to create your own endpoints or Ajax actions. You want to piggyback on the existing StoreAPI calls. ## Solution ExtendSchema offers the possibility to add contextual custom data to Store API endpoints, like `wc/store/cart` and `wc/store/cart/items` endpoints. That data is namespaced to your plugin and protected from other plugins causing it to malfunction. The data is available on all frontend filters and slotFills for you to consume. ## Basic usage You can use ExtendSchema by registering a couple of functions, `schema_callback` and `data_callback` on a specific endpoint namespace. ExtendSchema will call them at execution time and will pass them relevant data as well. This example below uses the Cart endpoint, [see passed parameters.](./available-endpoints-to-extend.md) **Note: Make sure to read the "Things to consider" section below.** ```php use Automattic\WooCommerce\StoreApi\Schemas\V1\CartSchema; add_action('woocommerce_blocks_loaded', function() { woocommerce_store_api_register_endpoint_data( array( 'endpoint' => CartSchema::IDENTIFIER, 'namespace' => 'plugin_namespace', 'data_callback' => 'my_data_callback', 'schema_callback' => 'my_schema_callback', 'schema_type' => ARRAY_A, ) ); }); function my_data_callback() { return [ 'custom-key' => 'custom-value', ]; } function my_schema_callback() { return [ 'custom-key' => [ 'description' => __( 'My custom data', 'plugin-namespace' ), 'type' => 'string', 'readonly' => true, ] ]; } ``` Data callback and Schema callback can also receive parameters: ```php function my_cart_item_callback( $cart_item ) { $product = $cart_item['data']; if ( is_my_custom_product_type( $product ) ) { $custom_value = get_custom_value( $product ); return [ 'custom-key' => $custom_value, ]; } } ``` ## Things To Consider ### ExtendSchema is a shared instance The ExtendSchema is stored as a shared instance between the API and consumers (third-party developers). So you shouldn't initiate the class yourself with `new ExtendSchema` because it would not work. Instead, you should always use the shared instance from the StoreApi dependency injection container like this. ```php $extend = StoreApi::container()->get( ExtendSchema::class ); ``` Also note that the dependency injection container is not available until after the `woocommerce_blocks_loaded` action has been fired, so you should hook your file that action: ```php use Automattic\WooCommerce\StoreApi\StoreApi; use Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema; add_action( 'woocommerce_blocks_loaded', function() { $extend = StoreApi::container()->get( ExtendSchema::class ); // my logic. }); ``` Or use the global helper functions: - `woocommerce_store_api_register_endpoint_data( $args )` - `woocommerce_store_api_register_update_callback( $args )` - `woocommerce_store_api_register_payment_requirements( $args )` - `woocommerce_store_api_get_formatter( $name )` ### Errors and fatals are silence for non-admins If your callback functions `data_callback` and `schema_callback` throw an exception or an error, or you passed the incorrect type of parameter to `register_endpoint_data`; that error would be caught and logged into WooCommerce error logs. If the current user is a shop manager or an admin, and has WP_DEBUG enabled, the error would be surfaced to the frontend. ### Callbacks should always return an array To reduce the chances of breaking your client code or passing the wrong type, and also to keep a consistent REST API response, callbacks like `data_callback` and `schema_callback` should always return an array, even if it was empty. ## API Definition - `ExtendSchema::register_endpoint_data`: Used to register data to a custom endpoint. It takes an array of arguments: | Attribute | Type | Required | Description | | :---------------- | :------- | :----------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------- | | `endpoint` | string | Yes | The endpoint you're trying to extend. It is suggested that you use the `::IDENTIFIER` available on the route Schema class to avoid typos. | | `namespace` | string | Yes | Your plugin namespace, the data will be available under this namespace in the StoreAPI response. | | `data_callback` | callback | Yes | A callback that returns an array with your data. | | `schema_callback` | callback | Yes | A callback that returns the shape of your data. | | `schema_type` | string | No (default: `ARRAY_A` ) | The type of your data. If you're adding an object (key => values), it should be `ARRAY_A`. If you're adding a list of items, it should be `ARRAY_N`. | ## Putting it all together This is a complete example that shows how you can register contextual WooCommerce Subscriptions data in each cart item (simplified). This example uses [Formatters](./extend-store-api-formatters.md), utility classes that allow you to format values so that they are compatible with the StoreAPI. ```php get( ExtendSchema::class ); WC_Subscriptions_Extend_Store_Endpoint::init( $extend ); }); class WC_Subscriptions_Extend_Store_Endpoint { /** * Stores Rest Extending instance. * * @var ExtendSchema */ private static $extend; /** * Plugin Identifier, unique to each plugin. * * @var string */ const IDENTIFIER = 'subscriptions'; /** * Bootstraps the class and hooks required data. * * @param ExtendSchema $extend_rest_api An instance of the ExtendSchema class. * * @since 3.1.0 */ public static function init( ExtendSchema $extend_rest_api ) { self::$extend = $extend_rest_api; self::extend_store(); } /** * Registers the actual data into each endpoint. */ public static function extend_store() { // Register into `cart/items` self::$extend->register_endpoint_data( array( 'endpoint' => CartItemSchema::IDENTIFIER, 'namespace' => self::IDENTIFIER, 'data_callback' => array( 'WC_Subscriptions_Extend_Store_Endpoint', 'extend_cart_item_data' ), 'schema_callback' => array( 'WC_Subscriptions_Extend_Store_Endpoint', 'extend_cart_item_schema' ), 'schema_type' => ARRAY_A, ) ); } /** * Register subscription product data into cart/items endpoint. * * @param array $cart_item Current cart item data. * * @return array $item_data Registered data or empty array if condition is not satisfied. */ public static function extend_cart_item_data( $cart_item ) { $product = $cart_item['data']; $item_data = array( 'billing_period' => null, 'billing_interval' => null, 'subscription_length' => null, 'trial_length' => null, 'trial_period' => null, 'sign_up_fees' => null, 'sign_up_fees_tax' => null, ); if ( in_array( $product->get_type(), array( 'subscription', 'subscription_variation' ), true ) ) { $item_data = array_merge( array( 'billing_period' => WC_Subscriptions_Product::get_period( $product ), 'billing_interval' => (int) WC_Subscriptions_Product::get_interval( $product ), 'subscription_length' => (int) WC_Subscriptions_Product::get_length( $product ), 'trial_length' => (int) WC_Subscriptions_Product::get_trial_length( $product ), 'trial_period' => WC_Subscriptions_Product::get_trial_period( $product ), ), self::format_sign_up_fees( $product ) ); } return $item_data; } /** * Register subscription product schema into cart/items endpoint. * * @return array Registered schema. */ public static function extend_cart_item_schema() { return array( 'billing_period' => array( 'description' => __( 'Billing period for the subscription.', 'woocommerce-subscriptions' ), 'type' => array( 'string', 'null' ), 'enum' => array_keys( wcs_get_subscription_period_strings() ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'billing_interval' => array( 'description' => __( 'The number of billing periods between subscription renewals.', 'woocommerce-subscriptions' ), 'type' => array( 'integer', 'null' ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'subscription_length' => array( 'description' => __( 'Subscription Product length.', 'woocommerce-subscriptions' ), 'type' => array( 'integer', 'null' ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'trial_period' => array( 'description' => __( 'Subscription Product trial period.', 'woocommerce-subscriptions' ), 'type' => array( 'string', 'null' ), 'enum' => array_keys( wcs_get_subscription_period_strings() ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'trial_length' => array( 'description' => __( 'Subscription Product trial interval.', 'woocommerce-subscriptions' ), 'type' => array( 'integer', 'null' ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'sign_up_fees' => array( 'description' => __( 'Subscription Product signup fees.', 'woocommerce-subscriptions' ), 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), 'sign_up_fees_tax' => array( 'description' => __( 'Subscription Product signup fees taxes.', 'woocommerce-subscriptions' ), 'type' => array( 'string', 'null' ), 'context' => array( 'view', 'edit' ), 'readonly' => true, ), ); } /** * Format sign-up fees. * * @param \WC_Product $product current product. * @return array */ private static function format_sign_up_fees( $product ) { $fees_excluding_tax = wcs_get_price_excluding_tax( $product, array( 'qty' => 1, 'price' => WC_Subscriptions_Product::get_sign_up_fee( $product ), ) ); $fees_including_tax = wcs_get_price_including_tax( $product, array( 'qty' => 1, 'price' => WC_Subscriptions_Product::get_sign_up_fee( $product ), ) ); $money_formatter = self::$extend->get_formatter( 'money' ); return array( 'sign_up_fees' => $money_formatter->format( $fees_excluding_tax ), 'sign_up_fees_tax' => $money_formatter->format( $fees_including_tax - $fees_excluding_tax ), ); } } ``` ## Formatting your data You may wish to use our pre-existing Formatters to ensure your data is passed through the Store API in the correct format. More information on the Formatters can be found in the [StoreApi Formatters documentation](./extend-store-api-formatters.md). --- ## Available Formatters *Source: apis/store-api/extending-store-api/extend-store-api-formatters.md* # Available Formatters `Formatters` are utility classes that allow you to format values to so that they are compatible with the StoreAPI. Default formatters handle values such as monetary amounts, currency information, or HTML. It is recommended that you use these formatters when you are extending the StoreAPI. ## Why are formatters useful? Using the formatter utilities when returning certain types of data will ensure that your custom data is consistent and compatible with other endpoints. They also take care of any store specific settings that may affect the formatting of the data, such as currency settings. Store API includes formatters for: - [Money](#moneyformatter) - [Currency](#currencyformatter) - [HTML](#htmlformatter) ## How to use formatters To get a formatter, you can use the `get_formatter` method of the `ExtendSchema` class. This method accepts a string, which is the name of the formatter you want to use. ```php get_formatter('money'); // For the MoneyFormatter get_formatter('html'); // For the HtmlFormatter get_formatter('currency'); // CurrencyFormatter ``` This returns a `FormatterInterface` which has the `format` method. The `format` method signature is: ```php format( $value, array $options = [] ); ``` Only `MoneyFormatter`'s behavior can be controlled by the `$options` parameter. This parameter is optional. ### Real world example Let's say we're going to be returning some extra price data via the API. We want to return the price in cents, and also the currency data for the store. We can use the `MoneyFormatter` and `CurrencyFormatter` to do this. First we need to ensure we can access the formatter classes. We can do this by using the `use` keyword: ```php use Automattic\WooCommerce\StoreApi\StoreApi; use Automattic\WooCommerce\StoreApi\Utilities\ExtendSchema; $extend = StoreApi::container()->get( ExtendSchema::class ); $my_custom_price = $extend->get_formatter( 'money' )->format( '10.00', [ 'rounding_mode' => PHP_ROUND_HALF_DOWN, 'decimals' => 2 ] ); $price_response = $extend->get_formatter( 'currency' )->format( [ 'price' => $my_custom_price, ] ); ``` The above code would result in `$price_response` being set to: ```text [ 'price' => '1000' 'currency_code' => 'GBP' 'currency_symbol' => '£' 'currency_minor_unit' => 2 'currency_decimal_separator' => '.' 'currency_thousand_separator' => ',' 'currency_prefix' => '£' 'currency_suffix' => '' ] ``` ## MoneyFormatter The [`MoneyFormatter`](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/StoreApi/Formatters/MoneyFormatter.php) class can be used to format a monetary value using the store settings. The store settings may be overridden by passing options to this formatter's `format` method. Values are returned in cents to avoid floating point rounding errors, so when using this formatter you'll most likely also be returning the currency data using the [`CurrencyFormatter`](#currencyformatter) alongside it. This will allow the consumer of the API to display the value in the intended format. ### Arguments | Argument | Type | Description | | --------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `$value` | `number` | The number you want to format into a monetary value | | `$options` | `array` | Should contain two keys, `decimals` which should be an `integer`, | | `$options['decimals']` | `number` | Used to control how many decimal places should be displayed in the monetary value. Defaults to the store setting. | | `$options['rounding_mode']` | `number` | Used to determine how to round the monetary value. This should be one of the PHP rounding modes described in the [PHP round() documentation](https://www.php.net/manual/en/function.round.php). Defaults to `PHP_ROUND_HALF_UP`. | ### Example use and returned value ```php get_formatter( 'money' )->format( 10.443, [ 'rounding_mode' => PHP_ROUND_HALF_DOWN, 'decimals' => 2 ] ); ``` returns `1044` ## CurrencyFormatter This formatter takes an array of prices, and returns the same array but with currency data appended to it. The currency data added is: | Key | Type | Description | | ----------------------------- | -------- | ------------------------------------------------------------------------------------------------- | | `currency_code` | `string` | The string representation of the currency, e.g. GBP or USD | | `currency_symbol` | `string` | The symbol of the currency, e.g. £ or \$ | | `currency_minor_unit` | `number` | How many decimal places will be shown in the currency | | `currency_decimal_separator` | `string` | The string used to separate the whole value and the decimal value in the currency. | | `currency_thousand_separator` | `string` | The string used to separate thousands in the currency, for example: £10,000 or €10.000 | | `currency_prefix` | `string` | A string that should appear before the currency value. | | `currency_suffix` | `string` | A string that should appear after the currency value. | This data can then be used by the client/consumer to format prices correctly according to store settings. Important: the array of prices passed to this formatted should already be in monetary format so you should use the [`MoneyFormatter`](#moneyformatter) first. ### Arguments | Argument | Type | Description | | -------- | ---------- | ---------------------------------------------------------------------------- | | `$value` | `number[]` | An array of prices that you want to merge with the store's currency settings | ### Example use and returned value ```php get_formatter( 'currency' )->format( [ 'price' => 1800, 'regular_price' => 1800, 'sale_price' => 1800, ] ); ``` returns ```text 'price' => '1800' 'regular_price' => '1800' 'sale_price' => '1800' 'price_range' => null 'currency_code' => 'GBP' 'currency_symbol' => '£' 'currency_minor_unit' => 2 'currency_decimal_separator' => '.' 'currency_thousand_separator' => ',' 'currency_prefix' => '£' 'currency_suffix' => '' ``` ## HtmlFormatter This formatter will take an HTML value, run it through: [`wptexturize`](https://developer.wordpress.org/reference/functions/wptexturize/), [`convert_chars`](https://developer.wordpress.org/reference/functions/convert_chars/), [`trim`](https://www.php.net/manual/en/function.trim.php), and [`wp_kses_post`](https://developer.wordpress.org/reference/functions/wp_kses_post/) before returning it. The purpose of this formatter is to make HTML "safe" (in terms of correctly formatted characters). `wp_kses_post` will ensure only HTML tags allowed in the context of a `post` are present in the string. ### Arguments | Argument | Type | Description | | -------- | -------- | ----------------------------------------------- | | `$value` | `string` | The string you want to format into "safe" HTML. | ### Example use and returned value ```php get_formatter( 'html' )->format( " This \"coffee\" is very strong." ); ``` returns: ```text alert('bad script!') This “coffee” is very strong. ``` This formatter should be used when returning HTML from the StoreAPI regardless of whether the HTML is user generated or not. This will ensure the consumer/client can display the HTML safely and without encoding issues. --- ## Updating the cart on-demand *Source: apis/store-api/extending-store-api/extend-store-api-update-cart.md* # Updating the cart on-demand ## The problem You're an extension developer, and your extension does some server-side processing as a result of some client-side input, i.e. a shopper filling in an input field in the Cart sidebar, and then pressing a button. This server-side processing causes the state of the cart to change, and you want to update the data displayed in the client-side Cart or Checkout block. You can't simply update the client-side cart state yourself. This is restricted to prevent malfunctioning extensions inadvertently updating it with malformed or invalid data which will cause the whole block to break. ## The solution `ExtendSchema` offers the ability for extensions to register callback functions to be executed when signalled to do so by the client-side Cart or Checkout. WooCommerce Blocks also provides a front-end function called `extensionCartUpdate` which can be called by client-side code, this will send data (specified by you when calling `extensionCartUpdate`) to the `cart/extensions` endpoint. When this endpoint gets hit, any relevant (based on the namespace provided to `extensionCartUpdate`) callbacks get executed, and the latest server-side cart data gets returned and the block is updated with this new data. ## Basic usage In your extension's server-side integration code: ```php add_action('woocommerce_blocks_loaded', function() { woocommerce_store_api_register_update_callback( [ 'namespace' => 'extension-unique-namespace', 'callback' => /* Add your callable here */ ] ); } ); ``` and on the client side: ```ts const { extensionCartUpdate } = wc.blocksCheckout; const { processErrorResponse } = wc.wcBlocksData; extensionCartUpdate( { namespace: 'extension-unique-namespace', data: { key: 'value', another_key: 100, third_key: { fourth_key: true, }, }, } ).then( () => { // Cart has been updated. } ).catch( ( error ) => { // Handle error. processErrorResponse(error); } ); ``` ## Things to consider ### Extensions cannot update the client-side cart state themselves You may be wondering why it's not possible to just make a custom AJAX endpoint for your extension that will update the cart. As mentioned, extensions are not permitted to update the client-side cart's state, because doing this incorrectly would cause the entire block to break, preventing the user from continuing their checkout. Instead you _must_ do this through the `extensionCartUpdate` function. ### Only one callback for a given namespace may be registered With this in mind, if your extension has several client-side interactions that result in different code paths being executed on the server-side, you may wish to pass additional data through in `extensionCartUpdate`. For example if you have two actions the user can take, one to _add_ a discount, and the other to _remove_ it, you may wish to pass a key called `action` along with the other data to `extensionCartUpdate`. Then in your callback, you can check this value to distinguish which code path you should execute. Example: ```php 'extension-unique-namespace', 'callback' => function( $data ) { if ( $data['action'] === 'add' ) { add_discount( ); } if ( $data['action'] === 'remove' ) { remove_discount(); } } ] ); } ); ``` If you try to register again, under the same namespace, the previously registered callback will be overwritten. ## API Definition ### PHP `ExtendSchema::register_update_callback`: Used to register a callback to be executed when the `cart/extensions` endpoint gets hit with a given namespace. It takes an array of arguments | Attribute | Type | Required | Description | | ----------- | ---------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `namespace` | `string` | Yes | The namespace of your extension. This is used to determine which extension's callbacks should be executed. | | `callback` | `Callable` | Yes | The function/method (or Callable) that will be executed when the `cart/extensions` endpoint is hit with a `namespace` that matches the one supplied. The callable should take a single argument. The data passed into the callback via this argument will be an array containing whatever data you choose to pass to it. The callable does not need to return anything, if it does, then its return value will not be used. | ### JavaScript `extensionCartUpdate`: Used to signal that you want your registered callback to be executed, and to pass data to the callback. It takes an object as its only argument. | Attribute | Type | Required | Description | | ----------- |-----------|----------| ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `namespace` | `string` | Yes | The namespace of your extension. This is used to determine which extension's callbacks should be executed. | | `data` | `Object` | No | The data you want to pass to your callback. Anything in the `data` key will be passed as the first (and only) argument to your callback as an associative array. | | `overwriteDirtyCustomerData` | `boolean` | No | Whether to overwrite the customer data in the client with the data returned from the server, even if it is dirty (i.e. it hasn't been pushed to the server yet). | ## Putting it all together You are the author of an extension that lets the shopper redeem points that they earn on your website for a discount on their order. There is a text field where the shopper can enter how many points they want to redeem, and a submit button that will apply the redemption. Your extension adds these UI elements to the sidebar in the Cart and Checkout blocks using the [`DiscountsMeta`](/docs/block-development/extensible-blocks/cart-and-checkout-blocks/available-slot-fills/) Slot. More information on how to use Slots is available in our [Slots and Fills documentation](/docs/block-development/reference/slot-fills/). Once implemented, the sidebar has a control added to it like this: ![image](https://user-images.githubusercontent.com/5656702/125109827-bf7c8300-e0db-11eb-9e51-59921b38a0c2.png) ### The "Redeem" button In your UI, you are tracking the value the shopper enters into the `Enter amount` box using a React `useState` variable. The variable in this example shall be called `pointsInputValue`. When the `Redeem` button gets clicked, you want to tell the server how many points to apply to the shopper's basket, based on what they entered into the box, apply the relevant discount, update the server-side cart, and then show the updated price in the client-side sidebar. To do this, you will need to use `extensionCartUpdate` to tell the server you want to execute your callback, and have the new cart state loaded into the UI. The `onClick` handler of the button may look like this: ```js const { extensionCartUpdate } = window.wc.blocksCheckout; const buttonClickHandler = () => { extensionCartUpdate( { namespace: 'super-coupons', data: { pointsInputValue, }, } ); }; ``` ### Registering a callback to run when the `cart/extensions` endpoint is hit So far, we haven't registered a callback with WooCommerce Blocks yet, so when `extensionCartUpdate` causes the `cart/extensions` endpoint to get hit, nothing will happen. Much like adding data to the Store API (described in more detail in [Exposing your data in the Store API](./extend-store-api-add-data.md).) we can add the callback by invoking the `register_update_callback` method on the `ExtendSchema` class from WooCommerce Blocks. We have written a function called `redeem_points` which applies a discount to the WooCommerce cart. This function does not return anything. Note, the actual implementation of this function is not the focus of this document, so has been omitted. All that is important to note is that it modifies the WooCommerce cart. ```php 'super-coupons', 'callback' => function( $data ) { redeem_points( $data['points'] ); }, ] ); } ); ``` Now that this is registered, when the button is pressed, the `cart/extensions` endpoint is hit, with a `namespace` of `super-coupons` our `redeem_points` function will be executed. After this has finished processing, the client-side cart will be updated by WooCommerce Blocks. --- ## Store API Guiding principles *Source: apis/store-api/guiding-principles.md* # Store API Guiding principles The following principles should be considered when extending, creating, or updating endpoints in the Store API. ## Routes must include a [well-defined JSON schema](https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/) Each route/endpoint requires a particular structure of input data and should return data using a defined and predictable structure. This is defined in the JSON schema, which contains a comprehensive list of all of the properties the API can return and which input parameters it can accept. Well-defined schema also provides a layer of security, as it enables us to validate and sanitize the requests being made to the API. When defining schema, take note of the [WordPress REST API handbook](https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/) which documents available properties and types, as well as the [JSON schema standard](http://json-schema.org/). In addition to this: * Properties should use snake_case 🐍 * Ambiguous terms should be avoided, and property names should try to use understandable language, rather than "WooCommerce" terminology or setting names * Properties should be defined using US English, but the descriptions of fields should be localized * Multiple types are permitted, for example, using a `null` type if a value is not applicable * `sanitize_callback` and `validate_callback` are encouraged where possible to ensure data is received in the correct format before processing requests If you’re struggling to define a consistent schema, your approach may be flawed. A common real-world example of this would be representing something like _Post Tags_. It may be tempting to use the Slug as the property field name in the response: ```php tags: [ "my-tag": { // ...tag data }, "my-other-tag": { // ...tag data } ] ``` However, this is difficult to represent in Schema and is not predictable for the client. A better approach would be to use an array of data, with one of the properties being the Slug: ```php tags: [ { "slug": "my-tag", // ...tag data }, { "slug": "my-other-tag", // ...tag data } ] ``` ## Routes should be designed around resources with a single type of schema Routes should be designed around resources (nouns) rather than operations (verbs). Routes should also return only one type of data defined by their Schema. For example: | Route | Resource type | Expected data | | ------------------------ | ------------- | --------------------------- | | `wc/store/v1/cart` | Cart | A cart object | | `wc/store/v1/cart/items` | Cart Item | A list of cart item objects | | `wc/store/v1/products` | Product | A list of product objects | | `wc/store/v1/products/1` | Product | A product object | There are 2 notable exceptions to this rule in the Store API; _Errors_ and _Cart Operations_. ### Error Handling Errors, including validation errors, should return an error response code (4xx or 5xx) and a [`WP_Error` object](https://developer.wordpress.org/reference/classes/wp_error/). The `AbstractRoute` class will handle the conversion of the `WP_Error` object into a valid JSON response. Error messages should be localized, but do not need to be written with language aimed at customers (clients should use the given error code to create customer-facing notices as needed). Error codes should have the prefix `woocommerce_rest_`. ### Cart Operations Some endpoints are designed around operations to avoid clients needing to make multiple round trips to the API. This is purely for convenience. An example would be the `wc/store/v1/cart/add-item` endpoint which accepts a quantity and product ID, but returns a full cart object, rather than just an updated list of items. ## Exposed data must belong to the current user or be non-sensitive Resources, including customer and order data, should reflect only the current session. Do not return data for other customers as this would be a breach of privacy and security issue. Store data such as settings (for example, store currency) is permitted in responses, but _private or sensitive data_ must be avoided. To allow more extensive access to data, you must use the authenticated [WC REST API](/docs/apis/rest-api/). Data returned from the API should not be [escaped](https://developer.wordpress.org/themes/theme-security/data-sanitization-escaping/) (this is left to the client rendering it), but it should be sanitized. For example, HTML should be run through [`wp_kses_post`](https://developer.wordpress.org/reference/functions/wp_kses_post/). It is the client’s responsibility to properly escape data that comes from the API, but we should try to avoid returning data that is potentially unsafe. ## Collections of resources should be paginated Large volumes of data should be paginated to avoid overwhelming the server. For example, returning a collection of products. * Use the response Headers `X-WP-Total`, `X-WP-TotalPages`, and Link to indicate available resources. * Use parameters `page` and `per_page` to retrieve certain pages. * The maximum allowed value for `per_page` is 100. ## API Responses should use standard HTTP status codes When returning content, use a valid HTTP response code such as: * `200 OK` for successful responses (this is the default response code). * `201 Created` when creating a resource, for example, adding a new cart item or applying a new coupon. * `204 No Content` for successful deletes. * `400 Bad Request` when a required parameter is not set. * `403 Forbidden` when a request is not allowed, for example, if the provided security nonce is invalid. * `404 Not Found` if a resource does not exist. * `409 Conflict` if a resource cannot be updated, for example, if something in the cart is invalid and removed during the request. A note on `DELETE` requests, a common pattern in the WordPress REST API is to return the deleted object. In the case of the Store API, we opt to return an empty response with status code `204 No Content` instead. This is more efficient. [A full list of HTTP status codes can be found here.](https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml) ## Breaking changes should be avoided where possible The Store API establishes a contract between itself and API consumers via the use of Schema. This contract should not be broken unless absolutely necessary. If a breaking change were necessary, a new version of the Store API would need to be released. A breaking change is anything that changes the format of existing Schema, removes a Schema property, removes an existing route, or makes a backwards-incompatible change to anything public that may already be in use by consumers. Breaking changes can be avoided by [deprecating existing properties](http://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9.3) rather than removing them, or [deprecating routes](https://datatracker.ietf.org/doc/html/rfc8594) and replacing them with a different route if major changes are needed. Non-breaking changes are always permitted without the need to increase the API version. Some examples of these include: * Adding new properties to schema * Adding new routes, endpoints, methods * Adding optional request parameters * Re-ordering response fields The version will not increase for bug fixes unless the scope of the bug causes a backwards-incompatible change. Fixes would not be rolled back to past API versions with the exception of security issues that require backporting. --- ## Nonce Tokens *Source: apis/store-api/nonce-tokens.md* # Nonce Tokens Nonces are generated numbers used to verify origin and intent of requests for security purposes. You can read more about [nonces in the WordPress codex](https://developer.wordpress.org/apis/security/nonces/). ## Store API Endpoints that Require Nonces POST requests to the `/cart` endpoints and all requests to the `/checkout` endpoints require a nonce to function. Failure to provide a valid nonce will return an error response, unless you're using [Cart Tokens](/docs/apis/store-api/cart-tokens) instead. ## Sending Nonce Tokens with requests Nonce tokens are included with the request headers. Create a request header named `Nonce`. This will be validated by the API. **Example:** ```sh curl --header "Nonce: 12345" --request GET https://example-store.com/wp-json/wc/store/v1/checkout ``` After making a successful request, an updated `Nonce` header will be sent back--this needs to be stored and updated by the client to make subsequent requests. ## Generating security nonces from WordPress Nonces must be created using the [`wp_create_nonce` function](https://developer.wordpress.org/reference/functions/wp_create_nonce/) with the key `wc_store_api`. ```php wp_create_nonce( 'wc_store_api' ) ``` There is no other mechanism in place for creating nonces. ## Disabling Nonces for Development If you want to test REST endpoints without providing a nonce, you can use the following filter: ```php add_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' ); ``` Nonce checks will be bypassed if `woocommerce_store_api_disable_nonce_check` evaluates to `true`. NOTE: This should only be done on development sites where security is not important. Do not enable this in production. --- ## Rate Limiting for Store API endpoints *Source: apis/store-api/rate-limiting.md* # Rate Limiting for Store API endpoints [Rate Limiting](https://github.com/woocommerce/woocommerce-blocks/pull/5962) is available for Store API endpoints. This is optional and disabled by default. It can be enabled by following [these instructions](#rate-limiting-options-filter). The main purpose prevent abuse on endpoints from excessive calls and performance degradation on the machine running the store. Rate limit tracking is controlled by either `USER ID` (logged in), `IP ADDRESS` (unauthenticated requests) or filter defined logic to fingerprint and group requests. It also offers standard support for running behind a proxy, load balancer, etc. This also optional and disabled by default. ## UI Control Currently, this feature is only controlled via the `woocommerce_store_api_rate_limit_options` filter. To control it via a UI, you can use the following community plugin: [Rate Limiting UI for WooCommerce](https://wordpress.org/plugins/rate-limiting-ui-for-woocommerce/). ## Checkout rate limiting You can enable rate limiting for Checkout place order and `POST /checkout` endpoint only via the UI by going to WooCommerce -> Settings -> Advanced -> Features and enabling "Rate limiting Checkout block and Store API". When enabled via the UI, the rate limiting will only be applied to the `POST /checkout` and Place Order flow for Checkout block. The limit will be a maximum of 3 requests per 60 seconds. ## Limit information A default maximum of 25 requests can be made within a 10-second time frame. These can be changed through an [options filter](#rate-limiting-options-filter). ## Methods restricted by Rate Limiting Only `POST` requests are rate limited. Requests using the `X-HTTP-Method-Override` header (such as `PUT`, `PATCH` requests sent via `wp.apiFetch`) are excluded from rate limiting. ## Rate Limiting options filter A filter is available for setting options for rate limiting: ```php add_filter( 'woocommerce_store_api_rate_limit_options', function() { return [ 'enabled' => false, // enables/disables Rate Limiting. Default: false 'proxy_support' => false, // enables/disables Proxy support. Default: false 'limit' => 25, // limit of request per timeframe. Default: 25 'seconds' => 10, // timeframe in seconds. Default: 10 ]; } ); ``` ## Proxy standard support If the Store is running behind a proxy, load balancer, cache service, CDNs, etc. keying limits by IP is supported through standard IP forwarding headers, namely: * `X_REAL_IP`|`CLIENT_IP` _Custom popular implementations that simplify obtaining the origin IP for the request_ * `X_FORWARDED_FOR` _De-facto standard header for identifying the originating IP, [Documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For)_ * `X_FORWARDED` _[Documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded), [RFC 7239](https://datatracker.ietf.org/doc/html/rfc7239)_ This is disabled by default. ## Enable Rate Limit by request custom fingerprinting For more advanced use cases, you can enable rate limiting by custom fingerprinting. This allows for a custom implementation to group requests without relying on logged-in User ID or IP Address. ### Custom basic example for grouping requests by User-Agent and Accept-Language combination ```php add_filter( 'woocommerce_store_api_rate_limit_id', function() { $accept_language = isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) : ''; return md5( wc_get_user_agent() . $accept_language ); } ); ``` ## Limit usage information observability Current limit information can be observed via custom response headers: * `RateLimit-Limit` _Maximum requests per time frame._ * `RateLimit-Remaining` _Requests available during current time frame._ * `RateLimit-Reset` _Unix timestamp of next time frame reset._ * `RateLimit-Retry-After` _Seconds until requests are unblocked again. Only shown when the limit is reached._ ### Response headers example ```http RateLimit-Limit: 5 RateLimit-Remaining: 0 RateLimit-Reset: 1654880642 RateLimit-Retry-After: 28 ``` ## Tracking limit abuses This uses a modified wc_rate_limit table with an additional remaining column for tracking the request count in any given request window. A custom action `woocommerce_store_api_rate_limit_exceeded` was implemented for extendability in tracking such abuses. ### Custom tracking usage example ```php add_action( 'woocommerce_store_api_rate_limit_exceeded', function ( $offending_ip, $action_id ) { /* Custom tracking implementation */ } ); ``` --- ## Cart Coupons API *Source: apis/store-api/resources-endpoints/cart-coupons.md* # Cart Coupons API ## List Cart Coupons ```http GET /cart/coupons ``` There are no parameters required for this endpoint. ```sh curl "https://example-store.com/wp-json/wc/store/v1/cart/coupons" ``` **Example response:** ```json [ { "code": "20off", "type": "fixed_cart", "totals": { "currency_code": "GBP", "currency_symbol": "£", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "£", "currency_suffix": "", "total_discount": "1667", "total_discount_tax": "333" }, "_links": { "self": [ { "href": "http://local.wordpress.test/wp-json/wc/store/v1/cart/coupons/20off" } ], "collection": [ { "href": "http://local.wordpress.test/wp-json/wc/store/v1/cart/coupons" } ] } } ] ``` ## Single Cart Coupon Get a single cart coupon. ```http GET /cart/coupons/:code ``` | Attribute | Type | Required | Description | | :-------- | :----- | :------: | :---------------------------------------------- | | `code` | string | Yes | The coupon code of the cart coupon to retrieve. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/cart/coupons/20off" ``` **Example response:** ```json { "code": "halfprice", "type": "percent", "totals": { "currency_code": "GBP", "currency_symbol": "£", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "£", "currency_suffix": "", "total_discount": "9950", "total_discount_tax": "0" } } ``` ## Add Cart Coupon Apply a coupon to the cart. Returns the new coupon object that was applied, or an error if it was not applied. ```http POST /cart/coupons/ ``` | Attribute | Type | Required | Description | | :-------- | :----- | :------: | :--------------------------------------------- | | `code` | string | Yes | The coupon code you wish to apply to the cart. | ```sh curl --request POST https://example-store.com/wp-json/wc/store/v1/cart/coupons?code=20off ``` **Example response:** ```json { "code": "20off", "type": "percent", "totals": { "currency_code": "GBP", "currency_symbol": "£", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "£", "currency_suffix": "", "total_discount": "1667", "total_discount_tax": "333" } } ``` ## Delete Single Cart Coupon Delete/remove a coupon from the cart. ```http DELETE /cart/coupons/:code ``` | Attribute | Type | Required | Description | | :-------- | :----- | :------: | :------------------------------------------------ | | `code` | string | Yes | The coupon code you wish to remove from the cart. | ```sh curl --request DELETE https://example-store.com/wp-json/wc/store/v1/cart/coupons/20off ``` ## Delete All Cart Coupons Delete/remove all coupons from the cart. ```http DELETE /cart/coupons/ ``` There are no parameters required for this endpoint. ```sh curl --request DELETE https://example-store.com/wp-json/wc/store/v1/cart/coupons ``` **Example response:** ```json [] ``` --- ## Cart Items API *Source: apis/store-api/resources-endpoints/cart-items.md* # Cart Items API ## List Cart Items ```http GET /cart/items ``` There are no extra parameters needed to use this endpoint. ```sh curl "https://example-store.com/wp-json/wc/store/v1/cart/items" ``` **Example response:** ```json [ { "key": "c74d97b01eae257e44aa9d5bade97baf", "id": 16, "quantity": 1, "type": "simple", "quantity_limits": { "minimum": 1, "maximum": 1, "multiple_of": 1, "editable": false }, "name": "Beanie", "short_description": "

This is a simple product.

", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

", "sku": "woo-beanie", "low_stock_remaining": null, "backorders_allowed": false, "show_backorder_badge": false, "sold_individually": true, "permalink": "https://store.local/product/beanie/", "images": [ { "id": 45, "src": "https://store.local/wp-content/uploads/2023/01/beanie-2.jpg", "thumbnail": "https://store.local/wp-content/uploads/2023/01/beanie-2-450x450.jpg", "srcset": "https://store.local/wp-content/uploads/2023/01/beanie-2.jpg 801w, https://store.local/wp-content/uploads/2023/01/beanie-2-450x450.jpg 450w, https://store.local/wp-content/uploads/2023/01/beanie-2-100x100.jpg 100w, https://store.local/wp-content/uploads/2023/01/beanie-2-600x600.jpg 600w, https://store.local/wp-content/uploads/2023/01/beanie-2-300x300.jpg 300w, https://store.local/wp-content/uploads/2023/01/beanie-2-150x150.jpg 150w, https://store.local/wp-content/uploads/2023/01/beanie-2-768x768.jpg 768w", "sizes": "(max-width: 801px) 100vw, 801px", "name": "beanie-2.jpg", "alt": "" } ], "variation": [], "item_data": [], "prices": { "price": "1800", "regular_price": "2000", "sale_price": "1800", "price_range": null, "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "", "raw_prices": { "precision": 6, "price": "18000000", "regular_price": "20000000", "sale_price": "18000000" } }, "totals": { "line_subtotal": "1800", "line_subtotal_tax": "360", "line_total": "1800", "line_total_tax": "360", "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "" }, "catalog_visibility": "visible", "extensions": {}, "_links": { "self": [ { "href": "https://store.local/wp-json/wc/store/v1/cart/items/c74d97b01eae257e44aa9d5bade97baf" } ], "collection": [ { "href": "https://store.local/wp-json/wc/store/v1/cart/items" } ] } }, { "key": "e03e407f41901484125496b5ec69a76f", "id": 29, "quantity": 1, "type": "variation", "quantity_limits": { "minimum": 1, "maximum": 9999, "multiple_of": 1, "editable": true }, "name": "Hoodie", "short_description": "", "description": "

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum sagittis orci ac odio dictum tincidunt. Donec ut metus leo. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed luctus, dui eu sagittis sodales, nulla nibh sagittis augue, vel porttitor diam enim non metus. Vestibulum aliquam augue neque. Phasellus tincidunt odio eget ullamcorper efficitur. Cras placerat ut turpis pellentesque vulputate. Nam sed consequat tortor. Curabitur finibus sapien dolor. Ut eleifend tellus nec erat pulvinar dignissim. Nam non arcu purus. Vivamus et massa massa.

", "sku": "woo-hoodie-red", "low_stock_remaining": null, "backorders_allowed": false, "show_backorder_badge": false, "sold_individually": false, "permalink": "https://store.local/product/hoodie/?attribute_pa_color=red&attribute_logo=No", "images": [ { "id": 40, "src": "https://store.local/wp-content/uploads/2023/01/hoodie-2.jpg", "thumbnail": "https://store.local/wp-content/uploads/2023/01/hoodie-2-450x450.jpg", "srcset": "https://store.local/wp-content/uploads/2023/01/hoodie-2.jpg 801w, https://store.local/wp-content/uploads/2023/01/hoodie-2-450x450.jpg 450w, https://store.local/wp-content/uploads/2023/01/hoodie-2-100x100.jpg 100w, https://store.local/wp-content/uploads/2023/01/hoodie-2-600x600.jpg 600w, https://store.local/wp-content/uploads/2023/01/hoodie-2-300x300.jpg 300w, https://store.local/wp-content/uploads/2023/01/hoodie-2-150x150.jpg 150w, https://store.local/wp-content/uploads/2023/01/hoodie-2-768x768.jpg 768w", "sizes": "(max-width: 801px) 100vw, 801px", "name": "hoodie-2.jpg", "alt": "" } ], "variation": [ { "raw_attribute": "attribute_pa_color", "attribute": "Color", "value": "Red" }, { "raw_attribute": "attribute_logo", "attribute": "Logo", "value": "No" } ], "item_data": [], "prices": { "price": "4200", "regular_price": "4500", "sale_price": "4200", "price_range": null, "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "", "raw_prices": { "precision": 6, "price": "42000000", "regular_price": "45000000", "sale_price": "42000000" } }, "totals": { "line_subtotal": "4200", "line_subtotal_tax": "840", "line_total": "4200", "line_total_tax": "840", "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "" }, "catalog_visibility": "visible", "extensions": {}, "_links": { "self": [ { "href": "https://store.local/wp-json/wc/store/v1/cart/items/e03e407f41901484125496b5ec69a76f" } ], "collection": [ { "href": "https://store.local/wp-json/wc/store/v1/cart/items" } ] } } ] ``` ## Single Cart Item Get a single cart item by its key. ```http GET /cart/items/:key ``` | Attribute | Type | Required | Description | | :-------- | :----- | :------: | :------------------------------------ | | `key` | string | Yes | The key of the cart item to retrieve. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/cart/items/c74d97b01eae257e44aa9d5bade97baf" ``` **Example response:** ```json { "key": "c74d97b01eae257e44aa9d5bade97baf", "id": 16, "quantity": 1, "quantity_limits": { "minimum": 1, "maximum": 1, "multiple_of": 1, "editable": false }, "name": "Beanie", "short_description": "

This is a simple product.

", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

", "sku": "woo-beanie", "low_stock_remaining": null, "backorders_allowed": false, "show_backorder_badge": false, "sold_individually": true, "permalink": "https://store.local/product/beanie/", "images": [ { "id": 45, "src": "https://store.local/wp-content/uploads/2023/01/beanie-2.jpg", "thumbnail": "https://store.local/wp-content/uploads/2023/01/beanie-2-450x450.jpg", "srcset": "https://store.local/wp-content/uploads/2023/01/beanie-2.jpg 801w, https://store.local/wp-content/uploads/2023/01/beanie-2-450x450.jpg 450w, https://store.local/wp-content/uploads/2023/01/beanie-2-100x100.jpg 100w, https://store.local/wp-content/uploads/2023/01/beanie-2-600x600.jpg 600w, https://store.local/wp-content/uploads/2023/01/beanie-2-300x300.jpg 300w, https://store.local/wp-content/uploads/2023/01/beanie-2-150x150.jpg 150w, https://store.local/wp-content/uploads/2023/01/beanie-2-768x768.jpg 768w", "sizes": "(max-width: 801px) 100vw, 801px", "name": "beanie-2.jpg", "alt": "" } ], "variation": [], "item_data": [], "prices": { "price": "1800", "regular_price": "2000", "sale_price": "1800", "price_range": null, "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "", "raw_prices": { "precision": 6, "price": "18000000", "regular_price": "20000000", "sale_price": "18000000" } }, "totals": { "line_subtotal": "1800", "line_subtotal_tax": "360", "line_total": "1800", "line_total_tax": "360", "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "" }, "catalog_visibility": "visible", "extensions": {}, "_links": { "self": [ { "href": "https://store.local/wp-json/wc/store/v1/cart/items/(?P[\\w-]{32})/c74d97b01eae257e44aa9d5bade97baf" } ], "collection": [ { "href": "https://store.local/wp-json/wc/store/v1/cart/items/(?P[\\w-]{32})" } ] } } ``` ## Add Cart Item Add an item to the cart. Returns the new cart item that was added, or an error response. ```http POST /cart/items/ ``` | Attribute | Type | Required | Description | | :---------- | :------ | :------: | :--------------------------------------------------------------------------------------------------- | | `id` | integer | Yes | The cart item product or variation ID. | | `quantity` | integer | Yes | Quantity of this item in the cart. | | `variation` | array | Yes | Chosen attributes (for variations) containing an array of objects with keys `attribute` and `value`. | ```sh curl --request POST https://example-store.com/wp-json/wc/store/v1/cart/items?id=100&quantity=1 ``` For an example response, see [Single Cart Item](#single-cart-item). If you're looking to add multiple items to the cart at once, please take a look at [batching](/docs/apis/store-api/resources-endpoints/cart#add-item). ## Edit Single Cart Item Edit an item in the cart. ```http PUT /cart/items/:key ``` | Attribute | Type | Required | Description | | :--------- | :------ | :------: | :--------------------------------- | | `key` | string | Yes | The key of the cart item to edit. | | `quantity` | integer | Yes | Quantity of this item in the cart. | ```sh curl --request PUT https://example-store.com/wp-json/wc/store/v1/cart/items/e369853df766fa44e1ed0ff613f563bd?quantity=10 ``` For an example response, see [Single Cart Item](#single-cart-item). ## Delete Single Cart Item Removes an item from the cart by its key. ```http DELETE /cart/items/:key ``` | Attribute | Type | Required | Description | | :-------- | :----- | :------: | :-------------------------------- | | `key` | string | Yes | The key of the cart item to edit. | ```sh curl --request DELETE https://example-store.com/wp-json/wc/store/v1/cart/items/e369853df766fa44e1ed0ff613f563bd ``` ## Delete All Cart Items Removes all items from the cart at once. ```http DELETE /cart/items/ ``` There are no extra parameters needed to use this endpoint. ```sh curl --request DELETE https://example-store.com/wp-json/wc/store/v1/cart/items ``` **Example response:** ```json [] ``` --- ## Cart API *Source: apis/store-api/resources-endpoints/cart.md* # Cart API The cart API returns the current state of the cart for the current session or logged in user. All POST endpoints require a [Nonce Token](/docs/apis/store-api/nonce-tokens) or a [Cart Token](/docs/apis/store-api/cart-tokens) and return the updated state of the full cart once complete. ## Get Cart ```http GET /cart ``` There are no parameters required for this endpoint. ```sh curl "https://example-store.com/wp-json/wc/store/v1/cart" ``` Returns the full cart object response (see [Cart Response](#cart-response)). ## Responses All endpoints under `/cart` (listed in this doc) return responses in the same format; a cart object which includes cart items, applied coupons, shipping addresses and rates, and non-sensitive customer data. ### Cart Response ```json { "items": [ { "key": "a5771bce93e200c36f7cd9dfd0e5deaa", "id": 38, "quantity": 1, "quantity_limits": { "minimum": 1, "maximum": 9999, "multiple_of": 1, "editable": true }, "name": "Beanie with Logo", "short_description": "

This is a simple product.

", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

", "sku": "Woo-beanie-logo", "low_stock_remaining": null, "backorders_allowed": false, "show_backorder_badge": false, "sold_individually": false, "permalink": "https://local.wordpress.test/product/beanie-with-logo/", "images": [ { "id": 61, "src": "https://local.wordpress.test/wp-content/uploads/2023/03/beanie-with-logo-1.jpg", "thumbnail": "https://local.wordpress.test/wp-content/uploads/2023/03/beanie-with-logo-1-450x450.jpg", "srcset": "https://local.wordpress.test/wp-content/uploads/2023/03/beanie-with-logo-1.jpg 800w, https://local.wordpress.test/wp-content/uploads/2023/03/beanie-with-logo-1-450x450.jpg 450w, https://local.wordpress.test/wp-content/uploads/2023/03/beanie-with-logo-1-100x100.jpg 100w, https://local.wordpress.test/wp-content/uploads/2023/03/beanie-with-logo-1-600x600.jpg 600w, https://local.wordpress.test/wp-content/uploads/2023/03/beanie-with-logo-1-300x300.jpg 300w, https://local.wordpress.test/wp-content/uploads/2023/03/beanie-with-logo-1-150x150.jpg 150w, https://local.wordpress.test/wp-content/uploads/2023/03/beanie-with-logo-1-768x768.jpg 768w", "sizes": "(max-width: 800px) 100vw, 800px", "name": "beanie-with-logo-1.jpg", "alt": "" } ], "variation": [], "item_data": [], "prices": { "price": "1800", "regular_price": "2000", "sale_price": "1800", "price_range": null, "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "", "raw_prices": { "precision": 6, "price": "18000000", "regular_price": "20000000", "sale_price": "18000000" } }, "totals": { "line_subtotal": "1800", "line_subtotal_tax": "180", "line_total": "1530", "line_total_tax": "153", "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "" }, "catalog_visibility": "visible", "extensions": {} }, { "key": "b6d767d2f8ed5d21a44b0e5886680cb9", "id": 22, "quantity": 1, "quantity_limits": { "minimum": 1, "maximum": 9999, "multiple_of": 1, "editable": true }, "name": "Belt", "short_description": "

This is a simple product.

", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

", "sku": "woo-belt", "low_stock_remaining": null, "backorders_allowed": false, "show_backorder_badge": false, "sold_individually": false, "permalink": "https://local.wordpress.test/product/belt/", "images": [ { "id": 51, "src": "https://local.wordpress.test/wp-content/uploads/2023/03/belt-2.jpg", "thumbnail": "https://local.wordpress.test/wp-content/uploads/2023/03/belt-2-450x450.jpg", "srcset": "https://local.wordpress.test/wp-content/uploads/2023/03/belt-2.jpg 801w, https://local.wordpress.test/wp-content/uploads/2023/03/belt-2-450x450.jpg 450w, https://local.wordpress.test/wp-content/uploads/2023/03/belt-2-100x100.jpg 100w, https://local.wordpress.test/wp-content/uploads/2023/03/belt-2-600x600.jpg 600w, https://local.wordpress.test/wp-content/uploads/2023/03/belt-2-300x300.jpg 300w, https://local.wordpress.test/wp-content/uploads/2023/03/belt-2-150x150.jpg 150w, https://local.wordpress.test/wp-content/uploads/2023/03/belt-2-768x768.jpg 768w", "sizes": "(max-width: 801px) 100vw, 801px", "name": "belt-2.jpg", "alt": "" } ], "variation": [], "item_data": [], "prices": { "price": "5500", "regular_price": "6500", "sale_price": "5500", "price_range": null, "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "", "raw_prices": { "precision": 6, "price": "55000000", "regular_price": "65000000", "sale_price": "55000000" } }, "totals": { "line_subtotal": "5500", "line_subtotal_tax": "550", "line_total": "4675", "line_total_tax": "468", "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "" }, "catalog_visibility": "visible", "extensions": {} } ], "coupons": [ { "code": "test", "discount_type": "percent", "totals": { "total_discount": "1095", "total_discount_tax": "109", "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "" } } ], "fees": [], "totals": { "total_items": "7300", "total_items_tax": "730", "total_fees": "0", "total_fees_tax": "0", "total_discount": "1095", "total_discount_tax": "110", "total_shipping": "1300", "total_shipping_tax": "130", "total_price": "8256", "total_tax": "751", "tax_lines": [ { "name": "Tax", "price": "751", "rate": "10%" } ], "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "" }, "shipping_address": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "Hello street", "address_2": "", "city": "beverly hills", "state": "CA", "postcode": "90211", "country": "US", "phone": "123456778" }, "billing_address": { "first_name": "John", "last_name": "Doe", "company": "", "address_1": "Hello street", "address_2": "", "city": "beverly hills", "state": "CA", "postcode": "90211", "country": "US", "email": "checkout@templates.com", "phone": "123456778" }, "needs_payment": true, "needs_shipping": true, "payment_requirements": [ "products" ], "has_calculated_shipping": true, "shipping_rates": [ { "package_id": 0, "name": "Shipment 1", "destination": { "address_1": "Hello street", "address_2": "", "city": "beverly hills", "state": "CA", "postcode": "90211", "country": "US" }, "items": [ { "key": "a5771bce93e200c36f7cd9dfd0e5deaa", "name": "Beanie with Logo", "quantity": 1 }, { "key": "b6d767d2f8ed5d21a44b0e5886680cb9", "name": "Belt", "quantity": 1 } ], "shipping_rates": [ { "rate_id": "flat_rate:10", "name": "Flat rate", "description": "", "delivery_time": "", "price": "1300", "taxes": "130", "instance_id": 10, "method_id": "flat_rate", "meta_data": [ { "key": "Items", "value": "Beanie with Logo × 1, Belt × 1" } ], "selected": true, "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "" }, { "rate_id": "free_shipping:12", "name": "Free shipping", "description": "", "delivery_time": "", "price": "0", "taxes": "0", "instance_id": 12, "method_id": "free_shipping", "meta_data": [ { "key": "Items", "value": "Beanie with Logo × 1, Belt × 1" } ], "selected": false, "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "" }, { "rate_id": "local_pickup:13", "name": "Local pickup", "description": "", "delivery_time": "", "price": "0", "taxes": "0", "instance_id": 13, "method_id": "local_pickup", "meta_data": [ { "key": "Items", "value": "Beanie with Logo × 1, Belt × 1" } ], "selected": false, "currency_code": "USD", "currency_symbol": "$", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "$", "currency_suffix": "" } ] } ], "items_count": 2, "items_weight": 0, "cross_sells": [], "errors": [], "payment_methods": [ "bacs", "cod" ], "extensions": {} } ``` ### Error Response If a cart action cannot be performed, an error response will be returned. This will include a reason code and an error message: ```json { "code": "woocommerce_rest_cart_invalid_product", "message": "This product cannot be added to the cart.", "data": { "status": 400 } } ``` Some error responses indicate conflicts (error 409), for example, when an item cannot be found or a coupon is no longer applied. When this type of response is returned, the current state of the cart from the server is also returned as part of the error data: ```json { "code": "woocommerce_rest_cart_invalid_key", "message": "Cart item no longer exists or is invalid.", "data": { "status": 409, "cart": { ... } } } ``` This allows the client to remain in sync with the cart data without additional requests, should the cart change or become outdated. ## Add Item Add an item to the cart and return the full cart response, or an error. This endpoint will return an error unless a valid [Nonce Token](/docs/apis/store-api/nonce-tokens) or [Cart Token](/docs/apis/store-api/cart-tokens) is provided. ```http POST /cart/add-item ``` | Attribute | Type | Required | Description | | :---------- | :------ | :------: | :---------------------------------------------------------------------------------------------------------------------------------------- | | `id` | integer | Yes | The cart item product or variation ID. | | `quantity` | integer | Yes | Quantity of this item in the cart. | | `variation` | array | Yes | Chosen attributes (for variations) containing an array of objects with keys `attribute` and `value`. See notes on attribute naming below. | ```sh curl --header "Nonce: 12345" --request POST https://example-store.com/wp-json/wc/store/v1/cart/add-item?id=100&quantity=1 ``` Returns the full [Cart Response](#cart-response) on success, or an [Error Response](#error-response) on failure. If you want to add supplemental cart item data before it is passed into `CartController::add_to_cart` use the [`woocommerce_store_api_add_to_cart_data`](https://github.com/woocommerce/woocommerce-blocks/blob/4d1c295a2bace9a4f6397cfd5469db31083d477a/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_store_api_add_to_cart_data) filter. For example: ```php add_filter( 'woocommerce_store_api_add_to_cart_data', function( $add_to_cart_data, \WP_REST_Request $request ) { if ( ! empty( $request['custom-request-param'] ) ) { $add_to_cart_data['cart_item_data']['custom-request-data'] = sanitize_text_field( $request['custom-request-param'] ); } return $add_to_cart_data; }, 10, 2 ); ``` **Variation attribute naming:** When adding variations to the cart, the naming of the attribute is important. For global attributes, the attribute posted to the API should be the slug of the attribute. This should have a `pa_` prefix. For example, if you have an attribute named `Color`, the slug will be `pa_color`. For product specific attributes, the attribute posted to the API can be one of the following: - the name of the attribute. For example, if you have an attribute named `Size`, the name will be `Size`. This is case-sensitive. - the slug of the attribute. For example, if you have an attribute named `Autograph ✏️`, the name will be `attribute_autograph-%e2%9c%8f%ef%b8%8f`. This is case-sensitive. You can get this slug from the related `select` on the product page. **Example POST body:** ```json { "id": 13, "quantity": 1, "variation": [ { "attribute": "pa_color", "value": "blue" }, { "attribute": "attribute_autograph-%e2%9c%8f%ef%b8%8f", "value": "Yes" }, { "attribute": "Logo", "value": "Yes" } ] } ``` The above example adds a product variation to the cart with attributes size and color. **Batching:** If you want to add multiple items at once, you need to use the batch endpoint: ```http POST /wc/store/v1/batch ``` The JSON payload for adding multiple items to the cart would look like this: ```json { "requests": [ { "path": "/wc/store/v1/cart/add-item", "method": "POST", "cache": "no-store", "body": { "id": 26, "quantity": 1 }, "headers": { "Nonce": "1db1d13784" } }, { "path": "/wc/store/v1/cart/add-item", "method": "POST", "cache": "no-store", "body": { "id": 27, "quantity": 1 }, "headers": { "Nonce": "1db1d13784" } } ] } ``` ## Remove Item Remove an item from the cart and return the full cart response, or an error. This endpoint will return an error unless a valid [Nonce Token](/docs/apis/store-api/nonce-tokens) or [Cart Token](/docs/apis/store-api/cart-tokens) is provided. ```http POST /cart/remove-item ``` | Attribute | Type | Required | Description | | :-------- | :----- | :------: | :-------------------------------- | | `key` | string | Yes | The key of the cart item to edit. | ```sh curl --header "Nonce: 12345" --request POST https://example-store.com/wp-json/wc/store/v1/cart/remove-item?key=e369853df766fa44e1ed0ff613f563bd ``` Returns the full [Cart Response](#cart-response) on success, or an [Error Response](#error-response) on failure. ## Update Item Update an item in the cart and return the full cart response, or an error. This endpoint will return an error unless a valid [Nonce Token](/docs/apis/store-api/nonce-tokens) or [Cart Token](/docs/apis/store-api/cart-tokens) is provided. ```http POST /cart/update-item ``` | Attribute | Type | Required | Description | | :--------- | :------ | :------: | :--------------------------------- | | `key` | string | Yes | The key of the cart item to edit. | | `quantity` | integer | Yes | Quantity of this item in the cart. | ```sh curl --header "Nonce: 12345" --request POST https://example-store.com/wp-json/wc/store/v1/cart/update-item?key=e369853df766fa44e1ed0ff613f563bd&quantity=10 ``` Returns the full [Cart Response](#cart-response) on success, or an [Error Response](#error-response) on failure. ## Apply Coupon Apply a coupon to the cart and return the full cart response, or an error. This endpoint will return an error unless a valid [Nonce Token](/docs/apis/store-api/nonce-tokens) or [Cart Token](/docs/apis/store-api/cart-tokens) is provided. ```http POST /cart/apply-coupon/ ``` | Attribute | Type | Required | Description | | :-------- | :----- | :------: | :--------------------------------------------- | | `code` | string | Yes | The coupon code you wish to apply to the cart. | ```sh curl --header "Nonce: 12345" --request POST https://example-store.com/wp-json/wc/store/v1/cart/apply-coupon?code=20off ``` Returns the full [Cart Response](#cart-response) on success, or an [Error Response](#error-response) on failure. ## Remove Coupon Remove a coupon from the cart and return the full cart response, or an error. This endpoint will return an error unless a valid [Nonce Token](/docs/apis/store-api/nonce-tokens) or [Cart Token](/docs/apis/store-api/cart-tokens) is provided. ```http POST /cart/remove-coupon/ ``` | Attribute | Type | Required | Description | | :-------- | :----- | :------: | :------------------------------------------------ | | `code` | string | Yes | The coupon code you wish to remove from the cart. | ```sh curl --header "Nonce: 12345" --request POST https://example-store.com/wp-json/wc/store/v1/cart/remove-coupon?code=20off ``` Returns the full [Cart Response](#cart-response) on success, or an [Error Response](#error-response) on failure. ## Update Customer Update customer data and return the full cart response, or an error. This endpoint will return an error unless a valid [Nonce Token](/docs/apis/store-api/nonce-tokens) or [Cart Token](/docs/apis/store-api/cart-tokens) is provided. ```http POST /cart/update-customer ``` | Attribute | Type | Required | Description | | :---------------------------- | :----- | :------: | :--------------------------------------------------------------------------------------- | | `billing_address` | object | no | Customer billing address. | | `billing_address.first_name` | string | no | Customer first name. | | `billing_address.last_name` | string | no | Customer last name. | | `billing_address.address_1` | string | no | First line of the address being shipped to. | | `billing_address.address_2` | string | no | Second line of the address being shipped to. | | `billing_address.city` | string | no | City of the address being shipped to. | | `billing_address.state` | string | no | ISO code, or name, for the state, province, or district of the address being shipped to. | | `billing_address.postcode` | string | no | Zip or Postcode of the address being shipped to. | | `billing_address.country` | string | no | ISO code for the country of the address being shipped to. | | `billing_address.email` | string | no | Email for the customer. | | `billing_address.phone` | string | no | Phone number of the customer. | | `shipping_address` | object | no | Customer shipping address. | | `shipping_address.first_name` | string | no | Customer first name. | | `shipping_address.last_name` | string | no | Customer last name. | | `shipping_address.address_1` | string | no | First line of the address being shipped to. | | `shipping_address.address_2` | string | no | Second line of the address being shipped to. | | `shipping_address.city` | string | no | City of the address being shipped to. | | `shipping_address.state` | string | no | ISO code, or name, for the state, province, or district of the address being shipped to. | | `shipping_address.postcode` | string | no | Zip or Postcode of the address being shipped to. | | `shipping_address.country` | string | no | ISO code for the country of the address being shipped to. | Returns the full [Cart Response](#cart-response) on success, or an [Error Response](#error-response) on failure. ## Select Shipping Rate Selects an available shipping rate for a package, then returns the full cart response, or an error. This endpoint will return an error unless a valid [Nonce Token](/docs/apis/store-api/nonce-tokens) or [Cart Token](/docs/apis/store-api/cart-tokens) is provided. ```http POST /cart/select-shipping-rate ``` | Attribute | Type | Required | Description | | :----------- | :------ | :------: | :---------------------------------------------- | | `package_id` | integer | yes | The ID of the shipping package within the cart. | | `rate_id` | string | yes | The chosen rate ID for the package. | ```sh curl --header "Nonce: 12345" --request POST /cart/select-shipping-rate?package_id=1&rate_id=flat_rate:1 ``` Returns the full [Cart Response](#cart-response) on success, or an [Error Response](#error-response) on failure. --- ## Checkout order API *Source: apis/store-api/resources-endpoints/checkout-order.md* # Checkout order API The checkout order API facilitates the processing of existing orders and handling payments. All checkout order endpoints require a [Nonce Token](/docs/apis/store-api/nonce-tokens) or a [Cart Token](/docs/apis/store-api/cart-tokens) otherwise these endpoints will return an error. ## Process Order and Payment Accepts the final chosen payment method, and any additional payment data, then attempts payment and returns the result. ```http POST /wc/store/v1/checkout/{ORDER_ID} ``` | Attribute | Type | Required | Description | | :----------------- | :----- | :------: | :------------------------------------------------------------------ | | `key` | string | Yes | The key for the order verification. | | `billing_email` | string | No | The email address used to verify guest orders. | | `billing_address` | object | Yes | Object of updated billing address data for the customer. | | `shipping_address` | object | Yes | Object of updated shipping address data for the customer. | | `payment_method` | string | Yes | The ID of the payment method being used to process the payment. | | `payment_data` | array | No | Data to pass through to the payment method when processing payment. | ```sh curl --header "Nonce: 12345" --request POST https://example-store.com/wp-json/wc/store/v1/checkout/{ORDER_ID} -d '{"key":"wc_order_oFmQYREzh9Tfv","billing_email":"admin@example.com","payment_method":"cheque","billing_address":{...},"shipping_address":{...}' ``` **Example request:** ```json { "key": "wc_order_oFmQYREzh9Tfv", "billing_email": "admin@example.com", "billing_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US", "email": "admin@example.com", "phone": "555-2368" }, "shipping_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US", "phone": "555-2368" }, "payment_method": "cheque", "payment_data": [] } ``` **Example response:** ```json { "order_id": 146, "status": "on-hold", "order_key": "wc_order_oFmQYREzh9Tfv", "customer_note": "", "customer_id": 1, "billing_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US", "email": "admin@example.com", "phone": "555-2368" }, "shipping_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US", "phone": "555-2368" }, "payment_method": "cheque", "payment_result": { "payment_status": "success", "payment_details": [], "redirect_url": "https://local.wordpress.test/block-checkout/order-received/146/?key=wc_order_VPffqyvgWVqWL" } } ``` ## Payment Data There are many payment gateways available for merchants to use, and each one will be expecting different `payment_data`. We cannot comprehensively list all expected requests for all payment gateways, and we would recommend reaching out to the authors of the payment gateway plugins you're working with for further information. An example of the payment data sent to the Checkout Order endpoint when using the [WooCommerce Stripe Payment Gateway](https://wordpress.org/plugins/woocommerce-gateway-stripe/) is shown below. For further information on generating a `stripe_source` please check [the Stripe documentation](https://stripe.com/docs). ```json { "payment_data": [ { "key": "stripe_source", "value": "src_xxxxxxxxxxxxx" }, { "key": "billing_email", "value": "myemail@email.com" }, { "key": "billing_first_name", "value": "Jane" }, { "key": "billing_last_name", "value": "Doe" }, { "key": "paymentMethod", "value": "stripe" }, { "key": "paymentRequestType", "value": "cc" }, { "key": "wc-stripe-new-payment-method", "value": true } ] } ``` --- ## Checkout API *Source: apis/store-api/resources-endpoints/checkout.md* # Checkout API The checkout API facilitates the creation of orders (from the current cart) and handling payments for payment methods. All checkout endpoints require either a [Nonce Token](/docs/apis/store-api/nonce-tokens) or a [Cart Token](/docs/apis/store-api/cart-tokens) otherwise these endpoints will return an error. ## Get Checkout Data Returns data required for the checkout. This includes a draft order (created from the current cart) and customer billing and shipping addresses. The payment information will be empty, as it's only persisted when the order gets updated via POST requests (right before payment processing). ```http GET /wc/store/v1/checkout ``` There are no parameters required for this endpoint. ```sh curl --header "Nonce: 12345" --request GET https://example-store.com/wp-json/wc/store/v1/checkout ``` ### Example Response ```json { "order_id": 146, "status": "checkout-draft", "order_key": "wc_order_VPffqyvgWVqWL", "customer_note": "", "customer_id": 1, "billing_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US", "email": "admin@example.com", "phone": "555-2368" }, "shipping_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US" }, "payment_method": "", "payment_result": { "payment_status": "", "payment_details": [], "redirect_url": "" } } ``` ## Update checkout data This endpoint allows you to update the checkout data for the current order. This can be called from the frontend to persist checkout fields, for example. ```http PUT /wc/store/v1/checkout?__experimental_calc_totals=true ``` Note the `__experimental_calc_totals` parameter. This is used to determine if the cart totals should be recalculated. This should be set to true if the cart totals are being updated in response to a PUT request, false otherwise. | Attribute | Type | Required | Description | | :------------------ | :----- | :------: | :-------------------------------------------------- | | `additional_fields` | object | No | Name => value pairs of additional fields to update. | | `payment_method` | string | No | The ID of the payment method selected. | | `order_notes` | string | No | Order notes. | ```sh curl --header "Nonce: 12345" --request PUT https://example-store.com/wp-json/wc/store/v1/checkout?additional_fields[plugin-namespace/leave-on-porch]=true&additional_fields[plugin-namespace/location-on-porch]=dsdd&payment_method=bacs&order_notes=Please%20leave%20package%20on%20back%20porch ``` ### Example Request ```json { "additional_fields": { "plugin-namespace/leave-on-porch": true, "plugin-namespace/location-on-porch": "dsdd" }, "payment_method": "bacs", "order_notes": "Please leave package on back porch" } ``` ### Example Response ```json { "order_id": 1486, "status": "checkout-draft", "order_key": "wc_order_KLpMaJ054PVlb", "order_number": "1486", "customer_note": "", "customer_id": 1, "billing_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US", "email": "admin@example.com", "phone": "555-2368" }, "shipping_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US" }, "payment_method": "bacs", "payment_result": null, "additional_fields": { "plugin-namespace/leave-on-porch": true, "plugin-namespace/location-on-porch": "dsdd" }, "__experimentalCart": { ... }, "extensions": {} } ``` Note the `__experimentalCart` field that is returned as part of the response. Totals will be updated on the front-end following a PUT request. This makes it possible to manipulate cart totals in response to fields persisted via the PUT request. ## Process Order and Payment Accepts the final customer addresses and chosen payment method, and any additional payment data, then attempts payment and returns the result. ```http POST /wc/store/v1/checkout ``` | Attribute | Type | Required | Description | | :------------------ | :----- | :------: | :------------------------------------------------------------------ | | `billing_address` | object | Yes | Object of updated billing address data for the customer. | | `shipping_address` | object | Yes | Object of updated shipping address data for the customer. | | `customer_note` | string | No | Note added to the order by the customer during checkout. | | `payment_method` | string | Yes | The ID of the payment method being used to process the payment. | | `payment_data` | array | No | Data to pass through to the payment method when processing payment. | | `customer_password` | string | No | Optionally define a password for new accounts. | | `expected_total` | string | No | Total the shopper confirmed, in minor units. See note below. | `expected_total` is a string in the smallest unit of the store currency (e.g. cents), matching the cart `totals.total_price` format. When provided, the order is rejected with a `409` (`woocommerce_rest_checkout_total_mismatch`) if the total the server calculates for the request no longer matches it, and the refreshed cart is returned so the client can display the updated total. Omit it to skip the check — e.g. for flows that cannot know the final total up front, such as some express payment methods. ```sh curl --header "Nonce: 12345" --request POST https://example-store.com/wp-json/wc/store/v1/checkout?payment_method=paypal&payment_data[0][key]=test-key&payment_data[0][value]=test-value ``` ### Example Request ```json { "billing_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US", "email": "admin@example.com", "phone": "555-2368" }, "shipping_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US" }, "customer_note": "Test notes on order.", "create_account": false, "payment_method": "cheque", "payment_data": [], "extensions": { "some-extension-name": { "some-data-key": "some data value" } } } ``` ### Example Response ```json { "order_id": 146, "status": "on-hold", "order_key": "wc_order_VPffqyvgWVqWL", "customer_note": "", "customer_id": 1, "billing_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US", "email": "admin@example.com", "phone": "555-2368" }, "shipping_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US" }, "payment_method": "cheque", "payment_result": { "payment_status": "success", "payment_details": [], "redirect_url": "https://local.wordpress.test/block-checkout/order-received/146/?key=wc_order_VPffqyvgWVqWL" } } ``` ## Payment Data There are many payment gateways available for merchants to use, and each one will be expecting different `payment_data`. We cannot comprehensively list all expected requests for all payment gateways, and we would recommend reaching out to the authors of the payment gateway plugins you're working with for further information. An example of the payment data sent to the Checkout endpoint when using the [WooCommerce Stripe Payment Gateway](https://wordpress.org/plugins/woocommerce-gateway-stripe/) is shown below. For further information on generating a `stripe_source` please check [the Stripe documentation](https://stripe.com/docs). ```json { "payment_data": [ { "key": "stripe_source", "value": "src_xxxxxxxxxxxxx" }, { "key": "billing_email", "value": "myemail@email.com" }, { "key": "billing_first_name", "value": "Jane" }, { "key": "billing_last_name", "value": "Doe" }, { "key": "paymentMethod", "value": "stripe" }, { "key": "paymentRequestType", "value": "cc" }, { "key": "wc-stripe-new-payment-method", "value": true } ] } ``` --- ## Order API *Source: apis/store-api/resources-endpoints/order.md* # Order API The order API returns the pay-for-order order. ## Get Order ```http GET /order/{ORDER_ID}?key={KEY}&billing_email={BILLING_EMAIL} ``` There is one required parameter for this endpoint which is `key`. `billing_email` must be added for guest orders. ```sh curl "https://example-store.com/wp-json/wc/store/v1/order/{ORDER_ID}?key={KEY}&billing_email={BILLING_EMAIL}" ``` Returns the full order object response (see [Order Response](#order-response)). ## Responses Order endpoints return responses in the same format as `/cart`; an order object which includes order items, applied coupons, shipping addresses and rates, and non-sensitive customer data. ### Order Response ```json { "id": 147, "status": "pending", "coupons": [ { "code": "discount20", "totals": { "currency_code": "GBP", "currency_symbol": "£", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "£", "currency_suffix": "", "total_discount": "421", "total_discount_tax": "0" } } ], "shipping_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US", "phone": "555-2368" }, "billing_address": { "first_name": "Peter", "last_name": "Venkman", "company": "", "address_1": "550 Central Park West", "address_2": "Corner Penthouse Spook Central", "city": "New York", "state": "NY", "postcode": "10023", "country": "US", "email": "admin@example.com", "phone": "555-2368" }, "items": [ { "key": "9bf31c7ff062936a96d3c8bd1f8f2ff3", "id": 15, "quantity": 1, "quantity_limits": { "minimum": 1, "maximum": 99, "multiple_of": 1, "editable": true }, "name": "Beanie", "short_description": "

This is a simple product.

", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

", "sku": "woo-beanie", "low_stock_remaining": null, "backorders_allowed": false, "show_backorder_badge": false, "sold_individually": false, "permalink": "https://local.wordpress.test/product/beanie/", "images": [ { "id": 44, "src": "https://local.wordpress.test/wp-content/uploads/2020/03/beanie-2.jpg", "thumbnail": "https://local.wordpress.test/wp-content/uploads/2020/03/beanie-2-324x324.jpg", "srcset": "https://local.wordpress.test/wp-content/uploads/2020/03/beanie-2.jpg 801w, https://local.wordpress.test/wp-content/uploads/2020/03/beanie-2-324x324.jpg 324w, https://local.wordpress.test/wp-content/uploads/2020/03/beanie-2-100x100.jpg 100w, https://local.wordpress.test/wp-content/uploads/2020/03/beanie-2-416x416.jpg 416w, https://local.wordpress.test/wp-content/uploads/2020/03/beanie-2-300x300.jpg 300w, https://local.wordpress.test/wp-content/uploads/2020/03/beanie-2-150x150.jpg 150w, https://local.wordpress.test/wp-content/uploads/2020/03/beanie-2-768x768.jpg 768w", "sizes": "(max-width: 801px) 100vw, 801px", "name": "beanie-2.jpg", "alt": "" } ], "variation": [], "prices": { "currency_code": "GBP", "currency_symbol": "£", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "£", "currency_suffix": "", "price": "1000", "regular_price": "2000", "sale_price": "1000", "price_range": null, "raw_prices": { "precision": 6, "price": "10000000", "regular_price": "20000000", "sale_price": "10000000" } }, "item_data": [], "totals": { "currency_code": "GBP", "currency_symbol": "£", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "£", "currency_suffix": "", "line_subtotal": "1000", "line_subtotal_tax": "0", "line_total": "800", "line_total_tax": "0" }, "catalog_visibility": "view" }, { "key": "e369853df766fa44e1ed0ff613f563bd", "id": 34, "quantity": 1, "quantity_limits": { "minimum": 1, "maximum": 99, "multiple_of": 1, "editable": true }, "name": "WordPress Pennant", "short_description": "

This is an external product.

", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

", "sku": "wp-pennant", "low_stock_remaining": null, "backorders_allowed": false, "show_backorder_badge": false, "sold_individually": false, "permalink": "https://local.wordpress.test/product/wordpress-pennant/", "images": [ { "id": 57, "src": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1.jpg", "thumbnail": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-324x324.jpg", "srcset": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1.jpg 800w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-324x324.jpg 324w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-100x100.jpg 100w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-416x416.jpg 416w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-300x300.jpg 300w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-150x150.jpg 150w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-768x768.jpg 768w", "sizes": "(max-width: 800px) 100vw, 800px", "name": "pennant-1.jpg", "alt": "" } ], "variation": [], "prices": { "currency_code": "GBP", "currency_symbol": "£", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "£", "currency_suffix": "", "price": "1105", "regular_price": "1105", "sale_price": "1105", "price_range": null, "raw_prices": { "precision": 6, "price": "11050000", "regular_price": "11050000", "sale_price": "11050000" } }, "item_data": [], "totals": { "currency_code": "GBP", "currency_symbol": "£", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "£", "currency_suffix": "", "line_subtotal": "1105", "line_subtotal_tax": "0", "line_total": "884", "line_total_tax": "0" }, "catalog_visibility": "view" } ], "needs_payment": true, "needs_shipping": true, "totals": { "subtotal":"2105", "total_discount": "421", "total_shipping": "500", "total_fees": "0", "total_tax": "0", "total_refund": "0", "total_price": "2184", "total_items": "2105", "total_items_tax": "0", "total_fees_tax": "0", "total_discount_tax": "0", "total_shipping_tax": "0", "tax_lines": [] }, "errors": [], "payment_requirements": [ "products" ], } ``` ### Error Response If an order action cannot be performed, an error response will be returned. This will include a reason code and an error message: ```json { "code": "woocommerce_rest_invalid_order", "message": "Invalid order ID or key provided.", "data": { "status": 401 } } ``` --- ## Product Attribute Terms API *Source: apis/store-api/resources-endpoints/product-attribute-terms.md* # Product Attribute Terms API ```http GET /products/attributes/:id/terms GET /products/attributes/:id/terms?orderby=slug ``` | Attribute | Type | Required | Description | | :---------------------- | :------ | :------: | :------------------------------------------------------------------------------------------------------------ | | `id` | integer | Yes | The ID of the attribute to retrieve terms for. | | `order` | string | no | Order ascending or descending. Allowed values: `asc`, `desc` | | `orderby` | string | no | Sort collection by object attribute. Allowed values: `id`, `name`, `name_num`, `slug`, `count`, `menu_order`. | | `__experimental_visual` | boolean | no | If true, include experimental visual swatch data for `wc-visual` attribute terms. | ## Visual response fields The following fields are included only when `__experimental_visual=true` is passed for `wc-visual` attribute terms. Other attribute types keep the default term response without `__experimentalVisual`. | Attribute | Type | Description | | :--------------------------- | :----- | :------------------------------------------------------------------------------------------------------------- | | `__experimentalVisual` | object | Experimental visual swatch data for `wc-visual` attribute terms. | | `__experimentalVisual.type` | string | Visual swatch type. Allowed values: `color`, `image`, `none`. | | `__experimentalVisual.value` | string | Visual swatch value. Returns a hex color for `color`, an image URL for `image`, or an empty string for `none`. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/attributes/1/terms?__experimental_visual=true" ``` **Example response for visual attribute terms:** ```json [ { "id": 22, "name": "Blue", "slug": "blue", "description": "", "parent": 0, "count": 5, "__experimentalVisual": { "type": "color", "value": "#1e73be" } }, { "id": 48, "name": "Burgundy", "slug": "burgundy", "description": "", "parent": 0, "count": 1, "__experimentalVisual": { "type": "image", "value": "https://example-store.com/wp-content/uploads/2026/06/burgundy-swatch.jpg" } } ] ``` **Example response for non-visual attribute terms:** ```json [ { "id": 12, "name": "Large", "slug": "large", "description": "", "parent": 0, "count": 7 } ] ``` --- ## Product Attributes API *Source: apis/store-api/resources-endpoints/product-attributes.md* # Product Attributes API ## List Product Attributes ```http GET /products/attributes ``` There are no parameters required for this endpoint. ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/attributes" ``` Example response: ```json [ { "id": 1, "name": "Color", "taxonomy": "pa_color", "type": "select", "order": "menu_order", "has_archives": false }, { "id": 2, "name": "Size", "taxonomy": "pa_size", "type": "select", "order": "menu_order", "has_archives": false } ] ``` ## Single Product Attribute Get a single attribute taxonomy. ```http GET /products/attributes/:id ``` | Attribute | Type | Required | Description | | :-------- | :------ | :------: | :----------------------------------- | | `id` | integer | Yes | The ID of the attribute to retrieve. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/attributes/1" ``` **Example response:** ```json { "id": 1, "name": "Color", "taxonomy": "pa_color", "type": "select", "order": "menu_order", "has_archives": false } ``` --- ## Product Brands API *Source: apis/store-api/resources-endpoints/product-brands.md* # Product Brands API ## List Product Brands ```http GET /products/brands ``` | Attribute | Type | Required | Description | | :----------- | :------ | :------: | :-------------------------------------------------------------------------------------------------------------------- | | `context` | string | No | Scope under which the request is made; determines fields present in response. | | `page` | integer | No | Current page of the collection. Defaults to `1`. | | `per_page` | integer | No | Maximum number of items to be returned in result set. Defaults to no limit. Values between `0` and `100` are allowed. | | `search` | string | No | Limit results to those matching a string. | | `exclude` | array | No | Ensure result set excludes specific IDs. | | `include` | array | No | Limit result set to specific IDs. | | `order` | string | No | Sort ascending or descending. Allowed values: `asc`, `desc`. Defaults to `asc`. | | `orderby` | string | No | Sort by term property. Allowed values: `name`, `slug`, `count`. Defaults to `name`. | | `hide_empty` | boolean | No | If true, empty terms will not be returned. Defaults to `true`. | | `parent` | integer | No | Limit results to those with a specific parent ID. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/brands" ``` Example response: ```json [ { "id": 16, "name": "Nike", "slug": "nike", "description": "This is the Nike brand.", "parent": 0, "count": 11, "image": { "id": 55, "src": "https://store.local/wp-content/uploads/2021/11/nike-logo.jpg", "thumbnail": "https://store.local/wp-content/uploads/2021/11/nike-logo-324x324.jpg", "srcset": "https://store.local/wp-content/uploads/2021/11/nike-logo.jpg 800w, https://store.local/wp-content/uploads/2021/11/nike-logo-324x324.jpg 324w, https://store.local/wp-content/uploads/2021/11/nike-logo-100x100.jpg 100w, https://store.local/wp-content/uploads/2021/11/nike-logo-416x416.jpg 416w, https://store.local/wp-content/uploads/2021/11/nike-logo-300x300.jpg 300w, https://store.local/wp-content/uploads/2021/11/nike-logo-150x150.jpg 150w, https://store.local/wp-content/uploads/2021/11/nike-logo-768x768.jpg 768w", "sizes": "(max-width: 800px) 100vw, 800px", "name": "nike-logo.jpg", "alt": "" }, "review_count": 2, "permalink": "https://store.local/product-brand/nike/" }, { "id": 21, "name": "Adidas", "slug": "adidas", "description": "", "parent": 0, "count": 1, "image": null, "review_count": 1, "permalink": "https://store.local/product-brand/adidas/" } ] ``` ## Single Product Brand Get a single brand. ```http GET /products/brands/:id ``` or ```http GET /products/brands/:slug ``` | Parameter | Type | Required | Description | | :-------- | :------ | :------: |:---------------------------------------------------------------------| | `identifier` | string | Yes | The identifier of the brand to retrieve. Can be a brand ID or slug. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/brands/1" ``` or ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/brands/adidas" ``` **Example response:** ```json { "id": 1, "name": "Adidas", "slug": "adidas", "description": "", "parent": 0, "count": 1, "image": null, "review_count": 1, "permalink": "https://store.local/product-brand/adidas/" } ``` --- ## Product Categories API *Source: apis/store-api/resources-endpoints/product-categories.md* # Product Categories API ## List Product Categories ```http GET /products/categories ``` | Attribute | Type | Required | Description | | :----------- | :------ | :------: | :-------------------------------------------------------------------------------------------------------------------- | | `context` | string | No | Scope under which the request is made; determines fields present in response. | | `page` | integer | No | Current page of the collection. Defaults to `1`. | | `per_page` | integer | No | Maximum number of items to be returned in result set. Defaults to no limit. Values between `0` and `100` are allowed. | | `search` | string | No | Limit results to those matching a string. | | `exclude` | array | No | Ensure result set excludes specific IDs. | | `include` | array | No | Limit result set to specific IDs. | | `order` | string | No | Sort ascending or descending. Allowed values: `asc`, `desc`. Defaults to `asc`. | | `orderby` | string | No | Sort by term property. Allowed values: `name`, `slug`, `count`. Defaults to `name`. | | `hide_empty` | boolean | No | If true, empty terms will not be returned. Defaults to `true`. | | `parent` | integer | No | Limit results to those with a specific parent ID. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/categories" ``` Example response: ```json [ { "id": 16, "name": "Clothing", "slug": "clothing", "description": "This is the clothing category.", "parent": 0, "count": 11, "image": { "id": 55, "src": "https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1.jpg", "thumbnail": "https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-324x324.jpg", "srcset": "https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1.jpg 800w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-324x324.jpg 324w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-100x100.jpg 100w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-416x416.jpg 416w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-300x300.jpg 300w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-150x150.jpg 150w, https://store.local/wp-content/uploads/2021/11/t-shirt-with-logo-1-768x768.jpg 768w", "sizes": "(max-width: 800px) 100vw, 800px", "name": "t-shirt-with-logo-1.jpg", "alt": "" }, "review_count": 2, "permalink": "https://store.local/product-category/clothing/" }, { "id": 21, "name": "Decor", "slug": "decor", "description": "", "parent": 0, "count": 1, "image": null, "review_count": 1, "permalink": "https://store.local/product-category/decor/" } ] ``` ## Single Product Category Get a single category. ```http GET /products/categories/:id ``` | Category | Type | Required | Description | | :------- | :------ | :------: | :---------------------------------- | | `id` | integer | Yes | The ID of the category to retrieve. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/categories/1" ``` **Example response:** ```json { "id": 1, "name": "Decor", "slug": "decor", "description": "", "parent": 0, "count": 1, "image": null, "review_count": 1, "permalink": "https://store.local/product-category/decor/" } ``` --- ## Product Collection Data API *Source: apis/store-api/resources-endpoints/product-collection-data.md* # Product Collection Data API This endpoint allows you to get aggregate data from a collection of products, for example, the min and max price in a collection of products (ignoring pagination). This is used by blocks for product filtering widgets, since counts are based on the product catalog being viewed. ```http GET /products/collection-data GET /products/collection-data?calculate_price_range=true GET /products/collection-data?calculate_attribute_counts[0][query_type]=or&calculate_attribute_counts[0][taxonomy]=pa_color GET /products/collection-data?calculate_rating_counts=true GET /products/collection-data?calculate_taxonomy_counts=product_cat ``` | Attribute | Type | Required | Description | | :------------------------------ | :----- | :------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `calculate_price_range` | bool | No | Returns the min and max price for the product collection. If false, only `null` will be returned. | | `calculate_attribute_counts` | object | No | Returns attribute counts for a list of attribute taxonomies you pass in via this parameter. Each should be provided as an object with keys "taxonomy" and "query_type". If empty, `null` will be returned. | | `calculate_rating_counts` | bool | No | Returns the counts of products with a certain average rating, 1-5. If false, only `null` will be returned. | | `calculate_stock_status_counts` | bool | No | Returns counts of products with each stock status (in stock, out of stock, on backorder). If false, only `null` will be returned. | | `calculate_taxonomy_counts` | array | No | Returns taxonomy counts for a list of taxonomies you pass in via this parameter. Each should be provided as a taxonomy name string. If empty, `null` will be returned. | **In addition to the above attributes**, all product list attributes are supported. This allows you to get data for a certain subset of products. See [the products API list products section](/docs/apis/store-api/resources-endpoints/products#list-products) for the full list. ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/collection-data?calculate_price_range=true&calculate_attribute_counts=pa_size,pa_color&calculate_rating_counts=true&calculate_taxonomy_counts=product_cat,product_tag" ``` **Example response:** ```json { "price_range": [ "currency_minor_unit": 2, "min_price": "0", "max_price": "9000", "currency_code": "USD", "currency_decimal_separator": ".", "currency_minor_unit": 2, "currency_prefix": "$", "currency_suffix": "", "currency_symbol": "$", "currency_thousand_separator": ",", ], "attribute_counts": [ { "term": 22, "count": 4 }, { "term": 23, "count": 3 }, { "term": 24, "count": 4 } ], "rating_counts": [ { "rating": 3, "count": 1 }, { "rating": 4, "count": 1 } ], "taxonomy_counts": [ { "term": 25, "count": 8 }, { "term": 26, "count": 6 }, { "term": 27, "count": 2 } ] } ``` --- ## Product Reviews API *Source: apis/store-api/resources-endpoints/product-reviews.md* # Product Reviews API ## List Product Reviews This endpoint returns product reviews (comments) and can also show results from either specific products or specific categories. ```http GET /products/reviews GET /products/reviews?category_id=1,2,3 GET /products/reviews?product_id=1,2,3 GET /products/reviews?orderby=rating&order=desc ``` | Attribute | Type | Required | Description | | :------------ | :------ | :------: | :-------------------------------------------------------------------------------------------------- | | `page` | integer | no | Current page of the collection. | | `per_page` | integer | no | Maximum number of items to be returned in result set. | | `offset` | integer | no | Offset the result set by a specific number of items. | | `order` | string | no | Order sort attribute ascending or descending. Allowed values: `asc`, `desc` | | `orderby` | string | no | Sort collection by object attribute. Allowed values : `date`, `date_gmt`, `id`, `rating`, `product` | | `category_id` | string | no | Limit result set to reviews from specific category IDs. | | `product_id` | string | no | Limit result set to reviews from specific product IDs. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/collection-data?calculate_price_range=true&calculate_attribute_counts=pa_size,pa_color&calculate_rating_counts=true" ``` **Example response:** ```json [ { "id": 83, "date_created": "2022-01-12T15:42:14", "formatted_date_created": "January 12, 2022", "date_created_gmt": "2022-01-12T15:42:14", "product_id": 33, "product_name": "Beanie with Logo", "product_permalink": "https://store.local/product/beanie-with-logo/", "product_image": { "id": 56, "src": "https://store.local/wp-content/uploads/2021/11/beanie-with-logo-1.jpg", "thumbnail": "https://store.local/wp-content/uploads/2021/11/beanie-with-logo-1-324x324.jpg", "srcset": "https://store.local/wp-content/uploads/2021/11/beanie-with-logo-1.jpg 800w, https://store.local/wp-content/uploads/2021/11/beanie-with-logo-1-324x324.jpg 324w, https://store.local/wp-content/uploads/2021/11/beanie-with-logo-1-100x100.jpg 100w, https://store.local/wp-content/uploads/2021/11/beanie-with-logo-1-416x416.jpg 416w, https://store.local/wp-content/uploads/2021/11/beanie-with-logo-1-300x300.jpg 300w, https://store.local/wp-content/uploads/2021/11/beanie-with-logo-1-150x150.jpg 150w, https://store.local/wp-content/uploads/2021/11/beanie-with-logo-1-768x768.jpg 768w", "sizes": "(max-width: 800px) 100vw, 800px", "name": "beanie-with-logo-1.jpg", "alt": "" }, "reviewer": "reviewer-name", "review": "

This is a fantastic product.

\n", "rating": 5, "verified": true, "reviewer_avatar_urls": { "24": "https://secure.gravatar.com/avatar/12345?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/12345?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/12345?s=96&d=mm&r=g" } } ] ``` --- ## Product Tags API *Source: apis/store-api/resources-endpoints/product-tags.md* # Product Tags API ## List Product Tags ```http GET /products/tags ``` | Attribute | Type | Required | Description | | :----------- | :------ | :------: | :-------------------------------------------------------------------------------------------------------------------- | | `context` | string | No | Scope under which the request is made; determines fields present in response. | | `page` | integer | No | Current page of the collection. Defaults to `1`. | | `per_page` | integer | No | Maximum number of items to be returned in result set. Defaults to no limit. Values between `0` and `100` are allowed. | | `search` | string | No | Limit results to those matching a string. | | `exclude` | array | No | Ensure result set excludes specific IDs. | | `include` | array | No | Limit result set to specific IDs. | | `order` | string | No | Sort ascending or descending. Allowed values: `asc`, `desc`. Defaults to `asc`. | | `orderby` | string | No | Sort by term property. Allowed values: `name`, `slug`, `count`. Defaults to `name`. | | `hide_empty` | boolean | No | If true, empty terms will not be returned. Defaults to `true`. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/tags" ``` Example response: ```json [ { "id": 1, "name": "Test Tag", "slug": "test-tag", "description": "", "parent": 0, "count": 1 }, { "id": 2, "name": "Another Tag", "slug": "another-tag", "description": "", "parent": 0, "count": 1 } ] ``` --- ## Products API *Source: apis/store-api/resources-endpoints/products.md* # Products API The store products API provides public product data so it can be rendered on the client side. ## Product Visibility ### Draft and non-published products Only published products are accessible via the Store API. Requesting a draft, pending, or other non-published product by ID or slug returns a `404` error. Non-published products are also excluded from the collection endpoint. ### Password-protected products Password-protected products are visible in the API, but their `description` and `short_description` fields are redacted (returned as empty strings) until the correct password has been submitted. The response includes an `is_password_protected` boolean field so clients can detect this state and prompt the user. Password verification uses WordPress's native `wp-postpass_*` cookie, set when a user submits the password form on the frontend. The Store API does not accept passwords directly. Other product data (price, images, categories, etc.) remains accessible regardless of password status. ## List Products ```http GET /products GET /products?search=product%20name GET /products?slug=slug-1,slug-2 GET /products?after=2017-03-22&date_column=date GET /products?before=2017-03-22&date_column=date GET /products?exclude=10,44,33 GET /products?include=10,44,33 GET /products?offset=10 GET /products?order=asc&orderby=price GET /products?parent=10 GET /products?parent_exclude=10 GET /products?type=simple GET /products?sku=sku-1,sku-2 GET /products?featured=true GET /products?category=22 GET /products?brand=adidas GET /products?_unstable_tax_my-taxonomy=my-taxonomy-term-id GET /products?tag=special-items GET /products?attributes[0][attribute]=pa_color&attributes[0][slug]=red GET /products?on_sale=true GET /products?min_price=5000 GET /products?max_price=10000 GET /products?stock_status=['outofstock'] GET /products?catalog_visibility=search GET /products?rating=4,5 GET /products?related=34 GET /products?return_price_range=true GET /products?return_attribute_counts=pa_size,pa_color GET /products?return_rating_counts=true ``` | Attribute | Type | Required | Description | | :------------------------------------------ | :------ | :------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `search` | string | no | Limit results to those matching a string. | | `slug` | string | no | Limit result set to products with specific slug(s). Use commas to separate. | | `after` | string | no | Limit response to resources created after a given ISO8601 compliant date. | | `before` | string | no | Limit response to resources created before a given ISO8601 compliant date. | | `date_column` | string | no | When limiting response using after/before, which date column to compare against. Allowed values: `date`, `date_gmt`, `modified`, `modified_gmt` | | `exclude` | array | no | Ensure result set excludes specific IDs. | | `include` | array | no | Limit result set to specific ids. | | `offset` | integer | no | Offset the result set by a specific number of items. | | `order` | string | no | Order sort attribute ascending or descending. Allowed values: `asc`, `desc` | | `orderby` | string | no | Sort collection by object attribute. Allowed values : `date`, `modified`, `id`, `include`, `title`, `slug`, `price`, `popularity`, `rating`, `menu_order`, `comment_count` | | `parent` | array | no | Limit result set to those of particular parent IDs. | | `parent_exclude` | array | no | Limit result set to all items except those of a particular parent ID. | | `type` | string | no | Limit result set to products assigned a specific type. | | `sku` | string | no | Limit result set to products with specific SKU(s). Use commas to separate. | | `featured` | boolean | no | Limit result set to featured products. | | `category` | string | no | Limit result set to products assigned to categories IDs or slugs, separated by commas. | | `category_operator` | string | no | Operator to compare product category terms. Allowed values: `in`, `not_in`, `and` | | `brand` | string | no | Limit result set to products assigned to brands IDs or slugs, separated by commas. | | `brand_operator` | string | no | Operator to compare product brand terms. Allowed values: `in`, `not_in`, `and` | | `_unstable_tax_[product-taxonomy]` | string | no | Limit result set to products assigned to the term ID of that custom product taxonomy. `[product-taxonomy]` should be the key of the custom product taxonomy registered. | | `_unstable_tax_[product-taxonomy]_operator` | string | no | Operator to compare custom product taxonomy terms. Allowed values: `in`, `not_in`, `and` | | `tag` | string | no | Limit result set to products assigned a specific tag ID. | | `tag_operator` | string | no | Operator to compare product tags. Allowed values: `in`, `not_in`, `and` | | `on_sale` | boolean | no | Limit result set to products on sale. | | `min_price` | string | no | Limit result set to products based on a minimum price, provided using the smallest unit of the currency. E.g. provide 10025 for 100.25 USD, which is a two-decimal currency, and 1025 for 1025 JPY, which is a zero-decimal currency. | | `max_price` | string | no | Limit result set to products based on a maximum price, provided using the smallest unit of the currency. E.g. provide 10025 for 100.25 USD, which is a two-decimal currency, and 1025 for 1025 JPY, which is a zero-decimal currency. | | `stock_status` | array | no | Limit result set to products with specified stock statuses. Expects an array of strings containing 'instock', 'outofstock' or 'onbackorder'. | | `attributes` | array | no | Limit result set to specific attribute terms. Expects an array of objects containing `attribute` (taxonomy), `term_id` or `slug`, and optional `operator` for comparison. | | `attribute_relation` | string | no | The logical relationship between attributes when filtering across multiple at once. | | `catalog_visibility` | string | no | Determines if hidden or visible catalog products are shown. Allowed values: `any`, `visible`, `catalog`, `search`, `hidden` | | `rating` | array | no | Limit result set to products with a certain average rating. Allowed values: `1`, `2`, `3`, `4`, `5`. | | `related` | integer | no | Limit result set to products related to a specific product ID. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products" ``` **Example response:** ```json [ { "id": 34, "name": "WordPress Pennant", "slug": "wordpress-pennant", "variation": "", "permalink": "https://local.wordpress.test/product/wordpress-pennant/", "sku": "wp-pennant", "summary": "

This is an external product.

", "short_description": "

This is an external product.

", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

", "on_sale": false, "prices": { "currency_code": "GBP", "currency_symbol": "£", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "£", "currency_suffix": "", "price": "1105", "regular_price": "1105", "sale_price": "1105", "price_range": null }, "average_rating": "0", "review_count": 0, "images": [ { "id": 57, "src": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1.jpg", "thumbnail": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-324x324.jpg", "srcset": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1.jpg 800w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-324x324.jpg 324w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-100x100.jpg 100w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-416x416.jpg 416w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-300x300.jpg 300w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-150x150.jpg 150w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-768x768.jpg 768w", "sizes": "(max-width: 800px) 100vw, 800px", "name": "pennant-1.jpg", "alt": "" } ], "has_options": false, "is_purchasable": true, "is_in_stock": true, "is_password_protected": false, "low_stock_remaining": null, "add_to_cart": { "text": "Add to cart", "description": "Add “WordPress Pennant” to your cart" } } ] ``` ## Single Product by ID Get a single product by id. ```http GET /products/:id ``` | Attribute | Type | Required | Description | | :-------- | :------ | :------: | :--------------------------------- | | `id` | integer | Yes | The ID of the product to retrieve. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/34" ``` **Example response:** ```json { "id": 34, "name": "WordPress Pennant", "slug": "wordpress-pennant", "variation": "", "permalink": "https://local.wordpress.test/product/wordpress-pennant/", "sku": "wp-pennant", "summary": "

This is an external product.

", "short_description": "

This is an external product.

", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

", "on_sale": false, "prices": { "currency_code": "GBP", "currency_symbol": "£", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "£", "currency_suffix": "", "price": "1105", "regular_price": "1105", "sale_price": "1105", "price_range": null }, "average_rating": "0", "review_count": 0, "images": [ { "id": 57, "src": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1.jpg", "thumbnail": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-324x324.jpg", "srcset": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1.jpg 800w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-324x324.jpg 324w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-100x100.jpg 100w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-416x416.jpg 416w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-300x300.jpg 300w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-150x150.jpg 150w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-768x768.jpg 768w", "sizes": "(max-width: 800px) 100vw, 800px", "name": "pennant-1.jpg", "alt": "" } ], "has_options": false, "is_purchasable": true, "is_in_stock": true, "is_password_protected": false, "low_stock_remaining": null, "add_to_cart": { "text": "Add to cart", "description": "Add “WordPress Pennant” to your cart" } } ``` ## Single Product by slug Get a single product by slug. ```http GET /products/:slug ``` | Attribute | Type | Required | Description | | :-------- | :----- | :------: | :----------------------------------- | | `slug` | string | Yes | The slug of the product to retrieve. | ```sh curl "https://example-store.com/wp-json/wc/store/v1/products/wordpress-pennant" ``` **Example response:** ```json { "id": 34, "name": "WordPress Pennant", "slug": "wordpress-pennant", "variation": "", "permalink": "https://local.wordpress.test/product/wordpress-pennant/", "sku": "wp-pennant", "summary": "

This is an external product.

", "short_description": "

This is an external product.

", "description": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

", "on_sale": false, "prices": { "currency_code": "GBP", "currency_symbol": "£", "currency_minor_unit": 2, "currency_decimal_separator": ".", "currency_thousand_separator": ",", "currency_prefix": "£", "currency_suffix": "", "price": "1105", "regular_price": "1105", "sale_price": "1105", "price_range": null }, "average_rating": "0", "review_count": 0, "images": [ { "id": 57, "src": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1.jpg", "thumbnail": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-324x324.jpg", "srcset": "https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1.jpg 800w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-324x324.jpg 324w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-100x100.jpg 100w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-416x416.jpg 416w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-300x300.jpg 300w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-150x150.jpg 150w, https://local.wordpress.test/wp-content/uploads/2020/03/pennant-1-768x768.jpg 768w", "sizes": "(max-width: 800px) 100vw, 800px", "name": "pennant-1.jpg", "alt": "" } ], "has_options": false, "is_purchasable": true, "is_in_stock": true, "is_password_protected": false, "low_stock_remaining": null, "add_to_cart": { "text": "Add to cart", "description": "Add “WordPress Pennant” to your cart" } } ``` ## Product Links and Embedding Product responses include `_links` that provide URLs to related resources. When products have upsells, cross-sells, or related products configured, embeddable links are included that can be used with WordPress's `_embed` feature. ### Available Links | Link | Description | Embeddable | | :----------- | :-------------------------------------------------- | :--------: | | `self` | Link to the current product | No | | `collection` | Link to the products collection | No | | `up` | Link to parent product (for variations) | No | | `upsells` | Link to fetch upsell products (if configured) | Yes | | `cross_sells`| Link to fetch cross-sell products (if configured) | Yes | | `related` | Link to fetch related products | Yes | ### Example Response with Links ```json { "id": 34, "name": "WordPress Pennant", "_links": { "self": [{"href": "https://local.wordpress.test/wp-json/wc/store/v1/products/34"}], "collection": [{"href": "https://local.wordpress.test/wp-json/wc/store/v1/products"}], "upsells": [{"href": "https://local.wordpress.test/wp-json/wc/store/v1/products?include=10,20", "embeddable": true}], "cross_sells": [{"href": "https://local.wordpress.test/wp-json/wc/store/v1/products?include=30", "embeddable": true}], "related": [{"href": "https://local.wordpress.test/wp-json/wc/store/v1/products?related=34&per_page=10", "embeddable": true}] } } ``` ### Using the `_embed` Parameter Add `?_embed` to any product request to automatically fetch and include the linked resources in an `_embedded` object: ```sh curl "https://local.wordpress.test/wp-json/wc/store/v1/products/34?_embed" ``` **Example response with embedding:** ```json { "id": 34, "name": "WordPress Pennant", "_links": { "self": [{"href": "https://local.wordpress.test/wp-json/wc/store/v1/products/34"}], "collection": [{"href": "https://local.wordpress.test/wp-json/wc/store/v1/products"}], "upsells": [{"href": "https://local.wordpress.test/wp-json/wc/store/v1/products?include=10,20", "embeddable": true}] }, "_embedded": { "upsells": [ {"id": 10, "name": "Upsell Product 1", "...": "..."}, {"id": 20, "name": "Upsell Product 2", "...": "..."} ] } } ``` ## Product Variations By default, Store API excludes product variations. You can retrieve the variations for a product by using the `type=variation`. ```sh curl "https://example-store.com/wp-json/wc/store/v1/products?type=variation" ``` --- ## WooCommerce coding standards *Source: best-practices/coding-standards/coding-standards.md* # WooCommerce coding standards Adhering to WooCommerce coding standards is essential for maintaining high code quality, ensuring compatibility, and facilitating easier maintenance and updates. This document outlines the recommended coding practices for developers working within the WooCommerce ecosystem, including the use of hooks, function prefixing, translatable texts, and code structure. ## Position of hooks Position hooks below the function call to align with the common pattern in the WordPress and WooCommerce ecosystem. Example: ```php /** * Add custom message. */ function YOUR_PREFIX_custom_message() { echo 'This is a custom message'; } add_action( 'wp_footer', 'YOUR_PREFIX_custom_message' ); ``` ## Prefixing function calls Use a consistent prefix for all function calls to avoid conflicts. For the code snippets in this repo, use `YOUR_PREFIX`. Example: ```php /** * Add custom discount. */ function YOUR_PREFIX_custom_discount( $price, $product ) { return $price * 0.9; // 10% discount } add_filter( 'woocommerce_product_get_price', 'YOUR_PREFIX_custom_discount', 10, 2 ); ``` ## Translatable texts and text domains Ensure all plain texts are translatable and use a consistent text domain, adhering to internationalization best practices. For the code snippets in this repo, use the textdomain `YOUR-TEXTDOMAIN`. Example: ```php /** * Add welcome message. */ function YOUR_PREFIX_welcome_message() { echo __( 'Welcome to our website', 'YOUR-TEXTDOMAIN' ); } add_action( 'wp_footer', 'YOUR_PREFIX_welcome_message' ); ``` ## Use of function_exists() To prevent errors from potential function redeclaration, wrap all function calls with `function_exists()`. Example: ```php /** * Add thumbnail support. */ if ( ! function_exists( 'YOUR_PREFIX_theme_setup' ) ) { function YOUR_PREFIX_theme_setup() { add_theme_support( 'post-thumbnails' ); } } add_action( 'after_setup_theme', 'YOUR_PREFIX_theme_setup' ); ``` ## Code quality standards To ensure the highest standards of code quality, developers are encouraged to adhere to the following practices: ### WooCommerce sniffs and WordPress code standards - **Ensure no code style issues** when code is passed through WooCommerce Sniffs and WordPress Code Standards for PHP_CodeSniffer. ### Automated testing - **Unit tests**: Implement automated unit tests to validate code functionality in isolation. - **E2E tests**: Utilize automated end-to-end tests to verify the integrated operation of components within the application. ### Tracking and managing bugs - **Monitor and aim to minimize** the number of open bugs, ensuring a stable and reliable product. ### Code organization - **Organize code in self-contained classes** to avoid creating "god/super classes" that contain all plugin code. This practice promotes modularity and simplifies maintenance. By following these coding standards and practices, developers can create high-quality, maintainable, and secure WooCommerce extensions that contribute positively to the WordPress ecosystem. --- ## CSS/Sass naming conventions *Source: best-practices/coding-standards/css-sass-naming-conventions.md* # CSS/Sass naming conventions ## Introduction Our guidelines are based on those used in [Calypso](https://github.com/Automattic/wp-calypso), which itself follows the [BEM methodology](https://getbem.com/). Refer to the [Calypso CSS/Sass Coding Guidelines](https://wpcalypso.wordpress.com/devdocs/docs/coding-guidelines/css.md) for full details. Read more about [BEM key concepts](https://en.bem.info/methodology/key-concepts/). There are a few differences in WooCommerce which are outlined below. ## Prefixing As a WordPress plugin WooCommerce has to play nicely with WordPress core and other plugins/themes. To minimize conflict potential, all classes should be prefixed with `.woocommerce-`. ## Class names When naming classes, remember: - **Block** - Standalone entity that is meaningful on its own. Such as the name of a component. - **Element** - Parts of a block and have no standalone meaning. They are semantically tied to its block. - **Modifier** - Flags on blocks or elements. Use them to change appearance or behavior. ### Example ```css /* Block */ .woocommerce-loop {} /* Nested block */ .woocommerce-loop-product {} /* Modifier */ .woocommerce-loop-product--sale {} /* Element */ .woocommerce-loop-product__link {} /* Element */ .woocommerce-loop-product__button-add-to-cart {} /* Modifier */ .woocommerce-loop-product__button-add-to-cart--added {} ``` **Note:** `.woocommerce-loop-product` is not named as such because the block is nested within `.woocommerce-loop`. It's to be specific so that we can have separate classes for single products, cart products, etc. **Nested blocks do not need to inherit their parents full name.** ## TL;DR - Follow the [WordPress Coding standards for CSS](https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/) unless it contradicts anything here. - Follow [Calypso guidelines for CSS](https://wpcalypso.wordpress.com/devdocs/docs/coding-guidelines/css.md). - Use BEM for [class names](https://en.bem.info/methodology/naming-convention/). - Prefix all class names. --- ## WooCommerce grammar, punctuation and capitalization guide *Source: best-practices/coding-standards/grammar-punctuation-capitalization.md* # WooCommerce grammar, punctuation and capitalization guide Following grammar, punctuation and style guidelines helps keep our presentation consistent. Users have a better experience if they know what to expect and where to find the information they need. ## Basics **Be democratic**. Some people read every word. Some scan and search or prefer video. Help everyone. **Be focused**. Lead with the most important information in sentences, paragraphs, and sections. **Be concise**. Use plain language and brief sentences. **Be consistent**. Follow our guidelines and style tips. **Be specific**. Communicate crystal clear. Trim the fat. ## Guidelines ### Abbreviations and acronyms Spell out the full version on first mention with abbreviation or acronym in parentheses. Use the short version on second and consecutive mentions. - First use: Payment Card Industry Data Security Standard (PCI-DSS) - Second use: PCI-DSS If the abbreviation or acronym is widely known, use it as is. For example: API, FAQ, HTML, PHP, SQL, SSL. ### Active voice With active voice, the subject in the sentence performs the action. With passive voice, the subject in the sentence has the action done unto it. - Active: Jon downloaded his extension files. - Passive: The extension files were downloaded by Jon. ### Capitalization Cases when we capitalize: - Blog post and documentation article titles: First word. - Documentation headings (h2): Use sentence case (not title case) for docs titles and subheadings. - Product names: Every word except prepositions and conjunctions. - Sentences: First word. - Unordered/Bulleted lists - First word of each entry. Cases when we use lower case: - "ecommerce" (not "eCommerce") - email address - `info@woocommerce.com` - website URL - `developer.woocommerce.com` ### Contractions Use with discretion. Contractions, such as I'm and there's, give writing an informal and conversational feel, but may be inappropriate if content is being translated. For example, sometimes the not in don't is ignored by online translators. ### Emoji Emoji can add subtle emotion and humor or bring visual attention to your content. Use rarely and intentionally. ### Numbers Spell out a number at the start of a sentence, and spell out numbers one through nine in all cases. Use numerals in all other cases. - Ten products will launch in June. Not: 10 products will launch in June. - Lance ran a marathon and won third place in his age group. - I bought five hammers and 21 types of nails for the building project. - There were 18 kinds of beer on tap at the pub. Use a comma for numbers with more than three digits: 41,500, 170,000, 1,000,000 or 1 million. #### Currency Use currency codes and not only the symbol/sign when specifying dollars. Whole amounts need not have a decimal and two places. - USD $20 - CAD $19.99 - AUD $39.50 When writing about other currencies, use the symbol/sign. - €995 - ¥5,000 - £18.99 #### Dates Spell out the day of the week and month, using the format: - Monday, December 12, 2016 #### Decimals Use decimal points when a number is difficult to convert to a fraction, such as 3.141 or 98.5 or 0.29. #### Fractions Spell out fractions: one-fourth #### Percent Spell out the word 'percent.' Don't use % symbol unless space is limited, e.g., for use on social media. #### Phone numbers Use hyphens without spaces between numbers, not parentheses or periods. Use a [country code](https://countrycode.org/) for all countries. - +1-555-867-5309 - +34-902-1899-00 #### Range and span Use a hyphen to indicate a range or span of numbers: 20-30 days. #### Temperature Use the degree symbol and the capital C abbreviation for Celsius and capital F abbreviation for Fahrenheit. - 27°C - 98°F #### Times Use numbers and am or pm with a space and without periods. - 7:00 am - 7:30 pm Use a hyphen between times to indicate a time period in am or pm. Use 'to' if the time period spans am and pm. - 7:00-9:00 am and 7:00 am to 10:30 pm Specify a time zone when writing about an event with potential attendees worldwide. Automattic uses Coordinated Universal Time (UTC). Abbreviate U.S. time zones: - Eastern time: EDT or EST - Central time: CDT or CST - Mountain time: MDT or MST - Pacific time: PDT or PST #### Years Abbreviate decades - 80s and 90s - 1900s and 1890s ### Punctuation #### Ampersands Ampersands need only be used when part of an official company/brand name. Should not be substituted for 'and.' - Ben & Jerry's - Andre, Timo, and Donny went to a football game at Camp Nou. #### Apostrophes An apostrophe makes a word possessive. If a word already ends in s and is singular, add an 's. If a word ends in s and is plural, add an apostrophe. - A teammate borrowed Sam's bike. - A teammate borrowed Chris's bike. - Employees hid the office managers' pens. These are possessives: FAQ's questions, HE's weekly rotation. These are plural: FAQs and HEs. #### Colons Use a colon to create a list. - Aaron ordered three kinds of donuts: glazed, chocolate, and pumpkin. #### Commas Use a serial comma, also known as an Oxford comma, when compiling a list. - Jinny likes sunflowers, daisies, and peonies. Use common sense for other cases. Read the sentence out loud, and use a comma where clarity or pause may be needed. #### Dashes and hyphens Use a hyphen - without spaces on either side to link words, or indicate a span or range. - first-time user - Monday-Friday Use an em dash - without spaces on either side to indicate an aside. Use a true em dash, not hyphens. - Multivariate testing-just one of our new Pro features-can help you grow your business. - Austin thought Brad was the donut thief, but he was wrong-it was Lain. #### Ellipses Ellipses ... can be used to indicate an indefinite ending to a sentence or to show words are omitted when used in brackets [...] Use rarely. #### Exclamation points Use an exclamation point rarely and use only one. Exclamation points follow the same placement convention explained in Periods. #### Periods Periods should be: - Inside quotation marks - Outside parentheses when the portion in parentheses is part of a larger sentence - Inside parentheses when the part in parentheses can stand on its own Examples - Jake said, "I had the best day ever." - She went to the supermarket (and to the nail salon). - My mom loves pizza and beer. (Beer needs to be cold and dark.) #### Question marks Question marks follow the same placement convention explained in Periods. #### Quotation marks Periods and commas go within quotation marks. Question marks within quotes follow logic - if the question mark is part of the quotation, it goes within. If you're asking a question that ends with a quote, it goes outside the quote. Use single quotation marks for quotes within quotes. - Who sings, "All These Things That I've Done"? - Brandon Flowers of The Killers said, "I was inspired and on a roll when I wrote, 'I got soul, but I'm not a soldier.'" #### Semicolons Semicolons can be used to join two related phrases. - Their debut solo album hit the Top 10 in 20 countries; it was #1 in the UK. ### People, places, and things #### Company names and products Use brand identity names and products as written on official websites. - Pull&Bear - UE Boom Refer to a company or product as 'it' (not 'they'). - WooCommerce is, and not WooCommerce are. #### File extensions A file extension type should be all uppercase without periods. Add a lowercase s to make plural. - HTML - JPEG - PDF A specific file should have a lowercase extension type: - dancingcat.gif - SalesReport2016.pdf - firethatcannon.mp3 #### Names and titles First mention of a person should include their first and last name. Second and consecutive mentions can use first name only. Capitalize job titles, the names of teams, and departments. - Happiness Engineers or HEs - Team Apollo - Legal #### Pronouns Use personal pronouns such as he/him/his, she/her/hers, and they/them/theirs as appropriate when referring to a specific person. When talking abstractly (rather than about a specific person), default to they/them/theirs, not he/him/his. For example: "when a developer needs to troubleshoot, they might choose to use Xdebug". Don't use "one" as a pronoun. Instead, use "you" when talking directly to the reader. For example, use "if you encounter an error, you should try deactivating the plugin" rather than "if one encounters an error, they should try deactivating the plugin". #### Quotations Use present tense when quoting someone. - "I love that WooCommerce is free and flexible," says Brent Jamison. #### Schools The first time you mention a school, college, or university in a piece of writing, refer to it by its full official name. On all other mentions, use its more common abbreviation. - Georgia Institute of Technology, Georgia Tech - Georgia State University, GSU #### States, cities, and countries Spell out all city and state names. Don't abbreviate city names. On first mention, write out United States. For further mentions, use U.S. The same applies to other countries or federations with a common abbreviation, such as European Union (EU) and United Kingdom (UK). #### URLs and websites Capitalize the names of websites and web publications. Don't italicize. Avoid writing out URLs; omit `http://www` when it's necessary. ### Slang and jargon Write in plain English. Text should be universally understood, with potential for translation. Briefly define technical terms when needed. ### Text formatting Use italics to indicate the title of a book, movie, or album. - The Oren Klaff book Pitch Anything is on sale for USD $5.99. Avoid: - Underline formatting - A mix of italic, bold, caps, and underline Left-align text, never center or right-aligned. Leave one space between sentences, never two. --- ## Naming conventions *Source: best-practices/coding-standards/naming-conventions.md* # Naming conventions ## PHP WooCommerce core generally follows [WordPress PHP naming conventions](https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#naming-conventions). There are some additional conventions that apply, depending on the location of the code. ### `/src` Classes defined inside `/src` follow the [PSR-4](https://www.php-fig.org/psr/psr-4/) standard. See the [README for `/src`](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/README.md) for more information. The following conventions apply to this directory: - No class name prefix is needed, as all classes in this location live within the `Automattic\WooCommerce` namespace. - Classes are named using `CamelCase` convention. - Functions are named using `snake_case` convention. - Class file names should match the class name. They do not need a `class-` prefix. - The namespace should match the directory structure. - Hooks are prefixed with `woocommerce_`. - Hooks are named using `snake_case` convention. For example, the class defined in `src/Util/StringUtil.php` should be named `StringUtil` and should be in the `Automattic\WooCommerce\Util` namespace. ### `/includes` The `/includes` directory contains legacy code that does not follow the PSR-4 standard. See the [README for `/includes`](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/README.md) for more information. The following conventions apply to this directory: - Class names are prefixed with `WC_`. - Classes are named using `Upper_Snake_Case` convention. - Functions are prefixed with `wc_`. - Functions are named using `snake_case` convention. - Hooks are prefixed with `woocommerce_`. - Hooks are named using `snake_case` convention. Class name examples: - `WC_Cache_Helper` - `WC_Cart` Function name examples: - `wc_get_product()` - `wc_is_active_theme()` Hook name examples (actions or filters): - `woocommerce_after_checkout_validation` - `woocommerce_get_formatted_order_total` ## JS WooCommerce core follows [WordPress JS naming conventions](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/#naming-conventions). As with PHP, function, class, and hook names should be prefixed, but the convention for JS is slightly different. - Global class names are prefixed with `WC`. Class names exported from modules are not prefixed. - Classes are named using `UpperCamelCase` convention. - Global function names are prefixed with `wc`. Function names exported from modules are not prefixed. - Functions are named using `camelCase` convention. - Hooks names are prefixed with `woocommerce`. - Hooks are named using `camelCase` convention. Global class name example: - `WCOrdersTable` Global function name example: - `wcSettings()` Hook name example (actions or filters): - `woocommerceTracksEventProperties` ## CSS and SASS See [CSS/Sass Naming Conventions](./css-sass-naming-conventions.md). --- ## Developing using WooCommerce CRUD objects *Source: best-practices/data-management/crud-objects.md* # Developing using WooCommerce CRUD objects CRUD is an abbreviation of the four basic operations you can do to a database or resource - Create, Read, Update, Delete. [WooCommerce 3.0 introduced CRUD objects](https://woocommerce.wordpress.com/2016/10/27/the-new-crud-classes-in-woocommerce-2-7/) for working with WooCommerce data. **Whenever possible these objects should be used in your code instead of directly updating metadata or using WordPress post objects.** Each of these objects contains a schema for the data it controls (properties), a getter and setter for each property, and a save/delete method which talks to a data store. The data store handles the actual saving/reading from the database. The object itself does not need to be aware of where the data is stored. ## The benefits of CRUD * Structure - Each object has a pre-defined structure and keeps its own data valid. * Control - We control the flow of data, and any validation needed, so we know when changes occur. * Ease of development - As a developer, you don't need to know the internals of the data you're working with, just the names. * Abstraction - The data can be moved elsewhere, e.g. custom tables, without affecting existing code. * Unification - We can use the same code for updating things in admin as we do in the REST API and CLIs. Everything is unified. * Simplified code - Less procedural code to update objects which reduces likelihood of malfunction and adds more unit test coverage. ## CRUD object structure The [`WC_Data`](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/abstracts/abstract-wc-data.php) class is the basic implementation for CRUD objects, and all CRUD objects extend it. The most important properties to note are `$data`, which is an array of props supported in each object, and `$id`, which is the object's ID. The [coupon object class](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/class-wc-coupon.php) is a good example of extending `WC_Data` and adding CRUD functions to all properties. ### Data `$data` stores the property names, and default values: ```php /** * Data array, with defaults. * @since 3.0.0 * @var array */ protected $data = array( 'code' => '', 'amount' => 0, 'date_created' => '', 'date_modified' => '', 'discount_type' => 'fixed_cart', 'description' => '', 'date_expires' => '', 'usage_count' => 0, 'individual_use' => false, 'product_ids' => array(), 'excluded_product_ids' => array(), 'usage_limit' => 0, 'usage_limit_per_user' => 0, 'limit_usage_to_x_items' => 0, 'free_shipping' => false, 'product_categories' => array(), 'excluded_product_categories' => array(), 'exclude_sale_items' => false, 'minimum_amount' => '', 'maximum_amount' => '', 'email_restrictions' => array(), 'used_by' => array(), ); ``` ### Getters and setters Each one of the keys in this array (property) has a getter and setter, e.g. `set_used_by()` and `get_used_by()`. `$data` itself is private, so the getters and setters must be used to access the data. Example getter: ```php /** * Get records of all users who have used the current coupon. * @since 3.0.0 * @param string $context * @return array */ public function get_used_by( $context = 'view' ) { return $this->get_prop( 'used_by', $context ); } ``` Example setter: ```php /** * Set which users have used this coupon. * @since 3.0.0 * @param array $used_by * @throws WC_Data_Exception */ public function set_used_by( $used_by ) { $this->set_prop( 'used_by', array_filter( $used_by ) ); } ``` `set_prop` and `get_prop` are part of `WC_Data`. These apply various filters (based on context) and handle changes, so we can efficiently save only the props that have changed rather than all props. A note on `$context`: when getting data for use on the front end or display, `view` context is used. This applies filters to the data so extensions can change the values dynamically. `edit` context should be used when showing values to edit in the backend, and for saving to the database. Using `edit` context does not apply any filters to the data. ### The constructor The constructor of the CRUD objects facilitates the read from the database. The actual read is not done by the CRUD class, but by its data store. Example: ```php /** * Coupon constructor. Loads coupon data. * @param mixed $data Coupon data, object, ID or code. */ public function __construct( $data = '' ) { parent::__construct( $data ); if ( $data instanceof WC_Coupon ) { $this->set_id( absint( $data->get_id() ) ); } elseif ( is_numeric( $data ) && 'shop_coupon' === get_post_type( $data ) ) { $this->set_id( $data ); } elseif ( ! empty( $data ) ) { $this->set_id( wc_get_coupon_id_by_code( $data ) ); $this->set_code( $data ); } else { $this->set_object_read( true ); } $this->data_store = WC_Data_Store::load( 'coupon' ); if ( $this->get_id() > 0 ) { $this->data_store->read( $this ); } } ``` Note how it sets the ID based on the data passed to the object, then calls the data store to retrieve the data from the database. Once the data is read via the data store, or if no ID is set, `$this->set_object_read( true );` is set so the data store and CRUD object knows it's read. Once this is set, changes are tracked. ### Saving and deleting Save and delete methods are optional on CRUD child classes because the `WC_Data` parent class can handle it. When `save` is called, the data store is used to store data to the database. Delete removes the object from the database. `save` must be called for changes to persist, otherwise they will be discarded. The save method in `WC_Data` looks like this: ```php /** * Save should create or update based on object existence. * * @since 2.6.0 * @return int */ public function save() { if ( $this->data_store ) { // Trigger action before saving to the DB. Allows you to adjust object props before save. do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store ); if ( $this->get_id() ) { $this->data_store->update( $this ); } else { $this->data_store->create( $this ); } return $this->get_id(); } } ``` Update/create is used depending on whether the object has an ID yet. The ID will be set after creation. The delete method is like this: ```php /** * Delete an object, set the ID to 0, and return result. * * @since 2.6.0 * @param bool $force_delete * @return bool result */ public function delete( $force_delete = false ) { if ( $this->data_store ) { $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); $this->set_id( 0 ); return true; } return false; } ``` ## CRUD usage examples ### Creating a new simple product ```php $product = new WC_Product_Simple(); $product->set_name( 'My Product' ); $product->set_slug( 'myproduct' ); $product->set_description( 'A new simple product' ); $product->set_regular_price( '9.50' ); $product->save(); $product_id = $product->get_id(); ``` ### Updating an existing coupon ```php $coupon = new WC_Coupon( $coupon_id ); $coupon->set_discount_type( 'percent' ); $coupon->set_amount( 25.00 ); $coupon->save(); ``` ### Retrieving a customer ```php $customer = new WC_Customer( $user_id ); $email = $customer->get_email(); $address = $customer->get_billing_address(); $name = $customer->get_first_name() . ' ' . $customer->get_last_name(); ``` --- ## Data storage primer *Source: best-practices/data-management/data-storage.md* # Data storage primer When developing for WordPress and WooCommerce, it's important to consider the nature and permanence of your data. This will help you decide the best way to store it. Here's a quick primer: ## Transients If the data may not always be present (i.e., it expires), use a [transient](https://developer.wordpress.org/apis/handbook/transients/). Transients are a simple and standardized way of storing cached data in the database temporarily by giving it a custom name and a timeframe after which it will expire and be deleted. ## WP Cache If the data is persistent but not always present, consider using the [WP Cache](https://developer.wordpress.org/reference/classes/wp_object_cache/). The WP Cache functions allow you to cache data that is computationally expensive to regenerate, such as complex query results. ## wp_options Table If the data is persistent and always present, consider the [wp_options table](https://developer.wordpress.org/apis/handbook/options/). The Options API is a simple and standardized way of storing data in the wp_options table in the WordPress database. ## Post Types If the data type is an entity with n units, consider a [post type](https://developer.wordpress.org/post_type/). Post types are "types" of content that are stored in the same way, but are easy to distinguish in the code and UI. ## Taxonomies If the data is a means of sorting/categorizing an entity, consider a [taxonomy](https://developer.wordpress.org/taxonomy/). Taxonomies are a way of grouping things together. ## Logging Logs should be written to a file using the [WC_Logger](https://woocommerce.com/wc-apidocs/class-WC_Logger.html) class. This is a simple and standardized way of recording events and errors for debugging purposes. Remember, the best method of data storage depends on the nature of the data and how it will be used in your application. --- ## How to manage WooCommerce Data Stores *Source: best-practices/data-management/data-stores.md* # How to manage WooCommerce Data Stores ## Introduction Data store classes act as a bridge between WooCommerce's data CRUD classes (`WC_Product`, `WC_Order`, `WC_Customer`, etc) and the database layer. With the database logic separate from data, WooCommerce becomes more flexible. The data stores shipped with WooCommerce core (powered by WordPress' custom posts system and some custom tables) can be swapped out for a different database structure, type, or even be powered by an external API. This guide will walk through the structure of a data store class, how to create a new data store, how to replace a core data store, and how to call a data store from your own code. The examples in this guide will look at the [`WC_Coupon`](https://github.com/woocommerce/woocommerce/blob/dcecf0f22890f3cd92fbea13a98c11b2537df2a8/includes/class-wc-coupon.php#L19) CRUD data class and [`WC_Coupon_Data_Store_CPT`](https://github.com/woocommerce/woocommerce/blob/dcecf0f22890f3cd92fbea13a98c11b2537df2a8/includes/data-stores/class-wc-coupon-data-store-cpt.php), an implementation of a coupon data store using WordPress custom post types. This is how coupons are currently stored in WooCommerce. The important thing to know about `WC_Coupon` or any other CRUD data class when working with data stores is which props (properties) they contain. This is defined in the [`data`](https://github.com/woocommerce/woocommerce/blob/dcecf0f22890f3cd92fbea13a98c11b2537df2a8/includes/class-wc-coupon.php#L26) array of each class. ## Structure Every data store for a CRUD object should implement the `WC_Object_Data_Store_Interface` interface. `WC_Object_Data_Store_Interface` includes the following methods: * `create` * `read` * `update` * `delete` * `read_meta` * `delete_meta` * `add_meta` * `update_meta` The `create`, `read`, `update`, and `delete` methods should handle the CRUD logic for your props: * `create` should create a new entry in the database. Example: Create a coupon. * `read` should query a single entry from the database and set properties based on the response. Example: Read a coupon. * `update` should make changes to an existing entry. Example: Update or edit a coupon. * `delete` should remove an entry from the database. Example: Delete a coupon. All data stores must implement handling for these methods. In addition to handling your props, other custom data can be passed. This is considered `meta`. For example, coupons can have custom data provided by plugins. The `read_meta`, `delete_meta`, `add_meta`, and `update_meta` methods should be defined so meta can be read and managed from the correct source. In the case of our WooCommerce core classes, we define them in `WC_Data_Store_WP` and then use the same code for all of our data stores. They all use the WordPress meta system. You can redefine these if meta should come from a different source. Your data store can also implement other methods to replace direct queries. For example, the coupons data store has a public `get_usage_by_user_id` method. Data stores should always define and implement an interface for the methods they expect, so other developers know what methods they need to write. Put another way, in addition to the `WC_Object_Data_Store_Interface` interface, `WC_Coupon_Data_Store_CPT` also implements `WC_Coupon_Data_Store_Interface`. ## Replacing a data store Let's look at how we would replace the `WC_Coupon_Data_Store_CPT` class with a `WC_Coupon_Data_Store_Custom_Table` class. Our examples will just provide stub functions, instead of a full working solution. Imagine that we would like to store coupons in a table named `wc_coupons` with the following columns: ```text id, code, amount, date_created, date_modified, discount_type, description, date_expires, usage_count,individual_use, product_ids, excluded_product_ids, usage_limit, usage_limit_per_user, limit_usage_to_x_items, free_shipping, product_categories, excluded_product_categories, exclude_sale_items, minimum_amount, maximum_amount, email_restrictions, used_by ``` These column names match 1 to 1 with prop names. First we would need to create a new data store class to contain our logic: ```php /** * WC Coupon Data Store: Custom Table. */ class WC_Coupon_Data_Store_Custom_Table extends WC_Data_Store_WP implements WC_Coupon_Data_Store_Interface, WC_Object_Data_Store_Interface { } ``` Note that we implement the main `WC_Object_Data_Store_Interface` interface as well as the ` WC_Coupon_Data_Store_Interface` interface. Together, these represent all the methods we need to provide logic for. We would then define the CRUD handling for these properties: ```php /** * Method to create a new coupon in the database. * * @param WC_Coupon */ public function create( &$coupon ) { $coupon->set_date_created( current_time( 'timestamp' ) ); /** * This is where code for inserting a new coupon would go. * A query would be built using getters: $coupon->get_code(), $coupon->get_description(), etc. * After the INSERT operation, we want to pass the new ID to the coupon object. */ $coupon->set_id( $coupon_id ); // After creating or updating an entry, we need to also cause our 'meta' to save. $coupon->save_meta_data(); // Apply changes let's the object know that the current object reflects the database and no "changes" exist between the two. $coupon->apply_changes(); // It is helpful to provide the same hooks when an action is completed, so that plugins can interact with your data store. do_action( 'woocommerce_new_coupon', $coupon_id ); } /** * Method to read a coupon. * * @param WC_Coupon */ public function read( &$coupon ) { $coupon->set_defaults(); // Read should do a check to see if this is a valid coupon // and otherwise throw an 'Invalid coupon.' exception. // For valid coupons, set $data to contain our database result. // All props should be set using set_props with output from the database. This "hydrates" the CRUD data object. $coupon_id = $coupon->get_id(); $coupon->set_props( array( 'code' => $data->code, 'description' => $data->description, // .. ) ); // We also need to read our meta data into the object. $coupon->read_meta_data(); // This flag reports if an object has been hydrated or not. If this ends up false, the database hasn't correctly set the object. $coupon->set_object_read( true ); do_action( 'woocommerce_coupon_loaded', $coupon ); } /** * Updates a coupon in the database. * * @param WC_Coupon */ public function update( &$coupon ) { // Update coupon query, using the getters. $coupon->save_meta_data(); $coupon->apply_changes(); do_action( 'woocommerce_update_coupon', $coupon->get_id() ); } /** * Deletes a coupon from the database. * * @param WC_Coupon * @param array $args Array of args to pass to the delete method. */ public function delete( &$coupon, $args = array() ) { // A lot of objects in WordPress and WooCommerce support // the concept of trashing. This usually is a flag to move the object // to a "recycling bin". Since coupons support trashing, your layer should too. // If an actual delete occurs, set the coupon ID to 0. $args = wp_parse_args( $args, array( 'force_delete' => false, ) ); $id = $coupon->get_id(); if ( $args['force_delete'] ) { // Delete Query $coupon->set_id( 0 ); do_action( 'woocommerce_delete_coupon', $id ); } else { // Trash Query do_action( 'woocommerce_trash_coupon', $id ); } } ``` We are extending `WC_Data_Store_WP` so our classes will continue to use WordPress' meta system. As mentioned in the structure section, we are responsible for implementing the methods defined by `WC_Coupon_Data_Store_Interface`. Each interface describes the methods and parameters it accepts, and what your function should do. A coupons replacement would look like the following: ```php /** * Increase usage count for current coupon. * * @param WC_Coupon * @param string $used_by Either user ID or billing email */ public function increase_usage_count( &$coupon, $used_by = '' ) { } /** * Decrease usage count for current coupon. * * @param WC_Coupon * @param string $used_by Either user ID or billing email */ public function decrease_usage_count( &$coupon, $used_by = '' ) { } /** * Get the number of uses for a coupon by user ID. * * @param WC_Coupon * @param id $user_id * @return int */ public function get_usage_by_user_id( &$coupon, $user_id ) { } /** * Return a coupon code for a specific ID. * @param int $id * @return string Coupon Code */ public function get_code_by_id( $id ) { } /** * Return an array of IDs for for a specific coupon code. * Can return multiple to check for existence. * @param string $code * @return array Array of IDs. */ public function get_ids_by_code( $code ) { } ``` Once all the data store methods are defined and logic written, we need to tell WooCommerce to load our new class instead of the built-in class. This is done using the `woocommerce_data_stores` filter. An array of data store slugs is mapped to default WooCommerce classes. Example: ```php 'coupon' => 'WC_Coupon_Data_Store_CPT', 'customer' => 'WC_Customer_Data_Store', 'customer-download' => 'WC_Customer_Download_Data_Store', 'customer-session' => 'WC_Customer_Data_Store_Session', 'order' => 'WC_Order_Data_Store_CPT', 'order-refund' => 'WC_Order_Refund_Data_Store_CPT', 'order-item' => 'WC_Order_Item_Data_Store', 'order-item-coupon' => 'WC_Order_Item_Coupon_Data_Store', 'order-item-fee' => 'WC_Order_Item_Fee_Data_Store', 'order-item-product' => 'WC_Order_Item_Product_Data_Store', 'order-item-shipping' => 'WC_Order_Item_Shipping_Data_Store', 'order-item-tax' => 'WC_Order_Item_Tax_Data_Store', 'payment-token' => 'WC_Payment_Token_Data_Store', 'product' => 'WC_Product_Data_Store_CPT', 'product-grouped' => 'WC_Product_Grouped_Data_Store_CPT', 'product-variable' => 'WC_Product_Variable_Data_Store_CPT', 'product-variation' => 'WC_Product_Variation_Data_Store_CPT', 'shipping-zone' => 'WC_Shipping_Zone_Data_Store', ``` We specifically want to target the coupon data store, so we would do something like this: ```php function myplugin_set_wc_coupon_data_store( $stores ) { $stores['coupon'] = 'WC_Coupon_Data_Store_Custom_Table'; return $stores; } add_filter( 'woocommerce_data_stores', 'myplugin_set_wc_coupon_data_store' ); ``` Our class would then be loaded by WooCommerce core, instead of `WC_Coupon_Data_Store_CPT`. ## Creating a new data store ### Defining a new product type Does your extension create a new product type? Each product type has a data store in addition to a parent product data store. The parent store handles shared properties like name or description and the child handles more specific data. For example, the external product data store handles "button text" and "external URL". The variable data store handles the relationship between parent products and their variations. Check out [this walkthrough](https://developer.woocommerce.com/2017/02/06/wc-2-7-extension-compatibility-examples-3-bookings/) for more information on this process. ### Data store for custom data If your extension introduces a new database table, new custom post type, or some new form of data not related to products, orders, etc, then you should implement your own data store. Your data store should still implement `WC_Object_Data_Store_Interface` and provide the normal CRUD functions. Your data store should be the main point of entry for interacting with your data, so any other queries or operations should also have methods. The [shipping zone data store](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/data-stores/class-wc-shipping-zone-data-store.php) serves as a good example for a "simple" data store using a custom table. The coupons code is a good example for a data store using a custom post type. All you need to do to register your data store is add it to the `woocommerce_data_stores` filter: ```php function myplugin_set_my_custom_data_store( $stores ) { $stores['mycustomdata'] = 'WC_My_Custom_Data_Store'; return $stores; } add_filter( 'woocommerce_data_stores', 'myplugin_set_my_custom_data_store' ); ``` You can then load your data store like any other WooCommerce data store. ## Calling a data store Calling a data store is as simple as using the static `WC_Data_Store::load()` method: ```php // Load the shipping zone data store. $data_store = WC_Data_Store::load( 'shipping-zone' ); // Get the number of shipping methods for zone ID 4. $num_of_methods = $data_store->get_method_count( 4 ); ``` You can also chain methods: ```php // Get the number of shipping methods for zone ID 4. $num_of_methods = WC_Data_Store::load( 'shipping-zone' )->get_method_count( 4 ); ``` The `::load()` method works for any data store registered to `woocommerce_data_stores`, so you could load your custom data store: ```php $data_store = WC_Data_Store::load( 'mycustomdata' ); ``` ## Data store limitations and WP Admin Currently, several WooCommerce screens still rely on WordPress to list objects. Examples of this include coupons and products. If you replace data via a data store, some parts of the existing UI may fail. An example of this may be lists of coupons when using the `type` filter. This filter uses meta data, and is in turn passed to WordPress which runs a query using the `WP_Query` class. This cannot handle data outside of the regular meta tables (Ref #19937). To get around this, usage of `WP_Query` would need to be deprecated and replaced with custom query classes and functions. --- ## Logging in WooCommerce *Source: best-practices/data-management/logging.md* # Logging in WooCommerce WooCommerce has its own robust system for logging, which can be used for debugging during development, catching errors on production, or even sending notifications when specific events occur. By default, WooCommerce uses this logger to record errors, warnings, and other notices that may be useful for troubleshooting problems with a store. Many extensions for WooCommerce also make use of the logger for similar purposes. ## Viewing logs You can view the entries created by the logger by going to **WooCommerce > Status > Logs**. The log viewing interface depends on which log storage method is configured (see the "Configuring the logger" section below). ### File system With the default file system storage method, the first thing you will see is the list of existing log files: ![The default log viewing interface, showing a list of log files](/img/doc_images/file-browse.png) The name of a log file is based on the source of the entries it contains (meaning the extension or the part of the WooCommerce codebase), as well as the date the entries were generated. In this file browsing view, you can sort the files in different ways as well as filtering them to show only those from a specific source. Clicking on a file will take you to a single file view, where you can see the actual log entries: ![The contents of a log file](/img/doc_images/file-view-new.png) Click on a line number in the file to highlight it. This can also be used to link to a specific line in a file from elsewhere. From the file browser view, you can sort and filter a list of log files, and then search for a string within the contents of those files: ![A list of search results](/img/doc_images/search-results.png) Clicking on a search result line number will take you to that line in the single file view. ### Database With the database storage method, you will see a list of log entries, starting with the most recent: ![The log viewing interface when log entries are stored in the database](/img/doc_images/database-logs.png) These entries can be sorted by timestamp, level, and source, as well as filtered to only show a particular source or a minimum level. You can also search for a string within the log entry message fields. ## Configuring the logger From the Logs screen at **WooCommerce > Status > Logs**, click the "Settings" link to make configuration changes: ![The Logs settings screen](/img/doc_images/settings.png) ### Logger Uncheck the box here to turn off all logging. This is not recommended in most circumstances, as logging can provide valuable information about what is happening on your site! ### Log storage Out-of-the-box, WooCommerce has two different log storage methods available: * **File system** - Log entries are recorded to files. Files are differentiated by the `source` value for the log entry (see the "Adding logs" section below), and by the current date. The files are stored in the `wc-logs` subdirectory of the site's `uploads` directory. A custom directory can be defined using the `woocommerce_log_directory` filter hook. Log files can be up to 5 MB in size, after which the log file will rotate. * **Database** - Log entries are recorded to the database, in the `{$wpdb->prefix}woocommerce_log` table. If you change this setting, and you already have some log entries, those entries will not be migrated to the other storage method, but neither will they be deleted. ### Retention period The logger will periodically go through and delete logs that are older than this time period, as a space-saving measure. If log entries are stored in the file system, the entire log file that is beyond the retention period will be deleted, while with database storage, individual log entries will be deleted. ### Level threshold Each log entry has a severity level (see the "Adding logs" section below). This sets a minimum severity level, and any log entries that are generated that are not at or above the minimum level will not be recorded. Use this setting with caution! If this setting is set to "None", it means that all log entries will be recorded, regardless of severity level. ## Adding logs Logs are added via methods in the `WC_Logger` class. The class instance is accessed by using the `wc_get_logger()` function. The basic method for adding a log entry is [`WC_Logger::log( $level, $message, $context )`](https://woocommerce.github.io/code-reference/classes/WC-Logger.html#method_log). There are also shortcut methods for each log severity level, for example `WC_Logger::warning( $message, $context )`. It is preferable to use the shortcut methods rather than the generic `log` method. ### Level Logs have eight different severity levels: * `emergency` * `alert` * `critical` * `error` * `warning` * `notice` * `info` * `debug` Aside from giving a site owner context as to how important a log entry is, these levels also allow logs to be filtered. If you only want log entries to be recorded for `error` severity and higher, you can set the threshold on the Logs Settings screen (see the "Configuring the logger" above). Note that this threshold will apply to all logs, regardless of which log handler is in use. The `WC_Log_Handler_Email` class, for example, has its own threshold setting, but it is secondary to the global threshold. ### Message The message is the main content of a log entry. Make sure it's understandable by anyone who might be viewing the logs! ### Context The context parameter is intended to be used to store additional structured data related to the log entry. For example, in a log entry about an order, you may want to include contents of the related order object. When the logger is generating an entry, the data in the context parameter is converted to JSON before it is stored. So, if you want to add multiple pieces of context data, each should be added as a separate key within the context array. There are two specific keys that can be added to the context array that will cause special behavior: #### `source` It is recommended that every log entry include a `source` value in the context parameter. `source` is intended to provide context about where in the application or codebase the log was generated, and can be used to filter log entries. If a source is not specified, the logger will generate a source value based on the plugin or file where the log entry was generated. #### `backtrace` Setting the `backtrace` key in your context parameter to `true` will cause the logger to generate a backtrace (i.e. stack trace) in array format, which will be included in the context in place of the `true` value. This is useful particularly for error-related logs, so you can see what code was executed that led to the log entry being generated. ![A backtrace displayed in the log file viewer](/img/doc_images/backtrace.png) ### Full example ```php wc_get_logger()->info( 'It is time for lunch.', array( 'source' => 'your_stomach', 'backtrace' => true, 'previous_meal' => $elapsed_time_since_breakfast, 'lunch_options' => array( 'fridge leftovers', 'bahn mi', 'tacos', 'pupusas' ), ) ); ``` ## Logging best practices ### When to use logging * To help troubleshoot an unexpected problem: * An unexpected value or error is received from an API. * Data in the system is incorrect or corrupted. * The application is in an unexpected or broken state. * To keep an audit log of a process: * Transaction details not stored elsewhere, like an order note (but maybe they should be?) * Results of data import or export. * An important setting is changed. * An automated process changes or deletes data. ### When _not_ to use logging * To let a developer know that they're using a method or API incorrectly. This can lead to a large volume of useless log entries, especially if it will get triggered on every page request. Better to give them immediate feedback in the form of an error or exception (e.g. `wc_doing_it_wrong()`). ### Best practices * Rather than using the `WC_Logger`'s `log()` method directly, it's better to use one of the wrapper methods that's specific to the log level. E.g. `info()` or `error()`. * Write a message that is a complete, coherent sentence. This will make it more useful for people who aren't familiar with the codebase. * Log messages should not be translatable. Keeping the message in English makes it easier to search for solutions based on the message contents, and also makes it easier for anyone troubleshooting to understand what's happening, since they may not speak the same language as the site owner. * Ideally, each log entry message should be a single line (i.e. no line breaks within the message string). Additional lines or extra data should be put in the context array. * Avoid outputting structured data in the message string. Put it in a key in the context array instead. The logger will handle converting it to JSON and making it legible in the log viewer. * If you need to include a stack trace, let the logger generate it for you. * Decide on a source for the component or system you are working on and use it for every log call you make. This will make it easier to find all the log entries that are related to the component, and filter them out from other, unrelated log entries. * Consider adding one log entry after a looped process with the aggregated results of the loop, rather than adding a separate entry during each item within a loop. ## Customizing the logger ### The logger class The `WC_Logger` class can be substituted for another class via the `woocommerce_logging_class` filter hook. The alternative class must implement [`WC_Logger_Interface`](https://woocommerce.github.io/code-reference/classes/WC-Logger-Interface.html), or it will not be used. Generally it is better to create a custom log handler (see below) rather than overriding the logger class itself. ### Log handlers In WooCommerce, a log handler is a PHP class that takes the raw log data and transforms it into a log entry that can be stored or dispatched. WooCommerce ships with four different log handler classes: * `Automattic\\WooCommerce\\Internal\\Admin\\Logging\\LogHandlerFileV2`: This is the default handler, representing the "file system" log storage method. It records log entries to files. * `WC_Log_Handler_File`: This is the old default handler that also records log entries to files. It may be deprecated in the future, and it is not recommended to use this class or extend it. * `WC_Log_Handler_DB`: This handler represents the "database" log storage method. It records log entries to the database. * `WC_Log_Handler_Email`: This handler does not store log entries, but instead sends them as email messages. Emails are sent to the site admin email address. This handler has [some limitations](https://github.com/woocommerce/woocommerce/blob/fe81a4cf27601473ad5c394a4f0124c785aaa4e6/plugins/woocommerce/includes/log-handlers/class-wc-log-handler-email.php#L15-L27). #### Changing or adding handlers To switch from the file handler to the database handler, you can simply update the option on the Logs Settings screen. However, in some cases, you may want to have more than one log handler, and/or you might want to modify the settings of a handler. For example, you may want to have most logs saved to files, but log entries that are classified as emergency or critical errors also sent to an email address. For this, you can use the `woocommerce_register_log_handlers` filter hook to create an array of log handler class instances that you want to use. Some handler class constructors have optional parameters that you can use when instantiating the class to change their default behavior. Here's an example of adding the email handler: ```php function my_wc_log_handlers( $handlers ) { $recipients = array( 'wayne@example.com', 'garth@example.com' ); // Send logs to multiple recipients. $threshold = 'critical'; // Only send emails for logs of this level and higher. $handlers[] = new WC_Log_Handler_Email( $recipients, $threshold ); return $handlers; } add_filter( 'woocommerce_register_log_handlers', 'my_wc_log_handlers' ); ``` #### Creating a custom handler You may want to create your own log handler class in order to send logs somewhere else, such as a Slack channel or perhaps an InfluxDB instance. Your class must extend the [`WC_Log_Handler`](https://woocommerce.github.io/code-reference/classes/WC-Log-Handler.html) abstract class and implement the [`WC_Log_Handler_Interface`](https://woocommerce.github.io/code-reference/classes/WC-Log-Handler-Interface.html) interface. The [`WC_Log_Handler_Email`](https://github.com/woocommerce/woocommerce/blob/6688c60fe47ad42d49deedab8be971288e4786c1/plugins/woocommerce/includes/log-handlers/class-wc-log-handler-email.php) handler class provides a good example of how to set this up. ### Log file storage location When using the "file system" log handler, by default the log files are stored in the `wc-logs` subdirectory of the WordPress `uploads` directory, which means they might be publicly accessible. WooCommerce adds an `.htaccess` file to prevent access to `wc-logs`, but not all web servers recognize that file. If you have the option, you may want to consider storing your log files in a directory outside of the web root. Make sure the directory has the same user/group permissions as the `uploads` directory so that WordPress can access it. Then use the `woocommerce_log_directory` filter hook to set the path to your custom directory. ### Turning off noisy logs If there is a particular log that is recurring frequently and clogging up your log files, you should probably figure out why it keeps getting triggered and resolve the issue. However, if that's not possible, you can add a callback to the `woocommerce_logger_log_message` filter hook to ignore that particular log while still allowing other logs to get through: ```php function my_ignored_logs( $message, $level, $context, $handler ) { if ( false !== strpos( $message, 'Look, a squirrel!' ) ) { return null; } return $message; } add_filter( 'woocommerce_logger_log_message', 'my_ignored_logs', 10, 4 ); ``` ### The Logs UI If you create a custom log handler and you want to build a separate interface for it on the Logs screen, there are a couple of filter hooks that you can work with: * `woocommerce_logger_handler_options`: This filter hook allows you to add your custom log handler to the list of "Log storage" options on the Settings screen. Your handler must be selected for this setting, making it the "default" log handler, before you can render an alternative interface for it. * `wc_logs_render_page`: This is the action to hook into for rendering your own Logs interface. It only fires if the default log handler is set to something that is not one of the built-in handlers. * `wc_logs_load_tab`: This action fires when the Logs tab first starts loading, before any content is output. It's useful for handling form submissions. --- ## How to configure caching plugins for WooCommerce *Source: best-practices/performance/configuring-caching-plugins.md* # How to configure caching plugins for WooCommerce ## Excluding pages from the cache Oftentimes if using caching plugins they'll already exclude these pages. Otherwise make sure you exclude the following pages from the cache through your caching systems respective settings. - Cart - My Account - Checkout These pages need to stay dynamic since they display information specific to the current customer and their cart. ## Excluding WooCommerce session from the cache If the caching system you're using offers database caching, it might be helpful to exclude `_wc_session_` from being cached. This will be dependent on the plugin or host caching so refer to the specific instructions or docs for that system. ## Excluding WooCommerce cookies from the cache Cookies in WooCommerce help track the products in your customers cart, can keep their cart in the database if they leave the site, and powers the recently viewed widget. Below is a list of the cookies WooCommerce uses for this, which you can exclude from caching. | COOKIE NAME | DURATION | PURPOSE | | --- | --- | --- | | woocommerce_cart_hash | session | Helps WooCommerce determine when cart contents/data changes. | | woocommerce_items_in_cart | session | Helps WooCommerce determine when cart contents/data changes. | | wp_woocommerce_session_ | 2 days | Contains a unique code for each customer so that it knows where to find the cart data in the database for each customer. | | woocommerce_recently_viewed | session | Powers the Recent Viewed Products widget. | | store_notice[notice id] | session | Allows customers to dismiss the Store Notice. | We're unable to cover all options, but we have added some tips for the popular caching plugins. For more specific support, please reach out to the support team responsible for your caching integration. ### W3 total cache minify settings Ensure you add 'mfunc' to the 'Ignored comment stems' option in the Minify settings. ### WP-Rocket WooCommerce is fully compatible with WP-Rocket. Please ensure that the following pages (Cart, Checkout, My Account) are not to be cached in the plugin's settings. We recommend avoiding JavaScript file minification. ### WP Super Cache WooCommerce is natively compatible with WP Super Cache. WooCommerce sends information to WP Super Cache so that it doesn't cache the Cart, Checkout, or My Account pages by default. ### Varnish ```varnish if (req.url ~ "^/(cart|my-account|checkout|addons)") { return (pass); } if ( req.url ~ "\\?add-to-cart=" ) { return (pass); } ``` ## Troubleshooting ### Why is my Varnish configuration not working in WooCommerce? Check out the following WordPress.org Support forum post on[ how cookies may be affecting your varnish coding](https://wordpress.org/support/topic/varnish-configuration-not-working-in-woocommerce). ```text Add this to vcl_recv above "if (req.http.cookie) {": # Unset Cookies except for WordPress admin and WooCommerce pages if (!(req.url ~ "(wp-login|wp-admin|cart|my-account/*|wc-api*|checkout|addons|logout|lost-password|product/*)")) { unset req.http.cookie; } # Pass through the WooCommerce dynamic pages if (req.url ~ "^/(cart|my-account/*|checkout|wc-api/*|addons|logout|lost-password|product/*)") { return (pass); } # Pass through the WooCommerce add to cart if (req.url ~ "\?add-to-cart=" ) { return (pass); } # Pass through the WooCommerce API if (req.url ~ "\?wc-api=" ) { return (pass); } # Block access to php admin pages via website if (req.url ~ "^/phpmyadmin/.*$" || req.url ~ "^/phppgadmin/.*$" || req.url ~ "^/server-status.*$") { error 403 "For security reasons, this URL is only accessible using localhost (127.0.0.1) as the hostname"; } Add this to vcl_fetch: # Unset Cookies except for WordPress admin and WooCommerce pages if ( (!(req.url ~ "(wp-(login|admin)|login|cart|my-account/*|wc-api*|checkout|addons|logout|lost-password|product/*)")) || (req.request == "GET") ) { unset beresp.http.set-cookie; } ``` ### Why is my Password Reset stuck in a loop? This is due to the My Account page being cached, Some hosts with server-side caching don't prevent my-account.php from being cached. If you're unable to reset your password and keep being returned to the login screen, please speak to your host to make sure this page is being excluded from their caching. --- ## Performance best practices for WooCommerce extensions *Source: best-practices/performance/performance-best-practices.md* # Performance best practices for WooCommerce extensions Optimizing the performance of WooCommerce extensions is vital for ensuring that online stores run smoothly, provide a superior user experience, and rank well in search engine results. This guide is tailored for developers looking to enhance the speed and efficiency of their WooCommerce extensions, with a focus on understanding performance impacts, benchmarking, testing, and implementing strategies for improvement. ## Performance optimization For WooCommerce extensions, performance optimization means ensuring that your code contributes to a fast, responsive user experience without adding unnecessary load times or resource usage to the store. ### Why performance is critical - **User Experience**: Fast-performing extensions contribute to a seamless shopping experience, encouraging customers to complete purchases. - **Store Performance**: Extensions can significantly impact the overall speed of WooCommerce stores; optimized extensions help maintain optimal site performance. - **SEO and Conversion Rates**: Speed is a critical factor for SEO rankings and conversion rates. Efficient extensions support better store rankings and higher conversions. ## Benchmarking performance Setting clear performance benchmarks is essential for development and continuous improvement of WooCommerce extensions. A recommended performance standard is achieving a Chrome Core Web Vitals "Performance" score of 90 or above on a simple Woo site, using tools like the [Chrome Lighthouse](https://developer.chrome.com/docs/lighthouse/overview/). ### Using accessible tools for benchmarking Chrome Lighthouse provides a comprehensive framework for evaluating the performance of web pages, including those impacted by your WooCommerce extension. By integrating Lighthouse testing into your development workflow, you can identify and address performance issues early on. We recommend leveraging tools like this to assess the impact of your extension on a WooCommerce store's performance and to identify areas for improvement. ## Performance improvement strategies Optimizing the performance of WooCommerce extensions can involve several key strategies: - **Optimize asset loading**: Ensure that scripts and styles are loaded conditionally, only on pages where they're needed. - **Efficient database queries**: Optimize database interactions to minimize query times and resource usage. Use indexes appropriately and avoid unnecessary data retrieval. - **Lazy Loading**: Implement lazy loading for images and content loaded by your extension to reduce initial page load times. - **Minification and concatenation**: Minify CSS and JavaScript files and concatenate them where possible to reduce the number of HTTP requests. - **Testing with and without your extension**: Regularly test WooCommerce stores with your extension activated and deactivated to clearly understand its impact on performance. - **Caching support**: Ensure your extension is compatible with popular caching solutions, and avoid actions that might bypass or clear cache unnecessarily. By following these best practices and regularly benchmarking and testing your extension, you can ensure it enhances, rather than detracts from, the performance of WooCommerce stores. Implementing these strategies will lead to more efficient, faster-loading extensions that store owners and their customers will appreciate. --- ## How to optimize performance for WooCommerce stores *Source: best-practices/performance/performance-optimization.md* # How to optimize performance for WooCommerce stores ## Introduction This guide covers best practices and techniques for optimizing the performance of WooCommerce stores, including caching, image optimization, database maintenance, code minification, and the use of Content Delivery Networks (CDNs). By following these recommendations, developers can build high-performing WooCommerce stores that provide a better user experience and contribute to higher conversion rates. ## Audience This guide is intended for developers who are familiar with WordPress and WooCommerce and want to improve the performance of their online stores. ## Prerequisites To follow this guide, you should have: 1. A basic understanding of WordPress and WooCommerce. 2. Access to a WordPress website with WooCommerce installed and activated. ## Step 1 - Implement caching Caching plays a crucial role in speeding up your WooCommerce store by serving static versions of your pages to visitors, reducing the load on your server. There are several ways to implement caching for your WooCommerce store: ### Server-Side caching Enable server-side caching through your hosting provider or by using server-level caching solutions like Varnish, NGINX FastCGI Cache, or Redis. ### WordPress caching plugins Install and configure a WordPress caching plugin, such as WP Rocket, W3 Total Cache, or WP Super Cache. These plugins can help you set up page caching, browser caching, and object caching for your WooCommerce store. ### WooCommerce-Specific caching Ensure that your caching solution is configured correctly for WooCommerce, allowing dynamic content such as cart and checkout pages to remain uncached. Some caching plugins, like WP Rocket, include built-in support for WooCommerce caching. ## Step 2 - Optimize images Optimizing images can significantly improve your store's performance by reducing the size of image files without compromising quality. To optimize images for your WooCommerce store: 1. Use the right image format: Choose an appropriate format for your images, such as JPEG for photographs and PNG for graphics with transparency. 2. Compress images: Use an image compression tool like TinyPNG or ShortPixel to reduce file sizes before uploading them to your store. 3. Enable lazy loading: Lazy loading delays the loading of images until they're needed, improving initial page load times. Many caching plugins and performance optimization plugins offer built-in lazy loading options. 4. Use responsive images: Ensure that your theme and plugins serve appropriately sized images for different devices and screen resolutions. ## Step 3 - Minify and optimize code Minifying and optimizing your store's HTML, CSS, and JavaScript files can help reduce file sizes and improve page load times. To minify and optimize code for your WooCommerce store: 1. Use a plugin: Install a performance optimization plugin like Autoptimize, WP Rocket, or W3 Total Cache to minify and optimize your store's HTML, CSS, and JavaScript files. 2. Combine and inline critical CSS: Where possible, combine and inline critical CSS to reduce the number of requests and improve page load times. 3. Defer non-critical JavaScript: Defer loading of non-critical JavaScript files to improve perceived page load times. ## Step 4 - Use a content delivery network (CDN) A Content Delivery Network (CDN) can help speed up your WooCommerce store by serving static assets like images, CSS, and JavaScript files from a network of servers distributed across the globe. To use a CDN for your WooCommerce store: 1. Choose a CDN provider: Select a CDN provider like Cloudflare, Fastly, or Amazon CloudFront that fits your needs and budget. 2. Set up your CDN: Follow your chosen CDN provider's instructions to set up and configure the CDN for your WooCommerce store. ## Step 5 - Optimize database Regularly optimizing your WordPress database can help improve your WooCommerce store's performance by removing unnecessary data and optimizing database tables. To optimize your database: 1. Use a plugin: Install a database optimization plugin like WP-Optimize, WP-Sweep, or Advanced Database Cleaner to clean up and optimize your WordPress database. 2. Remove unnecessary data: Regularly delete spam comments, post revisions, and expired transients to reduce database clutter. 3. Optimize database tables: Use the database optimization plugin to optimize your database tables, improving their efficiency and reducing query times. ## Step 6 - Choose a high-performance theme and plugins The theme and plugins you choose for your WooCommerce store can have a significant impact on performance. To ensure your store runs efficiently: 1. Select a lightweight, performance-optimized theme: Choose a theme specifically designed for WooCommerce that prioritizes performance and follows best coding practices. 2. Evaluate plugin performance: Use tools like Query Monitor or WP Hive to analyze the performance impact of the plugins you install, and remove or replace those that negatively affect your store's performance. ## Step 7 - Enable GZIP compression GZIP compression can help reduce the size of your store's HTML, CSS, and JavaScript files, leading to faster page load times. To enable GZIP compression: 1. Use a plugin: Install a performance optimization plugin like WP Rocket, W3 Total Cache, or WP Super Cache that includes GZIP compression options. 2. Configure your server: Alternatively, enable GZIP compression directly on your server by modifying your .htaccess file (for Apache servers) or nginx.conf file (for NGINX servers). ## Step 8 - Monitor and analyze performance Continuously monitor and analyze your WooCommerce store's performance to identify potential bottlenecks and areas for improvement. To monitor and analyze performance: 1. Use performance testing tools: Regularly test your store's performance using tools like Google PageSpeed Insights, GTmetrix, or WebPageTest. 2. Implement performance monitoring: Install a performance monitoring plugin like New Relic or use a monitoring service like Uptime Robot to keep track of your store's performance over time. ## Conclusion By following these best practices and techniques for performance optimization, you can build a high-performing WooCommerce store that offers a better user experience and contributes to higher conversion rates. Continuously monitor and analyze your store's performance to ensure it remains optimized as your store grows and evolves. --- ## How to Prevent Data Leaks in WooCommerce *Source: best-practices/security/prevent-data-leaks.md* # How to Prevent Data Leaks in WooCommerce Data leaks can expose sensitive information and compromise the security of a WooCommerce site. One common source of data leaks is direct access to PHP files. This tutorial will show you how to prevent these kinds of data leaks. In each PHP file of your WooCommerce extension, you should check if a constant called 'ABSPATH' is defined. This constant is defined by WordPress itself, and it's not defined if a file is being accessed directly. Here's how you can do this: ```php if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } ``` With this code, if someone tries to access the PHP file directly, the 'ABSPATH' constant won't be defined, and the script will exit before any sensitive data can be leaked. Remember, security is a crucial aspect of any WooCommerce site. Always take steps to prevent data leaks and protect your site's information. --- ## WooCommerce security best practices *Source: best-practices/security/security-best-practices.md* # WooCommerce security best practices ## Introduction to security practices Security is extremely important for online stores. A breach can lead to significant financial loss, reputational damage, and erosion of customer trust. Implementing robust security practices is crucial. This guide covers the best practices for securing WooCommerce stores, including hardening WordPress, keeping plugins and themes up to date, implementing secure coding practices, and protecting user data. By following these recommendations, developers can build secure and resilient WooCommerce stores that protect both their business and their customers. ### Audience This guide is intended for developers who are familiar with WordPress and WooCommerce and want to improve the security of their online stores. ### Prerequisites To follow this guide, you should have: 1. A basic understanding of WordPress and WooCommerce. 2. Access to a WordPress website with WooCommerce installed and activated. ## Security standards We recommend that you maintain the following standards: - **PHPCS**: The PHP Code Sniffer tool helps ensure your code adheres to specific coding standards, which can prevent common security issues. Extensions shouldn't have any failure results against PHPCS. - **SemGrep**: Focuses on identifying patterns that may indicate security vulnerabilities, allowing developers to write more secure code. Extensions shouldn't have any failure results against SemGrep. Understanding and implementing these standards can significantly reduce the risk of security vulnerabilities in your extensions and themes. ### Common security pitfalls and how to avoid them Several common security pitfalls can easily be avoided with vigilance and best practices: - **SQL injection**: Ensure all database queries are properly sanitized. - **Cross-site scripting**: Sanitize all user input to prevent malicious code from being executed. - **File inclusions**: Limit file inclusion to prevent unauthorized access to the file system. Awareness and prevention of these common issues are crucial steps in securing your WooCommerce store. For more resources, we recommend reading the [WordPress security documentation](https://developer.wordpress.org/apis/security/). ## Manual testing guidelines Even without access to automated tools like the [Woo Quality Insights Toolkit (QIT)](https://qit.woo.com), manual testing remains a vital component of securing your WooCommerce store. Here are some guidelines on how developers can manually test their extensions for security vulnerabilities: 1. **Code review**: Regularly review your code for security vulnerabilities, focusing on the areas where breaches commonly occur, such as user input fields and database queries. Code reviews should check against the [WordPress security criteria](https://developer.wordpress.org/apis/security/) mentioned above. 2. **Use security plugins**: Plugins like Wordfence, Sucuri, or iThemes Security provide an interface for manual security checks, including file integrity monitoring and malware scanning. Additionally, tooling like [OWASP Zap](https://www.zaproxy.org/) or [GitHub Security Scanning](https://github.com/features/security/) can be used. 3. **Testing environments**: Utilize staging environments to test the security of new features or updates before deploying them live. ## Other security best practices ### Keep WordPress, WooCommerce, and plugins up to date Regularly updating WordPress, WooCommerce, and all installed plugins is crucial to maintaining a secure online store. Updates often include security patches that address vulnerabilities and help protect your store from attacks. To keep your WordPress and WooCommerce installations up to date: 1. Enable automatic updates for WordPress core. 2. Regularly check for and install updates for WooCommerce and all plugins. ### Choose secure plugins and themes The plugins and themes you use can have a significant impact on the security of your WooCommerce store. To ensure your store is secure: 1. Install plugins and themes from reputable sources, such as the WordPress Plugin Directory and Theme Directory. 2. Regularly review and update the plugins and themes you use, removing any that are no longer maintained or have known security vulnerabilities. 3. Avoid using nulled or pirated plugins and themes, which may contain malicious code. ### Implement secure coding practices Secure coding practices are essential for building a secure WooCommerce store. To implement secure coding practices: 1. Follow the WordPress Coding Standards when developing custom themes or plugins. 2. Use prepared statements and parameterized queries to protect against SQL injection attacks. 3. Validate and sanitize user input to prevent cross-site scripting (XSS) attacks and other vulnerabilities. 4. Regularly review and update your custom code to address potential security vulnerabilities. ### Harden WordPress security Hardening your WordPress installation can help protect your WooCommerce store from attacks. To harden your WordPress security: 1. Use strong, unique passwords for all user accounts. 2. Limit login attempts and enable two-factor authentication (2FA) to protect against brute-force attacks. 3. Change the default `wp_` table prefix in your WordPress database. 4. Disable XML-RPC and REST API access when not needed. 5. Keep file permissions secure and restrict access to sensitive files and directories. ### Secure user data Protecting your customers' data is a critical aspect of securing your WooCommerce store. To secure user data: 1. Use SSL certificates to encrypt data transmitted between your store and your customers. 2. Store customer data securely and limit access to sensitive information. 3. Comply with data protection regulations, such as the GDPR, to ensure you handle customer data responsibly. ### Implement a security plugin Using a security plugin can help you monitor and protect your WooCommerce store from potential threats. To implement a security plugin: 1. Choose a reputable security plugin, such as Wordfence, Sucuri, or iThemes Security. 2. Configure the plugin's settings to enable features like malware scanning, firewall protection, and login security. ### Regularly monitor and audit your store's security Continuously monitor and audit your WooCommerce store's security to identify potential vulnerabilities and address them before they can be exploited. To monitor and audit your store's security: 1. Use a security plugin to perform regular scans for malware and other security threats. 2. Monitor your site's activity logs to identify suspicious activity and potential security issues. 3. Perform regular security audits to evaluate your store's overall security and identify areas for improvement. ### Create regular backups Backing up your WooCommerce store is essential for quickly recovering from security incidents, such as data loss or site compromise. To create regular backups: 1. Choose a reliable backup plugin, such as UpdraftPlus, BackupBuddy, or Duplicator. 2. Configure the plugin to automatically create regular backups of your entire site, including the database, files, and media. 3. Store your backups securely off-site to ensure they are accessible in case of an emergency. ## Conclusion By following these security best practices, you can build a secure and resilient WooCommerce store that protects both your business and your customers. Regularly monitoring, auditing, and updating your store's security measures will help ensure it remains protected as new threats and vulnerabilities emerge. --- ## Shareable Checkout URLs *Source: best-practices/urls-and-routing/checkout-urls.md* # Shareable Checkout URLs Custom checkout links automatically populate the cart with specific products and redirect customers straight to checkout with a unique session id. The custom checkout link path is `/checkout-link/` and is not customizable. ## Supported parameters ### Products ```plaintext products=123:2,456:1 ``` A comma-separated list of product IDs and quantities. For example, `123:2,456:1`. This feature supports simple products with no additional options. Individual variations can also be added to cart by using the correct variation ID. ### Coupon ```plaintext coupon=SPRING10 ``` A coupon code to apply to the cart. For example, `SPRING10`. ## Example ```plaintext https://yourstore.com/checkout-link/?products=123:2,456:1&coupon=SPRING10 ``` In this link: - Product ID `123` will be added with quantity `2` - Product ID `456` with quantity `1` - The coupon code `SPRING10` will be applied - The customer is taken directly to the checkout page ## Sessions Once the user is redirected to the checkout page, the cart is populated with the products and coupon code. The final URL includes a `session` parameter storing the ID of the session. Future changes to the checkout will be persisted in the session, enabling persistent and shareable carts. --- ## Customizing WooCommerce endpoint URLs *Source: best-practices/urls-and-routing/customizing-endpoint-urls.md* # Customizing WooCommerce endpoint URLs Before you start, check out [WooCommerce Endpoints](./woocommerce-endpoints.md). ## Customizing endpoint URLs The URL for each endpoint can be customized in **WooCommerce > Settings > Advanced** in the Page setup section. ![Endpoints](https://developer.woocommerce.com/wp-content/uploads/2023/12/endpoints.png) Ensure that they are unique to avoid conflicts. If you encounter issues with 404s, go to **Settings > Permalinks** and save to flush the rewrite rules. ## Using endpoints in menus If you want to include an endpoint in your menus, you need to use the Links section: ![The Links section of a menu item in WordPress](https://developer.woocommerce.com/wp-content/uploads/2023/12/2014-02-26-at-14.26.png) Enter the full URL to the endpoint and then insert that into your menu. Remember that some endpoints, such as view-order, require an order ID to work. In general, we don't recommend adding these endpoints to your menus. These pages can instead be accessed via the my-account page. ## Using endpoints in payment gateway plugins WooCommerce provides helper functions in the order class for getting these URLs. They are: `$order->get_checkout_payment_url( $on_checkout = false );` and: `$order->get_checkout_order_received_url();` Gateways need to use these methods for full 2.1+ compatibility. ## Troubleshooting ### Endpoints showing 404 - If you see a 404 error, go to **WordPress Admin** > **Settings > Permalinks** and Save. This ensures that rewrite rules for endpoints exist and are ready to be used. - If using an endpoint such as view-order, ensure that it specifies an order number. /view-order/ is invalid. /view-order/10/ is valid. These types of endpoints should not be in your navigation menus. ### Endpoints are not working On Windows servers, the **web.config** file may not be set correctly to allow for the endpoints to work correctly. In this case, clicking on endpoint links (e.g. /edit-account/ or /customer-logout/) may appear to do nothing except refresh the page. In order to resolve this, try simplifying the **web.config** file on your Windows server. Here's a sample file configuration: ```xml <<>?xml version="1.0" encoding="UTF-8"?> ``` ### Pages direct to wrong place Landing on the wrong page when clicking an endpoint URL is typically caused by incorrect settings. For example, clicking 'Edit address' on your account page takes you to the Shop page instead of the edit address form means you selected the wrong page in settings. Confirm that your pages are correctly configured and that a different page is used for each section. ### How to remove "Downloads" from My Account Sometimes the "Downloads" endpoint on the "My account" page does not need to be displayed. This can be removed by going to **WooCommerce > Settings > Advanced > Account endpoints** and clearing the Downloads endpoint field. ![Account endpoints](https://developer.woocommerce.com/wp-content/uploads/2023/12/Screenshot-2023-04-09-at-11.45.58-PM.png) --- ## Understanding the risks of removing URL bases in WooCommerce *Source: best-practices/urls-and-routing/removing-product-product-category-or-shop-from-the-url.md* # Understanding the risks of removing URL bases in WooCommerce ## In sum Removing `/product/`, `/product-category/`, or `/shop/` from the URLs is not advisable due to the way WordPress resolves its URLs. It uses the `product-category` (or any other text for that matter) base of a URL to detect that it is a URL leading to a product category. There are SEO plugins that allow you to remove this base, but that can lead to a number of problems with performance and duplicate URLs. ## Better to avoid You will make it harder for WordPress to detect what page you are trying to reach when you type in a product category URL. Also, understand that the standard "Page" in WordPress always has no base text in the URL. For example: - `http://yoursite.com/about-page/` (this is the URL of a standard page) - `http://yoursite.com/product-category/category-x/` (this is the URL leading to a product category) What would happen if we remove that 'product-category' part? - `http://yoursite.com/about-page/` - `http://yoursite.com/category-x/` WordPress will have to do much more work to detect what page you are looking for when entering one of the above URLs. That is why we do not recommend using any SEO plugin to achieve this. --- ## Working with webhooks in WooCommerce *Source: best-practices/urls-and-routing/webhooks.md* # Working with webhooks in WooCommerce ## What are webhooks? A [Webhook](http://en.wikipedia.org/wiki/Webhook) is an event notification sent to a URL of your choice. Users can configure them to trigger events on one site to invoke behavior on another. Webhooks are useful for integrating with third-party services and other external API that support them. ## Webhooks in WooCommerce Webhooks were introduced in WooCommerce 2.2 and can trigger events each time you add, edit or delete orders, products, coupons or customers. It's also possible to use webhooks with WooCommerce actions, e.g., Create a webhook to be used every time a product is added to the shopping cart, using the action `woocommerce_add_to_cart`. Webhooks also make it easier for third-party apps to integrate with WooCommerce. ## Creating webhooks ![WebHooks screen](https://woocommerce.com/wp-content/uploads/2013/01/woo-webhooks.png) To create a new webhook: 1/ **Go to**: **WooCommerce > Settings > Advanced > Webhooks**. > **Note:** Webhooks were formerly found under WooCommerce > Settings > API prior to WooCommerce 3.4. 2/ Select **Create a new webhook** (first incident) or **Add webhook**. The **Webhook Data** box appears. ![WebHooks creation](https://woocommerce.com/wp-content/uploads/2013/01/woo-webhooks.png) 3/ **Enter**. - **Name**: The **name** is auto-generated as "Webhook created on [date and time of creation]" as a standard to facilitate creation. Change the name to something else. - **Status**: Set to **Active** (delivers payload), **Paused** (does not deliver), or **Disabled** (does not deliver due delivery failures). - **Topic**: Indicate when the webhook should be triggered - **Order Created**, **Product Deleted**, or **Customer Updated**. There are also **Action** and **Custom** options. - **Action Event**: This option is available when the Topic is a WooCommerce **Action**, such as `woocommerce_add_to_cart` for when customers add products to the shopping cart. - **Custom Topic**: This option is for **advanced users only**. It's possible to introduce new, customized topics with the help of `woocommerce_webhook_topic_hooks` filter. - **Delivery URL**: URL where the webhook payload is delivered. - **Secret**: The Secret Key generates a hash of the delivered webhook and is provided in the request headers. This defaults to the current API user's consumer secret, if nothing is entered. 4/ **Save webhook**. > **Note**: The first time your webhook is saved with the Activated status, it sends a ping to the Delivery URL. Webhooks are disabled after 5 retries by default if the delivery URL returns an unsuccessful status such as `404` or `5xx`. Successful responses are `2xx`, `301` or `302`. To increase the number of retries, you can use the `woocommerce_max_webhook_delivery_failures` filter function. ## Editing and deleting webhooks Webhooks are listed the same way as posts or products. 1. Find the webhook you wish to alter. 2. Hover over the name, and **Edit** and **Delete permanently** options appear. 3. **Delete**, or make **Edits** and **Save changes**. Bulk deletion is also possible with the dropdown. ![WebHooks deletion](https://woocommerce.com/wp-content/uploads/2013/01/editdelete-webhook.png) ## Webhook logs WooCommerce saves logs of all events triggering a webhook. Webhook logs are found at: **WooCommerce > Status > Logs**. ![WebHooks logs](https://woocommerce.com/wp-content/uploads/2022/11/Viewing-WooCommerce-Webhook-Logs.png?w=650) Logs may be reviewed to see delivery and response from the server, making it simpler to integrate and debug. --- ## Understanding WooCommerce endpoints *Source: best-practices/urls-and-routing/woocommerce-endpoints.md* # Understanding WooCommerce endpoints Endpoints are an extra part in the website URL that is detected to show different content when present. For example: You may have a 'my account' page shown at URL **yoursite.com/my-account**. When the endpoint 'edit-account' is appended to this URL, making it '**yoursite.com/my-account/edit-account**' then the **Edit account page** is shown instead of the **My account page**. This allows us to show different content without the need for multiple pages and shortcodes, and reduces the amount of content that needs to be installed. Endpoints are located at **WooCommerce > Settings > Advanced**. ## Checkout endpoints The following endpoints are used for checkout-related functionality and are appended to the URL of the /checkout page: - Pay page - `/order-pay/{ORDER_ID}` - Order received (thanks) - `/order-received/` - Add payment method - `/add-payment-method/` - Delete payment method - `/delete-payment-method/` - Set default payment method - `/set-default-payment-method/` ## Account endpoints The following endpoints are used for account-related functionality and are appended to the URL of the /my-account page: - Orders - `/orders/` - View order - `/view-order/{ORDER_ID}` - Downloads - `/downloads/` - Edit account (and change password) - `/edit-account/` - Addresses - `/edit-address/` - Payment methods - `/payment-methods/` - Lost password - `/lost-password/` - Logout - `/customer-logout/` ## Learn more - [Customizing endpoint URLs](./customizing-endpoint-urls.md) --- ## WooCommerce Block Development *Source: block-development/README.md* # WooCommerce Block Development Welcome to the WooCommerce Block Development documentation! This section is your starting point for learning how to build, customize, and extend blocks for WooCommerce. Whether you’re new to block development or looking to deepen your expertise, this guide will walk you through the process step by step, from the basics to advanced extensibility. ## Start Here - **[Getting Started](/docs/block-development/getting-started/extensibility-overview/)**: Set up your environment and create your first block. - **[Tutorials](/docs/category/tutorials/)**: Follow hands-on guides to build and enhance your blocks. - **[Reference](/docs/category/reference/)**: Look up APIs, filters, and block details as you build. - **[Extensibility](/docs/category/extensible-blocks/)**: Learn to extend and customize blocks for advanced use cases. - **[Cart & Checkout](/docs/block-development/extensible-blocks/cart-and-checkout-blocks/)** and **[Product Collection](/docs/block-development/extensible-blocks/product-collection-block/)**: Explore specialized block documentation. Happy building! --- ## Getting started with Cart and Checkout extensibility *Source: block-development/extensible-blocks/cart-and-checkout-blocks/README.md* # Getting started with Cart and Checkout extensibility This document is a high-level overview of the moving parts required to extend the Cart and Checkout blocks. To get started, it is recommended to first read the [Block Development Environment](https://developer.wordpress.org/block-editor/getting-started/devenv/) documentation from WordPress and follow [Tutorial: Build your first block ](https://developer.wordpress.org/block-editor/getting-started/tutorial/). ## Example block template package There is an example block template in the WooCommerce repository. Having this template set up while reading this document may help to understand some of the concepts discussed. See the [`@woocommerce/extend-cart-checkout-block` package documentation](https://github.com/woocommerce/woocommerce/tree/trunk/packages/js/extend-cart-checkout-block/README.md) for how to install and run the example block. (Note: the code in the repository linked above will not be very useful alone; the code there is templating code. It will be transformed into regular JS and PHP after following the README instructions.) ## Front-end extensibility To extend the front-end of the blocks, extensions must use JavaScript. The JavaScript files must be enqueued and loaded on the page before they will have any effect. ### Build system Some extensions may be very simple and include only a single JavaScript file, other extensions may be complex and the code may be split into multiple files. Either way, it is recommended that the files are bundled together and minified into a single output file. If your extension has several distinct parts that only load on specific pages, bundle splitting is recommended, though that is out of scope for this document. To set up the build system, the recommended approach is to align with WordPress and use a JavaScript package called [`@wordpress/scripts`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/). This package contains a script called `build`. By default, this will build your scripts into a single output file that can be enqueued using `wp_enqueue_script`. The base configuration of the `build` script in `@wordpress/scripts` can be overridden by creating a `webpack.config.js` file in the root of your plugin. The example block shows how the base config can be extended. #### `WooCommerceDependencyExtractionWebpackPlugin` See [`WordPress Dependency Extraction Webpack Plugin`](https://github.com/WordPress/gutenberg/tree/trunk/packages/dependency-extraction-webpack-plugin) and [`WooCommerce Dependency Extraction Webpack Plugin`](https://github.com/woocommerce/woocommerce/tree/trunk/packages/js/dependency-extraction-webpack-plugin#dependency-extraction-webpack-plugin). This Webpack plugin is used to: - Externalize dependencies that are available as shared scripts or modules on WordPress sites. - This means when you import something from `@woocommerce/blocks-checkout` it resolves that path to `window.wc.wcBlocksCheckout` without you needing to change your code. It makes your code easier to read and allows these packages to be loaded onto the page once. - Add an asset file for each entry point that declares an object with the list of WordPress script or module dependencies for the entry point. The asset file also contains the current version calculated for the current source code. The PHP "asset file" that this plugin outputs contains information your script needs to register itself, such as dependencies and paths. If you have written code that is built by Webpack and using the WooCommerce Dependency Extraction Webpack Plugin, there will be an asset file output for each entry point. This asset file is a PHP file that contains information about your script, specifically dependencies and version, here's an example: ```php array( 'react', 'wc-settings', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-primitives' ), 'version' => '455da4f55e1ac73b6d34' ); ``` When enqueueing your script, using this asset file will ensure the dependencies are loaded correctly and that the client gets the most up-to-date version of your script (the version is used to ensure your script is fetched fresh, rather than from the cache). ```php [], 'version' => $this->get_file_version( $script_path ), ]; wp_register_script( 'example-blocks-integration-handle', $script_url, $script_asset['dependencies'], $script_asset['version'], true ); ``` Please see the [Cart and Checkout – Handling scripts, styles, and data](/docs/block-development/reference/integration-interface/) document for more information about how to correctly register scripts using the `IntegrationInterface`. ### Creating a block In the example block, there is a "checkout-newsletter-subscription-block" directory which contains the files needed to register an inner block in the Checkout. The example block template is only set up to import and build a single block, but the Webpack config can be modified to build multiple blocks. Doing this is not supported as part of this document, refer to the [Webpack documentation](https://webpack.js.org/concepts/) instead. The principles covered in [Tutorial: Build your first block ](https://developer.wordpress.org/block-editor/getting-started/tutorial/) apply here too. ### Modifying existing values on the front-end You may not need to create a block to get your extension working the way you want, for example, if your extension only modifies existing content through filters. In this case, you could remove the block folder from the example block, modify the Webpack config file so it no longer reads from that directory, and include the code you need in the entry JavaScript file. More information about how to use filters can be found in the [Filter Registry](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/packages/public-api/blocks-checkout/filter-registry/README.md) and [Available Filters](/docs/block-development/extensible-blocks/cart-and-checkout-blocks/filters-in-cart-and-checkout/) documents. ### Importing WooCommerce components into your extension Components can be imported from `@woocommerce/blocks-components` (externalized to `window.wc.blocksComponents` by `@woocommerce/dependency-extraction-webpack-plugin`). The list of available components can be seen in [the WooCommerce Storybook](https://woocommerce.github.io/woocommerce/?path=/docs/woocommerce-blocks_external-components-button--docs), listed under "WooCommerce Blocks -> External components". An example of importing the `Button` component is: ```js import { Button } from '@woocommerce/blocks-components'; const MyComponent = () => { return
; } ``` ### Importing WooCommerce utilities and React hooks Some checkout utilities and React hooks are available for external use from `@woocommerce/blocks-checkout`. See the [Checkout Utilities](/docs/block-development/extensible-blocks/cart-and-checkout-blocks/checkout-utilities/) documentation for available utilities. For accessing store data, using the [`wc/store/...`](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/docs/third-party-developers/extensibility/data-store/) data stores is preferred over importing internal hooks like `useStoreCart`. ## Back-end extensibility ### Declaring compatibility with the Cart and Checkout blocks Declaring compatibility helps merchants understand whether an extension supports the Cart and Checkout blocks if compatibility conflicts arise. Extensions usually fall into one of these categories: - An extension that is incompatible with the Cart and Checkout blocks should declare its incompatibility. - An extension that is compatible with the Cart and Checkout blocks should declare its compatibility. - An extension that does not affect the Cart or Checkout flow does not need to declare compatibility. WooCommerce only checks block compatibility for extensions that declare the `WC tested up to` header in the main plugin file. Add the header with the WooCommerce version your extension has tested against: ```php customer; // Or new WC_Customer( $id ) $checkout_fields = Package::container()->get( CheckoutFields::class ); $my_customer_billing_field = $checkout_fields->get_field_from_object( $field_id, $customer, 'billing' ); $my_customer_shipping_field = $checkout_fields->get_field_from_object( $field_id, $customer, 'shipping' ); ``` To access an order field: ```php use Automattic\WooCommerce\Blocks\Package; use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields; $field_id = 'my-plugin-namespace/my-field'; $order = wc_get_order( 1234 ); $checkout_fields = Package::container()->get( CheckoutFields::class ); $my_order_billing_field = $checkout_fields->get_field_from_object( $field_id, $order, 'billing' ); $my_order_shipping_field = $checkout_fields->get_field_from_object( $field_id, $order, 'shipping' ); ``` After an order is placed, the data saved to the customer and the data saved to the order will be the same. Customers can change the values for _future_ orders, or from within their My Account page. If you're looking at a customer value at a specific point in time (i.e. when the order was placed), access it from the order object, if you're looking for the most up to date value regardless, access it from the customer object. #### Guest customers When a guest customer places an order with additional fields, those fields will be saved to its session, so as long as the customer still has a valid session going, the values will always be there. #### Logged-in customers For logged-in customers, the value is only persisted once they place an order. Accessing a logged-in customer object during the place order lifecycle will return null or stale data. If you're at a place order hook, doing this will return previous data (not the currently inserted one): ```php $customer = new WC_Customer( $order->customer_id ); // Or new WC_Customer( 1234 ) $my_customer_billing_field = $checkout_fields->get_field_from_object( $field_id, $customer, 'billing' ); ``` Instead, always access the latest data if you want to run some extra validation/data-moving: ```php $customer = wc()->customer // This will return the current customer with its session. $my_customer_billing_field = $checkout_fields->get_field_from_object( $field_id, $customer, 'billing' ); ``` #### Accessing all fields You can use `get_all_fields_from_object` to access all additional fields saved to an order or a customer. ```php use Automattic\WooCommerce\Blocks\Package; use Automattic\WooCommerce\Blocks\Domain\Services\CheckoutFields; $order = wc_get_order( 1234 ); $checkout_fields = Package::container()->get( CheckoutFields::class ); $order_additional_billing_fields = $checkout_fields->get_all_fields_from_object( $order, 'billing' ); $order_additional_shipping_fields = $checkout_fields->get_all_fields_from_object( $order, 'shipping' ); $order_other_additional_fields = $checkout_fields->get_all_fields_from_object( $order, 'other' ); // Contact and Order are saved in the same place under the additional group. ``` This will return an array of all values, it will only include fields currently registered, if you want to include fields no longer registered, you can pass a third `true` parameter. ```php $order = wc_get_order( 1234 ); $checkout_fields = Package::container()->get( CheckoutFields::class ); $order_additional_billing_fields = $checkout_fields->get_all_fields_from_object( $order, 'billing' ); // array( 'my-plugin-namespace/my-field' => 'my-value' ); $order_additional_billing_fields = $checkout_fields->get_all_fields_from_object( $order, 'billing', true ); // array( 'my-plugin-namespace/my-field' => 'my-value', 'old-namespace/old-key' => 'old-value' ); ``` ### Accessing values directly While not recommended, you can use the direct meta key to access certain values, this is useful for external engines or page/email builders who only provide access to meta values. Values are saved under a predefined prefix, this is needed to able to query fields without knowing which ID the field was registered under, for a field with key `'my-plugin-namespace/my-field'`, it's meta key will be the following if it's an address field: - `_wc_billing/my-plugin-namespace/my-field` - `_wc_shipping/my-plugin-namespace/my-field` Or the following if it's a contact/order field: - `_wc_other/my-plugin-namespace/my-field`. Those prefixes are part of `CheckoutFields` class, and can be accessed using the following constants: ```php echo ( CheckoutFields::BILLING_FIELDS_PREFIX ); // _wc_billing/ echo ( CheckoutFields::SHIPPING_FIELDS_PREFIX ); // _wc_shipping/ echo ( CheckoutFields::OTHER_FIELDS_PREFIX ); // _wc_other/ ``` `CheckoutFields` provides a couple of helpers to get the group name or key based on one or the other: ```php CheckoutFields::get_group_name( "_wc_billing" ); // "billing" CheckoutFields::get_group_name( "_wc_billing/" ); // "billing" CheckoutFields::get_group_key( "shipping" ); // "_wc_shipping/" ``` Use cases here would be to build the key name to access the meta directly: ```php $key = CheckoutFields::get_group_key( "other" ) . 'my-plugin/is-opt-in'; $opted_in = get_user_meta( 123, $key, true ) === "1" ? true : false; ``` #### Checkboxes values When accessing a checkbox values directly, it will either return `"1"` for true, `"0"` for false, or `""` if the value doesn't exist, only the provided functions will sanitize that to a boolean. ## Supported field types The following field types are supported: - `select` - `text` - `checkbox` There are plans to expand this list, but for now these are the types available. ## Using the API To register additional checkout fields you must use the `woocommerce_register_additional_checkout_field` function. :::note Register fields on the `woocommerce_init` action (or later). Registering earlier can cause initialization and translation issues. ::: The registration function takes an array of options describing your field. Some field types take additional options. ### Options #### General options These options apply to all field types (except in a few circumstances which are noted inline). | Option name | Description | Required? | Example | Default value | | --- | --- | --- | --- | --- | | `id` | The field's ID. This should be a unique identifier for your field. It is composed of a namespace and field name separated by a `/`. | Yes | `plugin-namespace/how-did-you-hear` | No default - this must be provided. | | `label` | The label shown on your field. This will be the placeholder too. | Yes | `How did you hear about us?` | No default - this must be provided. | | `optionalLabel` | The label shown on your field if it is optional. This will be the placeholder too. | No | `How did you hear about us? (Optional)` | The default value will be the value of `label` with `(optional)` appended. | | `location` | The location to render your field. | Yes | `contact`, `address`, or `order` | No default - this must be provided. | | `type` | The type of field you're rendering. It defaults to `text` and must match one of the supported field types. | No | `text`, `select`, or `checkbox` | `text` | | `attributes` | An array of additional attributes to render on the field's input element. This is _not_ supported for `select` fields. | No | `[ 'data-custom-data' => 'my-custom-data' ]` | `[]` | | `required` | Can be a boolean or a JSON Schema array. If boolean and `true`, the shopper _must_ provide a value for this field during the checkout process. For checkbox fields, the shopper must check the box to place the order. If a JSON Schema array, the field will be required based on the schema conditions. See [Conditional visibility and validation via JSON Schema](#conditional-visibility-and-validation-via-json-schema). | No | `true` or `["type" => "object", "properties" => [...]]` | `false` | | `hidden` | Can be a boolean or a JSON Schema array. Must be `false` when used as a boolean. If a JSON Schema array, the field will be hidden based on the schema conditions. See [Conditional visibility and validation via JSON Schema](#conditional-visibility-and-validation-via-json-schema). | No | `false` or `["type" => "object", "properties" => [...]]` | `false` | | `validation` | An array of JSON Schema objects that define validation rules for the field. See [Conditional visibility and validation via JSON Schema](#conditional-visibility-and-validation-via-json-schema). | No | `[{"type": "object", "properties": {...}}]` | `[]` | | `sanitize_callback` | A function called to sanitize the customer-provided value when posted. | No | See example below | By default the field's value is returned unchanged. | | `validate_callback` | A function called to validate the customer-provided value when posted. This runs _after_ sanitization. | No | See example below | The default validation function will add an error to the response if the field is required and does not have a value. [See the default validation function.](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/Blocks/Domain/Services/CheckoutFields.php#L270-L281) | ##### Example of `sanitize_callback`. This function will remove spaces from the value {/* omit in toc */} ```php 'sanitize_callback' => function( $field_value ) { return str_replace( ' ', '', $field_value ); }, ``` ##### Example of `validate_callback`. This function will check if the value is an email {/* omit in toc */} ```php 'validate_callback' => function( $field_value ) { if ( ! is_email( $field_value ) ) { return new WP_Error( 'invalid_alt_email', 'Please ensure your alternative email matches the correct format.' ); } }, ``` #### Options for `text` fields Text fields don't have any additional options beyond the general options listed above. #### Options for `select` fields As well as the options above, select fields must also be registered with an `options` option. This is used to specify what options the shopper can select. Select fields will mount with no value selected by default, if the field is required, the user will be required to select a value. You can set a placeholder to be shown on the select by passing a `placeholder` value when registering the field. This will be the first option in the select and will not be selectable if the field is required. | Option name | Description | Required? | Example | Default value | | --- | --- | --- | --- | --- | | `options` | An array of options to show in the select input. Each options must be an array containing a `label` and `value` property. Each entry must have a unique `value`. Any duplicate options will be removed. The `value` is what gets submitted to the server during checkout and the `label` is simply a user-friendly representation of this value. It is not transmitted to the server in any way. | Yes | see below | No default - this must be provided. | | `placeholder` | If this value is set, the shopper will see this option in the select. If the select is required, the shopper cannot select this option. | No | `Select a role` | Select a $label | ##### Example of `options` value ```php [ [ 'value' => 'store_1', 'label' => 'Our London Store' ], [ 'value' => 'store_2', 'label' => 'Our Paris Store' ], [ 'value' => 'store_3', 'label' => 'Our New York Store' ] ] ``` #### Options for `checkbox` fields As well as the options above, checkbox field support showing an error message if it's required and not checked. | Option name | Description | Required? | Example | Default value | | --- | --- | --- | --- | --- | | `error_message` | A custom message to show if the box is unchecked. | No | `You must confirm you are over 18 before placing the order.` | `Please check this box if you want to proceed.` | ### Attributes Adding additional attributes to checkbox and text fields is supported. Adding them to select fields is **not possible for now**. These attributes have a 1:1 mapping to the HTML attributes on `input` elements (except `pattern` on checkbox). The supported attributes are: - `data-*` attributes - `aria-*` attributes - `autocomplete` - `autocapitalize` - `pattern` (not supported on checkbox fields) - `title` - `maxLength` (equivalent to `maxlength` HTML attribute) - `readOnly` (equivalent to `readonly` HTML attribute) `maxLength` and `readOnly` are in camelCase because the attributes are rendered on a React element which must receive them in this format. Certain attributes are not passed through to the field intentionally, these are `autofocus` and `disabled`. We are welcome to hear feedback and adjust this behaviour if valid use cases are provided. ## Usage examples ### Rendering a text field This example demonstrates rendering a text field in the address section: ```php add_action( 'woocommerce_init', function() { woocommerce_register_additional_checkout_field( array( 'id' => 'namespace/gov-id', 'label' => 'Government ID', 'optionalLabel' => 'Government ID (optional)', 'location' => 'address', 'required' => true, 'attributes' => array( 'autocomplete' => 'government-id', 'aria-describedby' => 'some-element', 'aria-label' => 'custom aria label', 'pattern' => '[A-Z0-9]{5}', // A 5-character string of capital letters and numbers. 'title' => 'Title to show on hover', 'data-custom' => 'custom data', ), ), ); } ); ``` This results in the following address form (the billing form will be the same): ![The shipping address form with the Government ID field rendered at the bottom](https://github.com/woocommerce/woocommerce/assets/5656702/f6eb3c6f-9178-4978-8e74-e6b2ea353192) The rendered markup looks like this: ```html ``` ### Rendering a checkbox field This example demonstrates rendering a checkbox field in the contact information section: ```php add_action( 'woocommerce_init', function() { woocommerce_register_additional_checkout_field( array( 'id' => 'namespace/marketing-opt-in', 'label' => 'Do you want to subscribe to our newsletter?', 'location' => 'contact', 'type' => 'checkbox', ) ); } ); ``` This results in the following contact information section: ![The contact information section with a newsletter subscription checkbox rendered inside it](https://github.com/woocommerce/woocommerce/assets/5656702/7444e41a-97cc-451d-b2c9-4eedfbe05724) Note that because an `optionalLabel` was not supplied, the string `(optional)` is appended to the label. To remove that an `optionalLabel` property should be supplied to override this. ### Rendering a select field This example demonstrates rendering a select field in the order information section: ```php add_action( 'woocommerce_init', function() { woocommerce_register_additional_checkout_field( array( 'id' => 'namespace/how-did-you-hear-about-us', 'label' => 'How did you hear about us?', 'placeholder' => 'Select a source', 'location' => 'order', 'type' => 'select', 'options' => [ [ 'value' => 'google', 'label' => 'Google' ], [ 'value' => 'facebook', 'label' => 'Facebook' ], [ 'value' => 'friend', 'label' => 'From a friend' ], [ 'value' => 'other', 'label' => 'Other' ], ] ) ); } ); ``` This results in the order information section being rendered like so: ### The select input before being focused ![The select input before being focused](https://github.com/woocommerce/woocommerce/assets/5656702/bbe17ad0-7c7d-419a-951d-315f56f8898a) ### The select input when focused ![The select input when focused](https://github.com/woocommerce/woocommerce/assets/5656702/bd943906-621b-404f-aa84-b951323e25d3) If it is undesirable to force the shopper to select a value, mark the select as optional by setting the `required` option to `false`. ## Validation and sanitization It is possible to add custom validation and sanitization for additional checkout fields using WordPress action hooks. These actions happen in two places: 1. Updating and submitting the form during the checkout process and, 2. Updating address/contact information in the "My account" area. ### Sanitization Sanitization is used to ensure the value of a field is in a specific format. An example is when taking a government ID, you may want to format it so that all letters are capitalized and there are no spaces. At this point, the value should **not** be checked for _validity_. That will come later. This step is only intended to set the field up for validation. #### Using the `woocommerce_sanitize_additional_field` filter To run a custom sanitization function for a field you can use the `sanitize_callback` function on registration, or the `woocommerce_sanitize_additional_field` filter. | Argument | Type | Description | |----------------|-------------------|-------------------------------------------------------------------------| | `$field_value` | `boolean\|string` | The value of the field. | | `$field_key` | `string` | The ID of the field. This is the same ID the field was registered with. | ##### Example of sanitization This example shows how to remove whitespace and capitalize all letters in the example Government ID field we added above. ```php add_action( 'woocommerce_sanitize_additional_field', function ( $field_value, $field_key ) { if ( 'namespace/gov-id' === $field_key ) { $field_value = str_replace( ' ', '', $field_value ); $field_value = strtoupper( $field_value ); } return $field_value; }, 10, 2 ); ``` ### Validation There are two phases of validation in the additional checkout fields system. The first is validating a single field based on its key and value. #### Single field validation ##### Using the `woocommerce_validate_additional_field` action When the `woocommerce_validate_additional_field` action is fired the callback receives the field's key, the field's value, and a `WP_Error` object. To add validation errors to the response, use the [`WP_Error::add`](https://developer.wordpress.org/reference/classes/wp_error/add/) method. | Argument | Type | Description | | --- | --- | --- | | `$errors` | `WP_Error` | An error object containing errors that were already encountered while processing the request. If no errors were added yet, it will still be a `WP_Error` object but it will be empty. | | `$field_key` | `string` | The id of the field. This is the ID the field was registered with. | | `$field_value` | `boolean\|string` | The value of the field | ###### The `WP_Error` object When adding your error to the `WP_Error` object, it should have a unique error code. You may want to prefix the error code with the plugin namespace to reduce the chance of collision. Using codes that are already in use across other plugins may result in the error message being overwritten or showing in a different location. ###### Example of single-field validation The below example shows how to apply custom validation to the `namespace/gov-id` text field from above. The code here ensures the field is made up of 5 characters, either upper-case letters or numbers. The sanitization function from the example above ensures that all whitespace is removed and all letters are capitalized, so this check is an extra safety net to ensure the input matches the pattern. ```php add_action( 'woocommerce_validate_additional_field', function ( WP_Error $errors, $field_key, $field_value ) { if ( 'namespace/gov-id' === $field_key ) { $match = preg_match( '/[A-Z0-9]{5}/', $field_value ); if ( 0 === $match || false === $match ) { $errors->add( 'invalid_gov_id', 'Please ensure your government ID matches the correct format.' ); } } }, 10, 3 ); ``` It is important to note that this action must _add_ errors to the `WP_Error` object it receives. Returning a new `WP_Error` object or any other value will result in the errors not showing. If no validation errors are encountered the function can just return void. #### Multiple field validation There are cases where the validity of a field depends on the value of another field, for example validating the format of a government ID based on what country the shopper is in. In this case, validating only single fields (as above) is not sufficient as the country may be unknown during the `woocommerce_validate_additional_field` action. To solve this, it is possible to validate a field in the context of the location it renders in. The other fields in that location will be passed to this action. ##### Using the `woocommerce_blocks_validate_location_{location}_fields` action This action will be fired for each location that additional fields can render in (`address`, `contact`, and `order`). For `address` it fires twice, once for the billing address and once for the shipping address. The callback receives the keys and values of the other additional fields in the same location. It is important to note that any fields rendered in other locations will not be passed to this action, however it might be possible to get those values by accessing the customer or order object, however this is not supported and there are no guarantees regarding backward compatibility in future versions. | Argument | Type | Description | | --- | --- | --- | | `$errors` | `WP_Error` | An error object containing errors that were already encountered while processing the request. If no errors were added yet, it will still be a `WP_Error` object but it will be empty. | | `$fields` | `array` | The fields rendered in this locations. | | `$group` | `'billing'\|'shipping'\|'other'` | If the action is for the address location, the type of address will be set here. If it is for contact or order, this will be 'other'. | There are several places where these hooks are fired. - When checking out using the Checkout block or Store API. - `woocommerce_blocks_validate_location_address_fields` (x2) - `woocommerce_blocks_validate_location_contact_fields` - `woocommerce_blocks_validate_location_other_fields` - When updating addresses in the "My account" area - `woocommerce_blocks_validate_location_address_fields` (**x1** - only the address being edited) - When updating the "Account details" section in the "My account" area - `woocommerce_blocks_validate_location_contact_fields` ##### Example of location validation In this example, assume there is another field registered alongside the `namespace/gov-id` called `namespace/confirm-gov-id`. This field will be a confirmation for the Government ID field. The example below illustrates how to verify that the value of the confirmation field matches the value of the main field. ```php add_action( 'woocommerce_blocks_validate_location_address_fields', function ( \WP_Error $errors, $fields, $group ) { if ( $fields['namespace/gov-id'] !== $fields['namespace/confirm-gov-id'] ) { $errors->add( 'gov_id_mismatch', 'Please ensure your government ID matches the confirmation.' ); } }, 10, 3 ); ``` If these fields were rendered in the "contact" location instead, the code would be the same except the hook used would be: `woocommerce_blocks_validate_location_contact_fields`. ## Conditional visibility and validation via JSON Schema The `required`, `hidden`, and `validation` properties accept an `array` of [JSON Schema](https://json-schema.org/understanding-json-schema/about) to create conditional logic for fields. This allows you to dynamically control field visibility, requirement status, and validation rules based on the values of other fields. Schema is evaluated in the frontend in real-time, and on the backend at any update. This ensures fast and responsive UI, and consistent results between the client and server. ### JSON Schema Structure Each schema in the array should be a valid JSON Schema object that defines conditions for when the property should be applied. The schema is evaluated against the current cart and checkout state, which includes all field values and various options (payment, shipping, customer). Basic structure of a JSON Schema object: ```json { "type": "object", "properties": { "fieldId": { "enum": ["value1", "value2"] } }, "required": ["fieldId"] } ``` If you're not familiar with JSON Schema, you can get a quick introduction to it [from the official website](https://json-schema.org/understanding-json-schema/basics), or from one of the libraries used [like AJV](https://ajv.js.org/json-schema.html) or [OPIS.](https://opis.io/json-schema/2.x/examples.html) Checkout builds an abstraction on top of both of them. ### Document object When you're writing your rules, you're writing a partial schema for the document object, essentially describing the ideal state you want for your field to be required or hidden. **Important:** All properties in the document object use snake_case naming convention (e.g., `total_price`, `shipping_rates`, `customer_note`), not camelCase. An example of the document object looks like this:
Document object ```json { "cart": { "coupons": [ "my_coupon" ], "shipping_rates": [ "free_shipping:1" ], "items": [ 27, 27, 68 ], "items_type": [ "simple", "variation" ], "items_count": 3, "items_weight": 0, "needs_shipping": true, "prefers_collection": false, "totals": { "total_price": 6600, "total_tax": 600 }, "extensions": {} }, "checkout": { "create_account": false, "customer_note": "", "additional_fields": { "namespace/myorder-field": "myvalue" }, "payment_method": "bacs" }, "customer": { "id": 1, "billing_address": { "first_name": "First Name", "last_name": "Last Name", "company": "Company", "address_1": "Address 1", "address_2": "Address 2", "city": "City", "state": "State", "postcode": "08000", "country": "US", "email": "email@example.com", "phone": "1234567890", "namespace/myfield": "myvalue" }, "shipping_address": { "first_name": "First Name", "last_name": "Last Name", "company": "Company", "address_1": "Address 1", "address_2": "Address 2", "city": "City", "state": "State", "postcode": "08000", "country": "US", "phone": "1234567890", "namespace/myfield": "myvalue" }, "additional_fields": { "namespace/mycontact-field": "myvalue" }, "address": { "first_name": "First Name", "last_name": "Last Name", "company": "Company", "address_1": "Address 1", "address_2": "Address 2", "city": "City", "state": "State", "postcode": "08000", "country": "US", "phone": "1234567890", "namespace/myfield": "myvalue" } } } ```
It's full schema is this one:
Document schema ```json { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Cart and Checkout Document Object Schema", "description": "Document object schema for cart, checkout, and customer information, to be used for conditional visibility, requirement, and validation of fields.", "type": "object", "properties": { "cart": { "type": "object", "description": "Information about the shopping cart", "properties": { "coupons": { "type": "array", "description": "List of coupon codes applied to the cart", "items": { "type": "string" } }, "shipping_rates": { "type": "array", "description": "List of currently selected shipping rates", "items": { "type": "string", "description": "Shipping rate identifier using the full shipping rate ID so method_id:instance_id, for example: flat_rate:1" } }, "items": { "type": "array", "description": "List of product IDs in the cart, IDs will be duplicated depending on the quantity of the product in the cart, so if you have 2 of product ID 1, the array will have 2 entries of product ID 1. This only supports integer quantities, not floats (which round up to the nearest integer).", "items": { "type": "integer" } }, "items_type": { "type": "array", "description": "Types of items in the cart, for example: simple, variation, subscription, etc.", "items": { "type": "string" } }, "items_count": { "type": "integer", "description": "Total number of items in the cart", "minimum": 0 }, "items_weight": { "type": "number", "description": "Total weight of items in the cart", "minimum": 0 }, "needs_shipping": { "type": "boolean", "description": "Whether the items in the cart require shipping" }, "prefers_collection": { "type": "boolean", "description": "Whether the customer prefers using Local Pickup" }, "totals": { "type": "object", "description": "Cart totals information", "properties": { "total_price": { "type": "integer", "description": "Total price of the cart in smallest currency unit (e.g., cents), after applying all discounts, shipping, and taxes" }, "total_tax": { "type": "integer", "description": "Total tax amount in smallest currency unit (e.g., cents), after applying all discounts, shipping, and taxes" } }, "additionalProperties": false }, "extensions": { "type": "object", "description": "Additional cart extension data, this is similar to what's passed in Store API's extensions parameter" } }, "additionalProperties": false }, "checkout": { "type": "object", "description": "Checkout preferences and settings", "properties": { "create_account": { "type": "boolean", "description": "Whether the customer checked the create account checkbox, this will be false if the customer is logged in, cannot create an account, or forced to create an account." }, "customer_note": { "type": "string", "description": "Customer's note or special instructions for the order, this will be empty if the customer didn't add a note." }, "additional_fields": { "type": "object", "description": "Additional checkout fields with 'order' location. These fields are rendered in the order information section.", "additionalProperties": { "type": "string" }, "patternProperties": { "^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$": { "type": "string", "description": "Custom fields with namespace identifiers" } } }, "payment_method": { "type": "string", "description": "Selected payment method identifier, this will be the payment method ID regardless if the customer selected a saved payment method or new payment method" } }, "additionalProperties": false }, "customer": { "type": "object", "description": "Customer information", "properties": { "id": { "type": "integer", "description": "Customer ID, this will be 0 if the customer is not logged in" }, "billing_address": { "$ref": "#/definitions/address", "description": "Customer's billing address" }, "shipping_address": { "$ref": "#/definitions/address", "description": "Customer's shipping address" }, "additional_fields": { "type": "object", "description": "Additional checkout fields with 'contact' location. These fields are rendered in the contact information section.", "additionalProperties": { "type": "string" }, "patternProperties": { "^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$": { "type": "string", "description": "Custom fields with namespace identifiers" } } }, "address": { "$ref": "#/definitions/address", "description": "This is a dynamic field that will be the billing or shipping address depending on the context of the field being evaluated." } }, "additionalProperties": false } }, "additionalProperties": false, "definitions": { "address": { "type": "object", "description": "Customer address information", "properties": { "first_name": { "type": "string", "description": "First name of the recipient" }, "last_name": { "type": "string", "description": "Last name of the recipient" }, "company": { "type": "string", "description": "Company name" }, "address_1": { "type": "string", "description": "Primary address line" }, "address_2": { "type": "string", "description": "Secondary address line" }, "city": { "type": "string", "description": "City name" }, "state": { "type": "string", "description": "State or province, this will be the state code if it's a predefined list, for example: CA, TX, NY, etc, or the field value if it's a freeform state, for example: London." }, "postcode": { "type": "string", "description": "Postal or ZIP code" }, "country": { "type": "string", "description": "Country code (e.g., US, UK)" }, "email": { "type": "string", "format": "email", "description": "Email address" }, "phone": { "type": "string", "description": "Phone number" } }, "additionalProperties": { "type": "string", "description": "Additional fields with 'address' location appear here as properties within the address objects" }, "patternProperties": { "^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$": { "type": "string", "description": "Additional fields with 'address' location using namespace identifiers (e.g., 'namespace/field-name')" } } } } } ```
### Examples #### Required and visible field In this example we make the field required and visible only if local pickup is being used. ```php 'required' => [ "type" => "object", "properties" => [ "cart" => [ "properties" => [ "prefers_collection" => [ "const" => true ] ] ] ] ], 'hidden' => [ "type" => "object", "properties" => [ "cart" => [ "properties" => [ "prefers_collection" => [ "const" => false ] ] ] ] ] ``` Notice that for hidden, we inverse the field, meaning, this field should only be hidden if `prefers_collection` is false, which is almost all cases except when it's selected. In the examples above, we used [the keyword `const`](https://ajv.js.org/json-schema.html#const). #### Validation schema example Validation is slightly different from conditional visibility and requirement. In validation, you will pass in a subset of schema (only applicable to your field), and its role is to validate the field and show any errors if there. In this example, we ensure that VAT is made up of a country code and 8-12 numbers. ```php 'validation' => [ "type" => "string", "pattern" => "^[A-Z]{2}[0-9]{8,12}$", "errorMessage" => "Please enter a valid VAT code with 2 letters for country code and 8-12 numbers." ] ``` Validation can also be against other fields, for example, an alternative email field that shouldn't match the current email: ```php 'validation' => [ "type" => "string", "format" => "email", "not" => [ "const" => [ '$data' => "/customer/billing_address/email" ] ], "errorMessage" => "Please enter a valid alternative email." ] ``` In the example above, we used [format keyword](https://github.com/ajv-validator/ajv-formats) and `$data` to refer to the current field value via [JSON pointers](https://ajv.js.org/guide/combining-schemas.html#data-reference). We also used the `errorMessage` property to provide a custom error message. #### `$data` keyword and JSON pointers `$data` keyword is a way in JSON schema to reference another field's value. In the above example, we use it to refer to the billing email via [JSON pointers](https://ajv.js.org/guide/combining-schemas.html#data-reference). When dealing with JSON pointers, there are some things to keep in mind: - The forward slash `/` is used to navigate through the JSON object, so for additional fields, a field named `my-plugin-namespace/my-field` will need to be referenced as `my-plugin-namespace~1my-field`. - Navigation in JSON pointers can be from the current field backward, or from the root. If you have an address field and want to validate say the phone field, this means you will validate 2 values, one for shipping, and one for billing, so you can reference the phone field in 2 ways: - `0/customer/address/phone` which uses root navigation (via the `0/`) prefix, and uses the dynamic `address` group, which will change depending if the billing or shipping value is being validated. - `1/phone` which uses relative pointers to step back, in this case, it will access its sibling field, the `phone` field. Increase the number to step back even further, for example, `2/id` will access the customer ID. ### Keywords and values that are not in spec We support [JSON Schema Draft-07](https://json-schema.org/draft-07), which is simple and doesn't support all the keywords and values that are in the latest spec, but we feel like it covers most of the use cases. On top of that, we introduced some non-standard keywords and values that are not in the spec, their implementation might be different between Opis and AJV (or any future implementation), this is the list of such keywords and values: - `errorMessage`: Custom error message for validation, in AJV, this is `errorMessage` and in Opis, this is `$error`, we only support `errorMessage` and maps that internally for Opis. We also don't support templates in `errorMessage` for now. - `$data`: Refers to the current field value via [JSON pointers](https://ajv.js.org/guide/combining-schemas.html#data-reference), both Opis and AJV use the same implementation. ### Evaluation Logic - For `required`: If any schema in the array matches the current checkout state, the field will be required. - For `hidden`: If any schema in the array matches the current checkout state, the field will be hidden. - For `validation`: The value of the field will be evaluated against the partial schema provided and an error will be shown if it didn't match. ### Performance Considerations Complex JSON Schema conditions can impact checkout performance. Keep your schemas as simple as possible and limit the number of conditions to what's necessary for your use case. ## Backward compatibility Due to technical reasons, it's not yet possible to specify the meta key for fields, as we want them to be prefixed and managed. Plugins with existing fields in shortcode Checkout can be compatible and react to reading and saving fields using hooks. Assuming 2 fields, named `my-plugin-namespace/address-field` in the address step and `my-plugin-namespace/my-other-field` in the order step, you can: ### React to saving fields You can react to those fields being saved by hooking into `woocommerce_set_additional_field_value` action. ```php add_action( 'woocommerce_set_additional_field_value', function ( $key, $value, $group, $wc_object ) { if ( 'my-plugin-namespace/address-field' !== $key ) { return; } if ( 'billing' === $group ) { $my_plugin_address_key = 'existing_billing_address_field_key'; } else { $my_plugin_address_key = 'existing_shipping_address_field_key'; } $wc_object->update_meta_data( $my_plugin_address_key, $value, true ); }, 10, 4 ); add_action( 'woocommerce_set_additional_field_value', function ( $key, $value, $group, $wc_object ) { if ( 'my-plugin-namespace/my-other-field' !== $key ) { return; } $my_plugin_key = 'existing_order_field_key'; $wc_object->update_meta_data( $my_plugin_key, $value, true ); }, 10, 4 ); ``` This way, you can ensure existing systems will continue working and your integration will continue to work. However, ideally, you should migrate your existing data and systems to use the new meta fields. ### React to reading fields You can use the `woocommerce_get_default_value_for_{$key}` filters to provide a different default value (a value coming from another meta field for example): ```php add_filter( "woocommerce_get_default_value_for_my-plugin-namespace/address-field", function ( $value, $group, $wc_object ) { if ( 'billing' === $group ) { $my_plugin_key = 'existing_billing_address_field_key'; } else { $my_plugin_key = 'existing_shipping_address_field_key'; } return $wc_object->get_meta( $my_plugin_key ); }, 10, 3 ); add_filter( "woocommerce_get_default_value_for_my-plugin-namespace/my-other-field", function ( $value, $group, $wc_object ) { $my_plugin_key = 'existing_order_field_key'; return $wc_object->get_meta( $my_plugin_key ); }, 10, 3 ); ``` ## A full example In this full example we will register the Government ID text field and verify that it conforms to a specific pattern. This example is just a combined version of the examples shared above. ```php add_action( 'woocommerce_init', function() { woocommerce_register_additional_checkout_field( array( 'id' => 'namespace/gov-id', 'label' => 'Government ID', 'location' => 'address', 'required' => true, 'attributes' => array( 'autocomplete' => 'government-id', 'pattern' => '[A-Z0-9]{5}', // A 5-character string of capital letters and numbers. 'title' => 'Your 5-digit Government ID', ), ), ); woocommerce_register_additional_checkout_field( array( 'id' => 'namespace/confirm-gov-id', 'label' => 'Confirm government ID', 'location' => 'address', 'required' => true, 'attributes' => array( 'autocomplete' => 'government-id', 'pattern' => '[A-Z0-9]{5}', // A 5-character string of capital letters and numbers. 'title' => 'Confirm your 5-digit Government ID', ), ), ); add_action( 'woocommerce_sanitize_additional_field', function ( $field_value, $field_key ) { if ( 'namespace/gov-id' === $field_key || 'namespace/confirm-gov-id' === $field_key ) { $field_value = str_replace( ' ', '', $field_value ); $field_value = strtoupper( $field_value ); } return $field_value; }, 10, 2 ); add_action( 'woocommerce_validate_additional_field', function ( WP_Error $errors, $field_key, $field_value ) { if ( 'namespace/gov-id' === $field_key ) { $match = preg_match( '/[A-Z0-9]{5}/', $field_value ); if ( 0 === $match || false === $match ) { $errors->add( 'invalid_gov_id', 'Please ensure your government ID matches the correct format.' ); } } return $errors; }, 10, 3 ); } ); add_action( 'woocommerce_blocks_validate_location_address_fields', function ( \WP_Error $errors, $fields, $group ) { if ( $fields['namespace/gov-id'] !== $fields['namespace/confirm-gov-id'] ) { $errors->add( 'gov_id_mismatch', 'Please ensure your government ID matches the confirmation.' ); } }, 10, 3 ); ``` --- ## Available slots *Source: block-development/extensible-blocks/cart-and-checkout-blocks/available-slot-fills.md* # Available slots This document presents the list of available Slots that you can use for adding your custom content (Fill). If you want to add a new SlotFill component, check the [Checkout - Slot Fill document](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/packages/public-api/blocks-checkout/slot/README.md). To read more about Slot and Fill, check the [Slot and Fill document](/docs/block-development/reference/slot-fills/). **Note About Naming:** Slots that are prefixed with `Experimental` are experimental and subject to change or remove. Once they graduate from the experimental stage, the naming would change and the `Experimental` prefix would be dropped. Check the [Feature Gating document](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/docs/internal-developers/blocks/feature-flags-and-experimental-interfaces.md) from more information. ## ExperimentalOrderMeta This Slot renders below the Checkout summary section and above the "Proceed to Checkout" button in the Cart. ```ts const { __ } = window.wp.i18n; const { registerPlugin } = window.wp.plugins; const { ExperimentalOrderMeta } = window.wc.blocksCheckout; const render = () => { return (
{ __( 'Yearly recurring total ...', 'YOUR-TEXTDOMAIN' ) }
); }; registerPlugin( 'slot-and-fill-examples', { render, scope: 'woocommerce-checkout', } ); ``` Cart: ![Example of ExperimentalOrderMeta in the Cart block](https://user-images.githubusercontent.com/1628454/154517779-117bb4e4-568e-413c-904c-855fc3450dfa.png) Checkout: ![Example of ExperimentalOrderMeta in the Checkout block](https://user-images.githubusercontent.com/1628454/154697224-de245182-6783-4914-81ba-1dbcf77292eb.png) ### Passed parameters - `cart`: `wc/store/cart` data but in `camelCase` instead of `snake_case`. [Object breakdown.](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/packages/public-api/types/type-defs/cart.ts) - `extensions`: external data registered by third-party developers using `ExtendSchema`. If you used `ExtendSchema` on `wc/store/cart` you would find your data under your namespace here. - `context`, equal to the name of the Block in which the fill is rendered: `woocommerce/cart` or `woocommerce/checkout` ## ExperimentalOrderShippingPackages This slot renders inside the shipping step of Checkout and inside the shipping options in Cart. ```ts const { __ } = window.wp.i18n; const { registerPlugin } = window.wp.plugins; const { ExperimentalOrderShippingPackages } = window.wc.blocksCheckout; const render = () => { return (
{ __( 'Express Shipping', 'YOUR-TEXTDOMAIN' ) }
); }; registerPlugin( 'slot-and-fill-examples', { render, scope: 'woocommerce-checkout', } ); ``` Cart: ![Example of ExperimentalOrderShippingPackages in the Cart block](https://user-images.githubusercontent.com/6165348/118399054-2b4dec80-b653-11eb-94a0-989e2e6e362a.png) Checkout: ![Example of ExperimentalOrderShippingPackages in the Checkout block](https://user-images.githubusercontent.com/6165348/118399133-90094700-b653-11eb-8ff0-c917947c199f.png) ### Passed parameters - `collapsible`: `Boolean|undefined` If a shipping package panel should be collapsible or not, this is false in Checkout and undefined in Cart. - `collapse`: `Boolean` If a panel should be collapsed by default, this is true if panels are collapsible. - `showItems`: `Boolean|undefined` If we should show the content of each package, this is undefined in Cart and Checkout and is left to the actual package logic to decide. - `noResultsMessage`: A React element that you can render if there are no shipping options. - `renderOption`: a render function that takes a rate object and returns a render option. - `cart`: `wc/store/cart` data but in `camelCase` instead of `snake_case`. [Object breakdown.](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/packages/public-api/types/type-defs/cart.ts) - `extensions`: external data registered by third-party developers using `ExtendSchema`, if you used `ExtendSchema` on `wc/store/cart` you would find your data under your namespace here. - `components`: an object containing components you can use to render your own shipping rates, it contains `ShippingRatesControlPackage`. - `context`, equal to the name of the Block in which the fill is rendered: `woocommerce/cart` or `woocommerce/checkout` ## ExperimentalOrderLocalPickupPackages This slot renders inside the Checkout Pickup Options block in the Checkout block. It does not render in the Cart block. ```ts const { __ } = window.wp.i18n; const { registerPlugin } = window.wp.plugins; const { ExperimentalOrderLocalPickupPackages } = window.wc.blocksCheckout; const render = () => { return (
{ __( 'By using our convenient local pickup option, you can come to our store and pick up your order. We will send you an email when your order is ready for pickup.', 'YOUR-TEXTDOMAIN' ) }
); }; registerPlugin( 'slot-and-fill-examples', { render, scope: 'woocommerce-checkout', } ); ``` Checkout: ![Example of ExperimentalOrderLocalPickupPackages in the Checkout block](https://user-images.githubusercontent.com/5656702/222814945-a449d016-0621-4a70-b0f4-2ae1ce6487f1.png) ### Passed parameters - `renderPickupLocation`: a render function that renders the address details of a local pickup option. - `cart`: `wc/store/cart` data but in `camelCase` instead of `snake_case`. [Object breakdown.](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/packages/public-api/types/type-defs/cart.ts) - `extensions`: external data registered by third-party developers using `ExtendSchema`, if you used `ExtendSchema` on `wc/store/cart` you would find your data under your namespace here. - `components`: an object containing components you can use to render your own pickup rates, it contains `ShippingRatesControlPackage` and `RadioControl`. ## ExperimentalDiscountsMeta This slot renders below the `CouponCode` input. ```ts const { __ } = window.wp.i18n; const { registerPlugin } = window.wp.plugins; const { ExperimentalDiscountsMeta } = window.wc.blocksCheckout; const render = () => { return (
{ __( 'You have 98683 coins to spend ...', 'YOUR-TEXTDOMAIN' ) }
); }; registerPlugin( 'slot-and-fill-examples', { render, scope: 'woocommerce-checkout', } ); ``` Cart: ![Cart showing ExperimentalDiscountsMeta location](https://user-images.githubusercontent.com/5656702/122774218-ea27a880-d2a0-11eb-9450-11f119567f26.png) Checkout: ![Checkout showing ExperimentalDiscountsMeta location](https://user-images.githubusercontent.com/5656702/122779606-efd3bd00-d2a5-11eb-8c84-6525eca5d704.png) ### Passed parameters - `cart`: `wc/store/cart` data but in `camelCase` instead of `snake_case`. [Object breakdown.](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/packages/public-api/types/type-defs/cart.ts) - `extensions`: external data registered by third-party developers using `ExtendSchema`, if you used `ExtendSchema` on `wc/store/cart` you would find your data under your namespace here. - `context`, equal to the name of the Block in which the fill is rendered: `woocommerce/cart` or `woocommerce/checkout` --- ## Checkout flow and events *Source: block-development/extensible-blocks/cart-and-checkout-blocks/checkout-payment-methods/checkout-flow-and-events.md* # Checkout flow and events This document gives an overview of the flow for the checkout in the WooCommerce checkout block, and some general architectural overviews. The architecture of the Checkout Block is derived from the following principles: - A single source of truth for data within the checkout flow. - Provide a consistent interface for extension integrations (eg Payment methods). This interface protects the integrity of the checkout process and isolates extension logic from checkout logic. The checkout block handles _all_ communication with the server for processing the order. Extensions are able to react to and communicate with the checkout block via the provided interface. - Checkout flow state is tracked by checkout status. - Extensions are able to interact with the checkout flow via subscribing to emitted events. Here's a high level overview of the flow: ![checkout flow diagram](https://user-images.githubusercontent.com/1628454/113739726-f8c9df00-96f7-11eb-80f1-78e25ccc88cb.png) ## General Concepts ### Tracking flow through status At any point in the checkout lifecycle, components should be able to accurately detect the state of the checkout flow. This includes things like: - Is something loading? What is loading? - Is there an error? What is the error? - is the checkout calculating totals? Using simple booleans can be fine in some cases, but in others it can lead to complicated conditionals and bug prone code (especially for logic behaviour that reacts to various flow state). To surface the flow state, the block uses statuses that are tracked in the various contexts. _As much as possible_ these statuses are set internally in reaction to various actions so there's no implementation needed in children components (components just have to _consume_ the status not set status). The following statuses exist in the Checkout. #### Checkout Data Store Status There are various statuses that are exposed on the Checkout data store via selectors. All the selectors are detailed below and in the [Checkout API docs](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/docs/internal-developers/block-client-apis/checkout/checkout-api.md). You can use them in your component like so ```jsx const { useSelect } = window.wp.data; const { checkoutStore } = window.wc.wcBlocksData; const MyComponent = ( props ) => { const isComplete = useSelect( ( select ) => select( checkoutStore ).isComplete() ); // do something with isComplete }; ``` The following boolean flags available related to status are: **isIdle**: When the checkout status is `IDLE` this flag is true. Checkout will be this status after any change to checkout state after the block is loaded. It will also be this status when retrying a purchase is possible after processing happens with an error. **isBeforeProcessing**: When the checkout status is `BEFORE_PROCESSING` this flag is true. Checkout will be this status when the user submits checkout for processing. **isProcessing**: When the checkout status is `PROCESSING` this flag is true. Checkout will be this status when all the observers on the event emitted with the `BEFORE_PROCESSING` status are completed without error. It is during this status that the block will be sending a request to the server on the checkout endpoint for processing the order. **Note:** there are some checkout payment status changes that happen during this state as well (outlined in the `PaymentProvider` exposed statuses section). **isAfterProcessing**: When the checkout status is `AFTER_PROCESSING` this flag is true. Checkout will have this status after the block receives the response from the server side processing request. **isComplete**: When the checkout status is `COMPLETE` this flag is true. Checkout will have this status after all observers on the events emitted during the `AFTER_PROCESSING` status are completed successfully. When checkout is at this status, the shopper's browser will be redirected to the value of `redirectUrl` at that point (usually the `order-received` route). #### Special States The following booleans are exposed via the checkout provider. They are independent from each other and checkout statuses, but can be used in combination to react to various states in the checkout. ##### **isCalculating** `isCalculating` is true when the total is being re-calculated for the order, or when a plugin is intentionally disabling the checkout using the `disableCheckoutFor` action (covered in the next section). There are numerous things that might trigger a recalculation of the total—coupons being added or removed, shipping rates updating, shipping rates being selected, etc. Instead of having to check each of those individual states, you can reliably check if this boolean is true (calculating) or false (not calculating). What `isCalculating` affects: - Disables the "Place Order" button in the checkout block - Disables the "Proceed to Checkout" button in the cart block - Shows a loading state for Express Payment methods while calculations are pending ###### Controlling `isCalculating` with `disableCheckoutFor` You can programmatically control `isCalculating` using the `disableCheckoutFor` thunk: ```jsx const { dispatch } = window.wp.data; const { checkoutStore } = window.wc.wcBlocksData; // Example: Disable checkout while performing an async operation dispatch( checkoutStore ).disableCheckoutFor( async () => { // Your async operation here, e.g. validating data with an API await myAsyncOperation(); // No need to return anything - we only care about the promise resolving } ); ``` The thunk controls internal state, ensuring that the client won't be able to attempt completing the flow until the provided promise resolves, regardless of whether it succeeds or fails. ##### **hasError** `hasError` is true when anything in the checkout has created an error condition state. This might be validation errors, request errors, coupon application errors, payment processing errors etc. ### `ShippingProvider` Exposed Statuses The shipping context provider exposes everything related to shipping in the checkout. Included in this are a set of error statuses that inform what error state the shipping context is in and the error state is affected by requests to the server on address changes, rate retrieval and selection. Currently the error status may be one of `NONE`, `INVALID_ADDRESS` or `UNKNOWN` (note, this may change in the future). The status is exposed on the `currentErrorStatus` object provided by the `useShippingDataContext` hook. This object has the following properties on it: - `isPristine` and `isValid`: Both of these booleans are connected to the same error status. When the status is `NONE` the values for these booleans will be `true`. It basically means there is no shipping error. - `hasInvalidAddress`: When the address provided for shipping is invalid, this will be true. - `hasError`: This is `true` when the error status for shipping is either `UNKNOWN` or `hasInvalidAddress`. ### Payment Method Data Store Status The status of the payment lives in the payment data store. You can query the status with the following selectors: ```jsx const { select } = window.wp.data; const { paymentStore } = window.wc.wcBlocksData; const MyComponent = ( props ) => { const isPaymentIdle = select( paymentStore ).isPaymentIdle(); const isExpressPaymentStarted = select( paymentStore ).isExpressPaymentStarted(); const isPaymentProcessing = select( paymentStore ).isPaymentProcessing(); const isPaymentReady = select( paymentStore ).isPaymentReady(); const hasPaymentError = select( paymentStore ).hasPaymentError(); // do something with the boolean values }; ``` The status here will help inform the current state of _client side_ processing for the payment and are updated via the store actions at different points throughout the checkout processing cycle. _Client side_ means the state of processing any payments by registered and active payment methods when the checkout form is submitted via those payment methods registered client side components. It's still possible that payment methods might have additional server side processing when the order is being processed but that is not reflected by these statuses (more in the [payment method integration doc](./payment-method-integration.md)). The possible _internal_ statuses that may be set are: - `IDLE`: This is the status when checkout is initialized and there are payment methods that are not doing anything. This status is also set whenever the checkout status is changed to `IDLE`. - `EXPRESS_STARTED`: **Express Payment Methods Only** - This status is used when an express payment method has been triggered by the user clicking it's button. This flow happens before processing, usually in a modal window. - `PROCESSING`: This status is set when the checkout status is `PROCESSING`, checkout `hasError` is false, checkout is not calculating, and the current payment status is not `FINISHED`. When this status is set, it will trigger the payment processing event emitter. - `READY`: This status is set after all the observers hooked into the payment processing event have completed successfully. The `CheckoutProcessor` component uses this along with the checkout `PROCESSING` status to signal things are ready to send the order to the server with data for processing and to take payment - `ERROR`: This status is set after an observer hooked into the payment processing event returns an error response. This in turn will end up causing the checkout `hasError` flag to be set to true. ### Emitting Events Another tricky thing for extensibility, is providing opinionated, yet flexible interfaces for extensions to act and react to specific events in the flow. For stability, it's important that the core checkout flow _controls_ all communication to and from the server specific to checkout/order processing and leave extension specific requirements for the extension to handle. This allows for extensions to predictably interact with the checkout data and flow as needed without impacting other extensions hooking into it. One of the most reliable ways to implement this type of extensibility is via the usage of an events system. Thus the various context providers: - expose subscriber APIs for extensions to subscribe _observers_ to the events they want to react to. - emit events at specific points of the checkout flow that in turn will feed data to the registered observers and, in some cases, react accordingly to the responses from observers. One _**very important rule**_ when it comes to observers registered to any event emitter in this system is that they _cannot_ update context state. Updating state local to a specific component is okay but not any context or global state. The reason for this is that the observer callbacks are run sequentially at a specific point and thus subsequent observers registered to the same event will not react to any change in global/context state in earlier executed observers. ```jsx const unsubscribe = emitter( myCallback ); ``` You could substitute in whatever emitter you are registering for the `emitter` function. So for example if you are registering for the `onCheckoutValidation` event emitter, you'd have something like: ```jsx const unsubscribe = onCheckoutValidation( myCallback ); ``` You can also indicate what priority you want your observer to execute at. Lower priority is run before higher priority, so you can affect when your observer will run in the stack of observers registered to an emitter. You indicate priority via an number on the second argument: ```jsx const unsubscribe = onCheckoutValidation( myCallback, 10 ); ``` In the examples, `myCallback`, is your subscriber function. The subscriber function could receive data from the event emitter (described in the emitter details below) and may be expected to return a response in a specific shape (also described in the specific emitter details). The subscriber function can be a `Promise` and when the event emitter cycles through the registered observers it will await for any registered Promise to resolve. Finally, the return value of the call to the emitter function is an unsubscribe function that can be used to unregister your observer. This is especially useful in a React component context where you need to make sure you unsubscribe the observer on component unmount. An example is usage in a `useEffect` hook: ```jsx const MyComponent = ( { onCheckoutValidation } ) => { useEffect( () => { const unsubscribe = onCheckoutValidation( () => true ); return unsubscribe; }, [ onCheckoutValidation ] ); return null; }; ``` **`Event Emitter Utilities`** There are a bunch of utility methods that can be used related to events. These are available in `assets/js/base/context/event-emit/utils.ts` and can be imported as follows: ```jsx import { noticeContexts, responseTypes, shouldRetry, } from '@woocommerce/base-context'; import { isSuccessResponse, isErrorResponse, isFailResponse, } from '@woocommerce/types'; ``` The helper functions are described below: - `isSuccessResponse`, `isErrorResponse` and `isFailResponse`: These are helper functions that receive a value and report via boolean whether the object is a type of response expected. For event emitters that receive responses from registered observers, a `type` property on the returned object from the observer indicates what type of response it is and event emitters will react according to that type. So for instance if an observer returned `{ type: 'success' }` the emitter could feed that to `isSuccessResponse` and it would return `true`. You can see an example of this being implemented for the [payment processing emitted event here](https://github.com/woocommerce/woocommerce/blob/df02d62e2d41e9007da44cb87fea2b7a9551f55c/plugins/woocommerce/client/blocks/packages/public-api/types/type-guards/observers.ts#L41-L65). - `noticeContexts`: This is an object containing properties referencing areas where notices can be targeted in the checkout. The object has the following properties: - `PAYMENTS`: This is a reference to the notice area in the payment methods step. - `EXPRESS_PAYMENTS`: This is a reference to the notice area in the express payment methods step. - `responseTypes`: This is an object containing properties referencing the various response types that can be returned by observers for some event emitters. It makes it easier for autocompleting the types and avoiding typos due to human error. The types are `SUCCESS`, `FAIL`, `ERROR`. The values for these types also correspond to the [payment status types](https://github.com/woocommerce/woocommerce/blob/2db0cfdaecc7cc60a45790e760e71c26edc4f295/plugins/woocommerce/src/StoreApi/Payments/PaymentResult.php#L13) from the [checkout endpoint response from the server](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/StoreApi/Schemas/V1/CheckoutSchema.php). - `shouldRetry`: This is a function containing the logic whether the checkout flow should allow the user to retry the payment after a previous payment failed. It receives the `response` object and by default checks whether the `retry` property is true/undefined or false. Refer to the [`onCheckoutSuccess`](#oncheckoutsuccess) documentation for more details. Note: `noticeContexts` and `responseTypes` are exposed to payment methods via the `emitResponse` prop given to their component: ```jsx const MyPaymentMethodComponent = ( { emitResponse } ) => { const { noticeContexts, responseTypes } = emitResponse; // other logic for payment method... }; ``` The following event emitters are available to extensions to register observers to: ### `onCheckoutValidation` Observers registered to this event emitter will receive nothing as an argument. Also, all observers will be executed before the checkout handles the responses from the emitters. Observers registered to this emitter can return `true` if they have nothing to communicate back to checkout, `false` if they want checkout to go back to `IDLE` status state, or an object with any of the following properties: - `errorMessage`: This will be added as an error notice on the checkout context. - `validationErrors`: This will be set as inline validation errors on checkout fields. If your observer wants to trigger validation errors it can use the following shape for the errors: - This is an object where keys are the property names the validation error is for (that correspond to a checkout field, eg `country` or `coupon`) and values are the error message describing the validation problem. This event is emitted when the checkout status is `BEFORE_PROCESSING` (which happens at validation time, after the checkout form submission is triggered by the user - or Express Payment methods). If all observers return `true` for this event, then the checkout status will be changed to `PROCESSING`. This event emitter subscriber can be obtained via the checkout context using the `useCheckoutContext` hook or to payment method extensions as a prop on their registered component: _For internal development:_ ```jsx import { useCheckoutContext } from '@woocommerce/base-contexts'; import { useEffect } from '@wordpress/element'; const Component = () => { const { onCheckoutValidation } = useCheckoutContext(); useEffect( () => { const unsubscribe = onCheckoutValidation( () => true ); return unsubscribe; }, [ onCheckoutValidation ] ); return null; }; ``` _For registered payment method components:_ ```jsx const { useEffect } = window.wp.element; const PaymentMethodComponent = ( { eventRegistration } ) => { const { onCheckoutValidation } = eventRegistration; useEffect( () => { const unsubscribe = onCheckoutValidation( () => true ); return unsubscribe; }, [ onCheckoutValidation ] ); }; ``` _For anything else:_ ```jsx const { onCheckoutValidation } = wc.blocksCheckoutEvents; useEffect( () => { const unsubscribe = onCheckoutValidation( () => true ); return unsubscribe; }, [ onCheckoutValidation ] ); ``` ### ~~`onPaymentProcessing`~~ This is now deprecated and replaced by the `onPaymentSetup` event emitter. ### `onPaymentSetup` This event emitter was fired when the payment method context status is `PROCESSING` and that status is set when the checkout status is `PROCESSING`, checkout `hasError` is false, checkout is not calculating, and the current payment status is not `FINISHED`. This event emitter will execute through each registered observer (passing in nothing as an argument) _until_ an observer returns a non-truthy value at which point it will _abort_ further execution of registered observers. When a payment method returns a non-truthy value, if it returns a valid response type the event emitter will update various internal statuses according to the response. Here's the possible response types that will get handled by the emitter: #### Success A successful response should be given when the user's entered data is correct and the payment checks are successful. A response is considered successful if, at a minimum, it is an object with this shape: ```js const successResponse = { type: 'success' }; ``` When a success response is returned, the payment method context status will be changed to `SUCCESS`. In addition, including any of the additional properties will result in extra actions: - `paymentMethodData`: The contents of this object will be included as the value for `payment_data` when checkout sends a request to the checkout endpoint for processing the order. This is useful if a payment method does additional server side processing. - `billingAddress`: This allows payment methods to update any billing data information in the checkout (typically used by Express payment methods) so it's included in the checkout processing request to the server. This data should be in the [shape outlined here](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/packages/public-api/settings/default-fields.ts). - `shippingAddress`: This allows payment methods to update any shipping data information for the order (typically used by Express payment methods) so it's included in the checkout processing request to the server. This data should be in the [shape outlined here](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/packages/public-api/settings/default-fields.ts). If `billingAddress` or `shippingAddress` properties aren't in the response object, then the state for the data is left alone. #### Fail A fail response should be given when there is an error with the payment processing. A response is considered a fail response when it is an object with this shape: ```js const failResponse = { type: 'failure' }; ``` When a fail response is returned by an observer, the payment method context status will be changed to `FAIL`. In addition, including any of the following properties will result in extra actions: - `message`: The string provided here will be set as an error notice in the checkout. - `messageContext`: If provided, this will target the given area for the error notice (this is where `noticeContexts` mentioned earlier come in to play). Otherwise the notice will be added to the `noticeContexts.PAYMENTS` area. - `paymentMethodData`: (same as for success responses). - `billingAddress`: (same as for success responses). #### Error An error response should be given when there is an error with the user input on the checkout form. A response is considered an error response when it is an object with this shape: ```js const errorResponse = { type: 'error' }; ``` When an error response is returned by an observer, the payment method context status will be changed to `ERROR`. In addition, including any of the following properties will result in extra actions: - `message`: The string provided here will be set as an error notice. - `messageContext`: If provided, this will target the given area for the error notice (this is where `noticeContexts` mentioned earlier come in to play). Otherwise, the notice will be added to the `noticeContexts.PAYMENTS` area. - `validationErrors`: This will be set as inline validation errors on checkout fields. If your observer wants to trigger validation errors it can use the following shape for the errors: - This is an object where keys are the property names the validation error is for (that correspond to a checkout field, eg `country` or `coupon`) and values are the error message describing the validation problem. If the response object doesn't match any of the above conditions, then the fallback is to set the payment status as `SUCCESS`. When the payment status is set to `SUCCESS` and the checkout status is `PROCESSING`, the `CheckoutProcessor` component will trigger the request to the server for processing the order. This event emitter subscriber can be obtained via the checkout context using the `usePaymentEventsContext` hook or to payment method extensions as a prop on their registered component: _For internal development:_ ```jsx import { usePaymentEventsContext } from '@woocommerce/base-contexts'; import { useEffect } from '@wordpress/element'; const Component = () => { const { onPaymentSetup } = usePaymentEventsContext(); useEffect( () => { const unsubscribe = onPaymentSetup( () => true ); return unsubscribe; }, [ onPaymentSetup ] ); return null; }; ``` _For registered payment method components:_ ```jsx const { useEffect } = window.wp.element; const PaymentMethodComponent = ( { eventRegistration } ) => { const { onPaymentSetup } = eventRegistration; useEffect( () => { const unsubscribe = onPaymentSetup( () => true ); return unsubscribe; }, [ onPaymentSetup ] ); }; ``` ### `onCheckoutSuccess` This event emitter is fired when the checkout status is `AFTER_PROCESSING` and the checkout `hasError` state is false. The `AFTER_PROCESSING` status is set by the `CheckoutProcessor` component after receiving a response from the server for the checkout processing request. Observers registered to this event emitter will receive the following object as an argument: ```js const onCheckoutProcessingData = { redirectUrl, orderId, customerId, orderNotes, paymentResult, }; ``` The properties are: - `redirectUrl`: This is a string that is the url the checkout will redirect to as returned by the processing on the server. - `orderId`: Is the id of the current order being processed. - `customerId`: Is the id for the customer making the purchase (that is attached to the order). - `orderNotes`: This will be any custom note the customer left on the order. - `paymentResult`: This is the value of [`payment_result` from the /checkout StoreApi response](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/StoreApi/Schemas/V1/CheckoutSchema.php). The data exposed on this object is (via the object properties): - `paymentStatus`: Whatever the status is for the payment after it was processed server side. Will be one of `success`, `failure`, `pending`, `error`. - `paymentDetails`: This will be an arbitrary object that contains any data the payment method processing server side sends back to the client in the checkout processing response. Payment methods are able to hook in on the processing server side and set this data for returning. This event emitter will invoke each registered observer until a response from any of the registered observers does not equal `true`. At that point any remaining non-invoked observers will be skipped and the response from the observer triggering the abort will be processed. This emitter will handle a `success` response type (`{ type: success }`) by setting the checkout status to `COMPLETE`. Along with that, if the response includes `redirectUrl` then the checkout will redirect to the given address. This emitter will also handle a `failure` response type or an `error` response type and if no valid type is detected it will treat it as an `error` response type. In all cases, if there are the following properties in the response, additional actions will happen: - `message`: This string will be added as an error notice. - `messageContext`: If present, the notice will be configured to show in the designated notice area (otherwise it will just be a general notice for the checkout block). - `retry`: If this is `true` or not defined, then the checkout status will be set to `IDLE`. This basically means that the error is recoverable (for example try a different payment method) and so checkout will be reset to `IDLE` for another attempt by the shopper. If this is `false`, then the checkout status is set to `COMPLETE` and the checkout will redirect to whatever is currently set as the `redirectUrl`. - `redirectUrl`: If this is present, then the checkout will redirect to this url when the status is `COMPLETE`. If all observers return `true`, then the checkout status will just be set to `COMPLETE`. This event emitter subscriber can be obtained via the checkout context using the `useCheckoutContext` hook or to payment method extensions as a prop on their registered component: _For internal development:_ ```jsx import { useCheckoutContext } from '@woocommerce/base-contexts'; import { useEffect } from '@wordpress/element'; const Component = () => { const { onCheckoutSuccess } = useCheckoutContext(); useEffect( () => { const unsubscribe = onCheckoutSuccess( () => true ); return unsubscribe; }, [ onCheckoutSuccess ] ); return null; }; ``` _For registered payment method components:_ ```jsx const { useEffect } = window.wp.element; const PaymentMethodComponent = ( { eventRegistration } ) => { const { onCheckoutSuccess } = eventRegistration; useEffect( () => { const unsubscribe = onCheckoutSuccess( () => true ); return unsubscribe; }, [ onCheckoutSuccess ] ); }; ``` _For anything else:_ ```jsx const { onCheckoutSuccess } = wc.blocksCheckoutEvents; useEffect( () => { const unsubscribe = onCheckoutSuccess( () => true ); return unsubscribe; }, [ onCheckoutSuccess ] ); ``` ### `onCheckoutFail` This event emitter is fired when the checkout status is `AFTER_PROCESSING` and the checkout `hasError` state is `true`. The `AFTER_PROCESSING` status is set by the `CheckoutProcessor` component after receiving a response from the server for the checkout processing request. Observers registered to this emitter will receive the same data package as those registered to `onCheckoutSuccess`. The response from the first observer returning a value that does not `===` true will be handled similarly as the `onCheckoutSuccess` except it only handles when the type is `error` or `failure`. If all observers return `true`, then the checkout status will just be set to `IDLE` and a default error notice will be shown in the checkout context. This event emitter subscriber can be obtained via the checkout context using the `useCheckoutContext` hook or to payment method extensions as a prop on their registered component: _For internal development:_ ```jsx import { useCheckoutContext } from '@woocommerce/base-contexts'; import { useEffect } from '@wordpress/element'; const Component = () => { const { onCheckoutFail } = useCheckoutContext(); useEffect( () => { const unsubscribe = onCheckoutFail( () => true ); return unsubscribe; }, [ onCheckoutFail ] ); return null; }; ``` _For registered payment method components:_ ```jsx const { useEffect } = window.wp.element; const PaymentMethodComponent = ( { eventRegistration } ) => { const { onCheckoutFail } = eventRegistration; useEffect( () => { const unsubscribe = onCheckoutFail( () => true ); return unsubscribe; }, [ onCheckoutFail ] ); }; ``` _For anything else:_ ```jsx const { onCheckoutFail } = wc.blocksCheckoutEvents; useEffect( () => { const unsubscribe = onCheckoutFail( () => true ); return unsubscribe; }, [ onCheckoutFail ] ); ``` ### `onShippingRateSuccess` This event emitter is fired when shipping rates are not loading and the shipping data context error state is `NONE` and there are shipping rates available. This event emitter doesn't care about any registered observer response and will simply execute all registered observers passing them the current shipping rates retrieved from the server. ### `onShippingRateFail` This event emitter is fired when shipping rates are not loading and the shipping data context error state is `UNKNOWN` or `INVALID_ADDRESS`. This event emitter doesn't care about any registered observer response and will simply execute all registered observers passing them the current error status in the context. ### `onShippingRateSelectSuccess` This event emitter is fired when a shipping rate selection is not being persisted to the server and there are selected rates available and the current error status in the context is `NONE`. This event emitter doesn't care about any registered observer response and will simply execute all registered observers passing them the current selected rates. ### `onShippingRateSelectFail` This event emitter is fired when a shipping rate selection is not being persisted to the server and the shipping data context error state is `UNKNOWN` or `INVALID_ADDRESS`. This event emitter doesn't care about any registered observer response and will simply execute all registered observers passing them the current error status in the context. --- ## Filtering payment methods in the Checkout block *Source: block-development/extensible-blocks/cart-and-checkout-blocks/checkout-payment-methods/filtering-payment-methods.md* # Filtering payment methods in the Checkout block ## The problem You're an extension developer, and your extension is conditionally hiding payment gateways on the checkout step. You need to be able to hide payment gateways on the Checkout block using a front-end extensibility point. ### The solution WooCommerce Blocks provides a function called `registerPaymentMethodExtensionCallbacks` which allows extensions to register callbacks for specific payment methods to determine if they can make payments. ### Importing #### Aliased import ```js import { registerPaymentMethodExtensionCallbacks } from '@woocommerce/blocks-registry'; ``` #### `wc global` ```js const { registerPaymentMethodExtensionCallbacks } = window.wc.wcBlocksRegistry; ``` ### Signature | Parameter | Description | Type | | ----------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- | | `namespace` | Unique string to identify your extension. Choose something that eliminates a name collision with another extension. | `string` | | `callbacks` | An object containing callbacks registered for different payment methods | Record< string, CanMakePaymentExtensionCallback > | Read more below about [callbacks](#callbacks-registered-for-payment-methods). #### Extension namespace collision When trying to register callbacks under an extension namespace already used with `registerPaymentMethodExtensionCallbacks`, the registration will be aborted and you will be notified that you are not using a unique namespace. This will be shown in the JavaScript console. ### Usage example ```js registerPaymentMethodExtensionCallbacks( 'my-hypothetical-extension', { cod: ( arg ) => { return arg.shippingAddress.city === 'Berlin'; }, cheque: ( arg ) => { return false; }, } ); ``` ### Callbacks registered for payment methods Extensions can register only one callback per payment method: ```text payment_method_name: ( arg ) => {...} ``` `payment_method_name` is the value of the [name property](/docs/block-development/extensible-blocks/cart-and-checkout-blocks/checkout-payment-methods/payment-method-integration) used when the payment method was registered with WooCommerce Blocks. The registered callbacks are used to determine whether the corresponding payment method should be available as an option for the shopper. The function will be passed an object containing data about the current order. ```ts type CanMakePaymentExtensionCallback = ( cartData: CanMakePaymentArgument ) => boolean; ``` Each callback will have access to the information bellow ```ts interface CanMakePaymentArgument { cart: Cart; cartTotals: CartTotals; cartNeedsShipping: boolean; billingAddress: CartResponseBillingAddress; shippingAddress: CartResponseShippingAddress; selectedShippingMethods: Record< string, unknown >; paymentRequirements: Array< string >; } ``` If you need data that is not available in the parameter received by the callback you can consider [exposing your data in the Store API](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/docs/third-party-developers/extensibility/rest-api/extend-rest-api-add-data.md). ## Filtering payment methods using requirements ### The problem Your extension has added functionality to your store in such a way that only specific payment gateways can process orders that contain certain products. Using the example of `Bookings` if the shopper adds a `Bookable` product to their cart, for example a stay in a hotel, and you, the merchant, want to confirm all bookings before taking payment. You would still need to capture the customer's checkout details but not their payment method at that point. ### The solution To allow the shopper to check out without entering payment details, but still require them to fill in the other checkout details it is possible to create a new payment method which will handle carts containing a `Bookable` item. Using the `supports` configuration of payment methods it is possible to prevent other payment methods (such as credit card, PayPal etc.) from being used to check out, and only allow the one your extension has added to appear in the Checkout block. For more information on how to register a payment method with WooCommerce Blocks, please refer to the [Payment method integration](./payment-method-integration.md) documentation. ### Basic usage Following the documentation for registering payment methods linked above, you should register your payment method with a unique `supports` feature, for example `booking_availability`. This will be used to isolate it and prevent other methods from displaying. First you will need to create a function that will perform the checks on the cart to determine what the specific payment requirements of the cart are. Below is an example of doing this for our `Bookable` products. Then you will need to use the `register_payment_requirements` on the `ExtendSchema` class to tell the Checkout block to execute a callback to check for requirements. ### Putting it all together This code example assumes there is some class called `Pseudo_Booking_Class` that has the `cart_contains_bookable_product` method available. The implementation of this method is not relevant here. ```php /** * Check the content of the cart and add required payment methods. * * * @return array list of features required by cart items. */ function inject_payment_feature_requirements_for_cart_api() { // Cart contains a bookable product, so return an array containing our requirement of booking_availability. if ( Pseudo_Booking_Class::cart_contains_bookable_product() ) { return array( 'booking_availability' ); } // No bookable products in the cart, no need to add anything. return array(); } ``` To summarise the above: if there's a bookable product in the cart then this function will return an array containing `booking_availability`, otherwise it will return an empty array. The next step will tell the `ExtendSchema` class to execute this callback when checking which payment methods to display. To do this you could use the following code: ```php add_action('woocommerce_blocks_loaded', function() { woocommerce_store_api_register_payment_requirements( array( 'data_callback' => 'inject_payment_feature_requirements_for_cart_api', ) ); }); ``` It is important to note the comment in this code block, you must not instantiate your own version of `ExtendSchema`. If you've added your payment method correctly with the correct `supports` values then when you reach the checkout page with a `Bookable` item in your cart, any method that does not `supports` the `booking_availability` requirement should not display, while yours, the one that _does_ support this requirement _will_ display. --- ## Payment method integration *Source: block-development/extensible-blocks/cart-and-checkout-blocks/checkout-payment-methods/payment-method-integration.md* # Payment method integration ## Client Side integration The client side integration consists of an API for registering both _regular_ and _express_ payment methods. In both cases, the client side integration is done using registration methods exposed on the `blocks-registry` API. You can access this via the `wc` global in a WooCommerce environment (`wc.wcBlocksRegistry`). > Note: The `@woocommerce/blocks-registry` import examples in this document require a build process that maps WooCommerce packages to their registered script handles. Do not install `@woocommerce/blocks-registry` from npm. Use the [`@woocommerce/dependency-extraction-webpack-plugin`](https://www.npmjs.com/package/@woocommerce/dependency-extraction-webpack-plugin) in your webpack configuration to externalize bundled WooCommerce packages such as `@woocommerce/blocks-registry` to the `wc-blocks-registry` script. ## Express Payment Methods Express payment methods are payment methods that consist of a one-button payment process initiated by the shopper such as Stripe, ApplePay, or GooglePay. ![Express Payment Area](https://user-images.githubusercontent.com/1429108/79565636-17fed500-807f-11ea-8e5d-9af32e43b71d.png) ### Registration To register an express payment method, you use the `registerExpressPaymentMethod` function from the blocks registry. ```js const { registerExpressPaymentMethod } = window.wc.wcBlocksRegistry; ``` If you're using an aliased import for `@woocommerce/blocks-registry`, you can import the function like this: ```js import { registerExpressPaymentMethod } from '@woocommerce/blocks-registry'; ``` The registry function expects a JavaScript object with options specific to the payment method: ```js registerExpressPaymentMethod( options ); ``` The options you feed the configuration instance should be an object in this shape (see `ExpressPaymentMethodConfiguration` typedef): ```js const options = { name: 'my_payment_method', title: 'My Mayment Method', description: 'A setence or two about your payment method', gatewayId: 'gateway-id', label: , content: , edit: , canMakePayment: () => true, paymentMethodId: 'my_payment_method', supports: { features: [], style: [], }, }; ``` #### `ExpressPaymentMethodConfiguration` | Option | Type | Description | Required | | --- | --- | --- | --- | | `name` | String | Unique identifier for the gateway client side. | Yes | | `title` | String | Human readable name of your payment method. Displayed to the merchant in the editor. | No | | `description` | String | One or two sentences describing your payment gateway. Displayed to the merchant in the editor. | No | | `gatewayId` | String | ID of the Payment Gateway registered server side. Used to direct the merchant to the right settings page within the editor. If this is not provided, the merchant will be redirected to the general Woo payment settings page. | No | | `content` | ReactNode | React node output in the express payment method area when the block is rendered in the frontend. Receives props from the checkout payment method interface. | Yes | | `edit` | ReactNode | React node output in the express payment method area when the block is rendered in the editor. Receives props from the payment method interface to checkout (with preview data). | Yes | | `canMakePayment` | Function | Callback to determine whether the payment method should be available for the shopper. | Yes | | `paymentMethodId` | String | Identifier accompanying the checkout processing request to the server. Used to identify the payment method gateway class for processing the payment. Should match the gateway's server-side ID, as it is also used to detect whether the gateway is compatible with the Checkout block in the editor. Defaults to the value of `name` when omitted. | No | | `supports:features` | Array | Array of payment features supported by the gateway. Used to crosscheck if the payment method can be used for the cart content. Defaults to `['products']` if no value is provided. | No | | `supports:style` | Array | This is an array of style variations supported by the express payment method. These are styles that are applied across all the active express payment buttons and can be controlled from the express payment block in the editor. Supported values for these are one of `['height', 'borderRadius']`. | No | #### The `canMakePayment` option `canMakePayment` is a callback to determine whether the payment method should be available as an option for the shopper. The function will be passed an object containing data about the current order. ```ts canMakePayment( { cart: Cart, cartTotals: CartTotals, cartNeedsShipping: boolean, shippingAddress: CartShippingAddress, billingAddress: CartBillingAddress, selectedShippingMethods: Record, paymentRequirements: string[], } ) ``` `canMakePayment` returns a boolean value. If your gateway needs to perform async initialization to determine availability, you can return a promise (resolving to boolean). This allows a payment method to be hidden based on the cart, e.g. if the cart has physical/shippable products (example: [`Cash on delivery`](https://github.com/woocommerce/woocommerce/blob/df02d62e2d41e9007da44cb87fea2b7a9551f55c/plugins/woocommerce/client/blocks/assets/js/extensions/payment-methods/cod/index.js#L46-L73)); or for payment methods to control whether they are available depending on other conditions. `canMakePayment` only runs on the frontend of the Store. In editor context, rather than use `canMakePayment`, the editor will assume the payment method is available (true) so that the defined `edit` component is shown to the merchant. **Keep in mind this function could be invoked multiple times in the lifecycle of the checkout and thus any expensive logic in the callback provided on this property should be memoized.** ### Button Attributes for Express Payment Methods This API provides a way to synchronise the look and feel of the express payment buttons for a coherent shopper experience. Express Payment Methods must prefer the values provided in the `buttonAttributes`, and use it's own configuration settings as backup when the buttons are rendered somewhere other than the Cart or Checkout block. For example, in your button component, you would do something like this: ```js // Get your extension specific settings and set defaults if not available let { borderRadius = '4', height = '48', } = getButtonSettingsFromConfig(); // In a cart & checkout block context, we receive `buttonAttributes` as a prop which overwrite the extension specific settings if ( typeof buttonAttributes !== 'undefined' ) { height = buttonAttributes.height; borderRadius = buttonAttributes.borderRadius; } ... return ); } return ( ); }; registerPaymentMethod( { name: 'my-custom-payment', label:
My Custom Payment
, content:
Payment method description
, edit:
Payment method description
, placeOrderButton: CustomButton, canMakePayment: () => true, supports: { features: [ 'products' ], }, } ); ``` **Note:** The custom button is only shown when the payment method is selected from the list. When a saved payment token is selected, the default "Place Order" button is used instead. ## Props Fed to Payment Method Nodes A big part of the payment method integration is the interface that is exposed for payment methods to use via props when the node provided is cloned and rendered on block mount. While all the props are listed below, you can find more details about what the props reference, their types etc via the [typedefs described in this file](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/client/blocks/packages/public-api/types/type-defs/payment-method-interface.ts). | Property | Type | Description | | --- | --- | --- | | `activePaymentMethod` | String | The slug of the current active payment method in the checkout. | | `billing` | Object with billingAddress, cartTotal, currency, cartTotalItems, displayPricesIncludingTax, appliedCoupons, customerId properties | Contains everything related to billing. | | `cartData` | Object with cartItems, cartFees, extensions properties | Data exposed from the cart including items, fees, and any registered extension data. Note that this data should be treated as immutable (should not be modified/mutated) or it will result in errors in your application. | | `checkoutStatus` | Object with isCalculating, isComplete, isIdle, isProcessing properties | The current checkout status exposed as various boolean state. | | `components` | Object with ValidationInputError, PaymentMethodLabel, PaymentMethodIcons, LoadingMask properties | It exposes React components that can be implemented by your payment method for various common interface elements used by payment methods. | | `emitResponse` | Object with noticeContexts and responseTypes properties | Contains some constants that can be helpful when using the event emitter. Read the _[Emitting Events](./checkout-flow-and-events.md#emitting-events)_ section for more details. | | `eventRegistration` | Object with onCheckoutValidation, onCheckoutSuccess, onCheckoutFail, onPaymentSetup, onShippingRateSuccess, onShippingRateFail, onShippingRateSelectSuccess, onShippingRateSelectFail properties | Contains all the checkout event emitter registration functions. These are functions the payment method can register observers on to interact with various points in the checkout flow (see [this doc](./checkout-flow-and-events.md) for more info). | | `onClick` | Function | **Provided to express payment methods** that should be triggered when the payment method button is clicked (which will signal to checkout the payment method has taken over payment processing) | | `onClose` | Function | **Provided to express payment methods** that should be triggered when the express payment method modal closes and control is returned to checkout. | | `onSubmit` | Function | Submits the checkout and begins processing | | `validate` | Function | Async function that validates the checkout form without submitting. Returns a promise resolving to `{ hasError: boolean }`. Useful when you need to validate before showing a payment sheet. | | `buttonAttributes` | Object with height, borderRadius properties | Styles set by the merchant that should be respected by all express payment buttons | | `paymentStatus` | Object | Various payment status helpers. Note, your payment method does not have to handle setting this status client side. Checkout will handle this via the responses your payment method gives from observers registered to [checkout event emitters](./checkout-flow-and-events.md). | | `paymentStatus.isPristine` | Boolean | This is true when the current payment status is `PRISTINE`. | | `paymentStatus.isStarted` | Boolean | This is true when the current payment status is `EXPRESS_STARTED`. | | `paymentStatus.isProcessing` | Boolean | This is true when the current payment status is `PROCESSING`. | | `paymentStatus.isFinished` | Boolean | This is true when the current payment status is one of `ERROR`, `FAILED`, or `SUCCESS`. | | `paymentStatus.hasError` | Boolean | This is true when the current payment status is `ERROR`. | | `paymentStatus.hasFailed` | Boolean | This is true when the current payment status is `FAILED`. | | `paymentStatus.isSuccessful` | Boolean | This is true when the current payment status is `SUCCESS`. | | `setExpressPaymentError` | Function | Receives a string and allows express payment methods to set an error notice for the express payment area on demand. This can be necessary because some express payment method processing might happen outside of checkout events. | | `shippingData` | Object with shippingRates, shippingRatesLoading, selectedRates, setSelectedRates, isSelectingRate, shippingAddress, setShippingAddress, needsShipping properties | Contains all shipping related data (outside of the shipping status). | | `shippingStatus` | Object with shippingErrorStatus, shippingErrorTypes properties | Various shipping status helpers. | | `shouldSavePayment` | Boolean | Indicates whether or not the shopper has selected to save their payment method details (for payment methods that support saved payments). True if selected, false otherwise. Defaults to false. | Any registered `savedTokenComponent` node will also receive a `token` prop which includes the id for the selected saved token in case your payment method needs to use it for some internal logic. However, keep in mind, this is just the id representing this token in the database (and the value of the radio input the shopper checked), not the actual customer payment token (since processing using that usually happens on the server for security). ## Server Side Integration For the server side integration, you need to create a class that extends the `Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType` class. This class is the server side representation of your payment method. It is used to handle the registration of your payment methods assets with the Store API and Checkout block at the correct time. It is not the same as the [Payment Gateway API](/features/payments/payment-gateway-api.md) that you need to implement separately for payment processing. ### Example Payment Method Integration Class ```php settings = get_option( 'woocommerce_my_payment_method_settings', [] ); } /** * This should return whether the payment method is active or not. * * If false, the scripts will not be enqueued. * * @return boolean */ public function is_active() { return filter_var( $this->get_setting( 'enabled', false ), FILTER_VALIDATE_BOOLEAN ); } /** * Returns an array of scripts/handles to be registered for this payment method. * * In this function you should register your payment method scripts (using `wp_register_script`) and then return the * script handles you registered with. This will be used to add your payment method as a dependency of the checkout script * and thus take sure of loading it correctly. * * Note that you should still make sure any other asset dependencies your script has are registered properly here, if * you're using Webpack to build your assets, you may want to use the WooCommerce Webpack Dependency Extraction Plugin * (https://www.npmjs.com/package/@woocommerce/dependency-extraction-webpack-plugin) to make this easier for you. * * @return array */ public function get_payment_method_script_handles() { wp_register_script( 'my-payment-method', 'path/to/your/script/my-payment-method.js', [], '1.0.0', true ); return [ 'my-payment-method' ]; } /** * Returns an array of script handles to be enqueued for the admin. * * Include this if your payment method has a script you _only_ want to load in the editor context for the checkout block. * Include here any script from `get_payment_method_script_handles` that is also needed in the admin. */ public function get_payment_method_script_handles_for_admin() { return $this->get_payment_method_script_handles(); } /** * Returns an array of key=>value pairs of data made available to the payment methods script client side. * * This data will be available client side via `wc.wcSettings.getSetting`. So for instance if you assigned `stripe` as the * value of the `name` property for this class, client side you can access any data via: * `wc.wcSettings.getSetting( 'stripe_data' )`. That would return an object matching the shape of the associative array * you returned from this function. * * @return array */ public function get_payment_method_data() { return [ 'title' => $this->get_setting( 'title' ), 'description' => $this->get_setting( 'description' ), 'supports' => $this->get_supported_features(), ]; } } ``` ### Registering the Payment Method Integration After creating a class that extends `Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType`, you need to register it with the server side handling of payment methods. You can do this by using the `register` method on the `PaymentMethodRegistry` class. ```php use MyPlugin\MyPaymentMethod\MyPaymentMethodType; use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry; add_action( 'woocommerce_blocks_payment_method_type_registration', function( PaymentMethodRegistry $payment_method_registry ) { $payment_method_registry->register( new MyPaymentMethodType() ); } ); ``` ## Processing Payments (legacy support) Payments are still handled via the [Payment Gateway API](/features/payments/payment-gateway-api.md). This is a separate API from the one used for the payment methods integration above. The checkout block converts incoming `payment_data` provided by the client-side script to `$_POST` and calls the Payment Gateway `process_payment` method. _If you already have a WooCommerce Payment method extension integrated with the shortcode checkout flow, the legacy handling will take care of processing your payment for you on the server side._ ## Processing Payments via the Store API There may be more advanced cases where the legacy payment processing mentioned earlier doesn't work for your existing payment method integration. For these cases, there is also an action hook you can use to handle the server side processing of the order which provides more context and is specific to the Store API. This hook is the _preferred_ place to hook in your payment processing: ```php do_action_ref_array( 'woocommerce_rest_checkout_process_payment_with_context', [ $context, &$result ] ); ``` > Note: A good place to register your callback on this hook is in the `initialize` method of the payment method type class you created earlier A callback on this hook will receive: - A `PaymentContext` object which contains the chosen `payment_method` (this is the same as the `paymentMethodId` value defined when registering your payment method), the `order` being placed, and any additional `payment_data` provided by the payment method client. - A `PaymentResult` object which you can use to set the status, redirect url, and any additional payment details back to the client via the Store API. If you set a status on the provided `PaymentResult` object, legacy payment processing will be ignored for your payment method. If there is an error, your callback can throw an exception which will be handled by the Store API. Here is an example callback: ```php add_action( 'woocommerce_rest_checkout_process_payment_with_context', function( $context, $result ) { if ( $context->payment_method === 'my_payment_method' ) { // Order processing would happen here! // $context->order contains the order object if needed // ... // If the logic above was successful, we can set the status to success. $result->set_status( 'success' ); $result->set_payment_details( array_merge( $result->payment_details, [ 'custom-data' => '12345', ] ) ); $result->set_redirect_url( 'some/url/to/redirect/to' ); } }, 10, 2 ); ``` ## Passing values from the client to the server side payment processing In this example, lets pass some data from the BACS payment method to the server. Registration of BACS looks something like this: ```js // Get our settings that were provided when the payment method was registered const settings = window.wc.wcSettings.getSetting( 'bacs_data' ); // This is a component that would be rendered in the checkout block when the BACS payment method is selected const Content = () => { return decodeEntities( settings?.description || '' ); }; // This is the label for the payment method const Label = ( props ) => { const { PaymentMethodLabel } = props.components; return ; }; // Register the payment method const bankTransferPaymentMethod = { name: 'BACS', label: