WooStore class
A client for the WooCommerce Store API — the public one.
This is the API to use for anything a shopper touches: browsing, the cart, and checkout. It needs no API keys at all, which is what makes it the right choice for a shipped app. The admin API's consumer keys can read every customer's address and change every price, and anything you ship to a device can be read off that device.
final store = WooStore(baseUrl: 'https://your-store.com');
final products = await store.products.list(search: 'beanie');
await store.cart.addItem(id: products.first.id, quantity: 1);
final cart = await store.cart.get();
print(cart.totals.totalPrice); // $18.00
Carts are identified by a Cart-Token the store issues on the first
request; this client captures it and sends it back automatically. Give it
a CartTokenStore to keep a shopper's basket across app launches.
Available on WooCommerce 8.0+ (the Store API shipped with WooCommerce Blocks and was merged into core). Requires no plugin on a current store.
Constructors
Properties
- apiPath → String
-
Where the Store API lives under the site root.
final
- cart → StoreCartResource
-
The shopper's cart.
no setter
- checkout → StoreCheckoutResource
-
Turning the cart into a paid order.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- products → StoreProducts
-
Public product browsing — no keys, no admin fields.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- session → CartSession
-
The cart token bookkeeping. Use it to persist, adopt, or clear a cart.
final
Methods
-
batch(
List< StoreBatchRequest> requests) → Future<List< Map< >String, Object?> > - Runs several Store API calls in one round trip.
-
close(
) → void - Releases the underlying HTTP client, if this created it.
-
getList(
String path, {Map< String, Object?> ? query}) → Future<List< Map< >String, Object?> > - Sends a GET and decodes a list.
-
getOne(
String path, {Map< String, Object?> ? query}) → Future<Map< String, Object?> > - Sends a GET and decodes an object.
-
getPage(
String path, {Map< String, Object?> ? query, int page = 1, int perPage = 10}) → Future<WooPage< Map< >String, Object?> > - Sends a GET and decodes a list, with the store's paging headers.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
post(
String path, {Map< String, Object?> ? body, Map<String, Object?> ? query}) → Future<Map< String, Object?> > - Sends a POST and decodes an object.
-
put(
String path, {Map< String, Object?> ? body, Map<String, Object?> ? query}) → Future<Map< String, Object?> > - Sends a PUT and decodes an object.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited