npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@agentojs/woocommerce

v0.1.0

Published

Connect WooCommerce to AI agents (Claude, ChatGPT, Gemini) — MCP, UCP, ACP protocols

Readme

@agentojs/woocommerce

npm version License: MIT

WooCommerce adapter for AI commerce agents. Implements the CommerceBackend interface from @agentojs/core using WooCommerce's dual API surface.

Part of the AgentOJS monorepo.

Features

  • Dual API architecture (Store API + REST API) -- handled transparently
  • Cart-Token JWT management with in-memory state
  • Automatic price conversion from minor units to decimals
  • Variable product support (fetches variations)
  • Native fetch() -- zero runtime dependencies

Installation

npm install @agentojs/woocommerce @agentojs/core

Quick Start

import { WooCommerceBackend } from '@agentojs/woocommerce';

const backend = new WooCommerceBackend({
  baseUrl: 'https://your-store.com',
  consumerKey: 'ck_your_consumer_key',
  consumerSecret: 'cs_your_consumer_secret',
});

const { data: products } = await backend.searchProducts({ q: 'hoodie' });
console.log(products[0].title);

Generate API keys in WooCommerce: Settings > Advanced > REST API > Add Key (Read/Write permissions).

Configuration

interface WooCommerceBackendConfig {
  /** WooCommerce site URL (e.g., "https://store.example.com") */
  baseUrl: string;
  /** WooCommerce REST API consumer key (starts with ck_) */
  consumerKey: string;
  /** WooCommerce REST API consumer secret (starts with cs_) */
  consumerSecret: string;
}

Dual API Architecture

WooCommerce exposes two APIs with different capabilities. This adapter transparently routes calls to the correct one:

| Feature | Store API (wc/store/v1) | REST API (wc/v3) | |---------|--------------------------|---------------------| | Auth | None / Cart-Token JWT | Basic Auth (key + secret) | | Products | Read (public) | Read + Write | | Cart | Full CRUD | Not available | | Checkout | Full flow | Not available | | Orders | Not available | Full CRUD | | Categories | Not available | Full CRUD | | Shipping Zones | Not available | Read |

Cart-Token Flow

WooCommerce carts are identified by a JWT token returned in the Cart-Token response header. This adapter:

  1. Creates a UUID as the public cartId
  2. Maps it internally to the real Cart-Token JWT
  3. Stores cart state (email, addresses, payment method) in memory

Cart state is in-memory and lost on process restart. This is acceptable for stateless AI agent interactions.

Full Example

import { WooCommerceBackend } from '@agentojs/woocommerce';

const backend = new WooCommerceBackend({
  baseUrl: 'https://your-store.com',
  consumerKey: 'ck_key',
  consumerSecret: 'cs_secret',
});

// Browse products
const { data: products } = await backend.searchProducts({ q: 'hoodie' });
console.log(`Found ${products.length} products`);

// Create a cart
const cart = await backend.createCart('default', [
  { variant_id: '42', quantity: 2 },
]);
console.log(`Cart total: ${cart.total} ${cart.currency_code}`);

// Update shipping address
await backend.updateCart(cart.id, {
  email: '[email protected]',
  shipping_address: {
    first_name: 'John',
    last_name: 'Doe',
    address_1: '123 Main St',
    city: 'New York',
    province: 'NY',
    postal_code: '10001',
    country_code: 'US',
  },
});

// Shipping and checkout
const shippingOptions = await backend.getShippingOptions(cart.id);
await backend.addShippingMethod(cart.id, shippingOptions[0].id);
const order = await backend.completeCart(cart.id);
console.log(`Order #${order.display_id} placed!`);

API Reference

Products

| Method | Description | |--------|-------------| | searchProducts(filters) | Search products via Store API with pagination | | getProduct(id) | Get single product with variations (if variable) | | getCollections() | List product categories with products | | getCollection(id) | Get single category with its products |

Cart

| Method | Description | |--------|-------------| | createCart(regionId, items) | Create cart and add initial items | | getCart(cartId) | Retrieve cart by ID | | updateCart(cartId, updates) | Update email, shipping/billing address | | addLineItem(cartId, variantId, quantity) | Add item to cart | | removeLineItem(cartId, lineItemId) | Remove item by key |

Shipping

| Method | Description | |--------|-------------| | getShippingOptions(cartId) | Get available shipping rates | | addShippingMethod(cartId, optionId) | Select a shipping rate |

Checkout

| Method | Description | |--------|-------------| | createPaymentSessions(cartId) | Get available payment methods | | selectPaymentSession(cartId, providerId) | Select payment method | | completeCart(cartId) | Complete checkout, returns Order |

initializePayment() is not supported for WooCommerce and throws an error.

Orders

| Method | Description | |--------|-------------| | getOrder(orderId) | Fetch order by ID (REST API) | | listOrders(filters) | List orders with filters (email, status) |

Regions & Health

| Method | Description | |--------|-------------| | getRegions() | Get shipping zones as regions | | healthCheck() | Check if WP REST API is accessible |

Price Handling

WooCommerce Store API returns prices in minor units (e.g., "2999" for $29.99). This adapter automatically converts them to decimal format using the currency_minor_unit field from the API response.

Error Handling

import { WooCommerceApiError } from '@agentojs/woocommerce';

try {
  await backend.getProduct('999');
} catch (err) {
  if (err instanceof WooCommerceApiError) {
    console.error(`HTTP ${err.status}: ${err.body}`);
    console.error(`URL: ${err.url}`);
  }
}

Exported Types

The package exports all internal WooCommerce API types for advanced use:

import type {
  WcStoreProduct,
  WcVariation,
  WcCart,
  WcCartItem,
  WcOrder,
  WcAddress,
  WcShippingRate,
  WcPaymentMethod,
  WcCategory,
  WcShippingZone,
} from '@agentojs/woocommerce';

License

MIT