From cocart
CoCart TypeScript/JavaScript SDK patterns for headless WooCommerce. Use when setting up CoCart in JS/TS projects including Astro, Next.js, Nuxt, SvelteKit, Remix, Hono, Elysia.js, Fastify, Deno, Framer, or Webflow.
How this skill is triggered — by the user, by Claude, or both
Slash command
/cocart:jsThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
You are an expert in CoCart — the headless WooCommerce REST API — and its official TypeScript/JavaScript SDK (`@cocartheadless/sdk`).
You are an expert in CoCart — the headless WooCommerce REST API — and its official TypeScript/JavaScript SDK (@cocartheadless/sdk).
Detect the user's language or runtime from their project context and apply the correct skill:
js)phppythongoflutterswiftIf the language is ambiguous, default to this skill (JS/TS) and mention the other SDKs are available.
# npm
npm install @cocartheadless/sdk
# yarn
yarn add @cocartheadless/sdk
# pnpm
pnpm add @cocartheadless/sdk
# bun
bun add @cocartheadless/sdk
# CDN (Framer, Webflow, plain HTML — no npm required)
# <script src="https://cdn.jsdelivr.net/npm/@cocartheadless/sdk/dist/index.global.js"></script>
Requirements: Node.js 20+, CoCart plugin installed on WooCommerce store. TypeScript 5.0+ recommended.
import { CoCart } from '@cocartheadless/sdk';
const client = new CoCart('https://your-store.com');
// Browse products (no auth required)
const products = await client.products().all({ per_page: '12' });
// Add to cart (guest session created automatically)
await client.cart().addItem(123, 2);
// Get cart with dot-notation access
const cart = await client.cart().get();
console.log(cart.get('totals.total'));
console.log(cart.getItems());
// Fluent configuration
const client = new CoCart('https://your-store.com')
.setTimeout(15000)
.setMaxRetries(2)
.addHeader('X-Custom', 'value');
Always keep store credentials server-side. Suggested .env pattern:
# Public (safe to expose to browser)
NEXT_PUBLIC_STORE_URL=https://your-store.com # Next.js
PUBLIC_STORE_URL=https://your-store.com # Astro / SvelteKit / Vite
# Private (server-side only)
STORE_URL=https://your-store.com
COCART_CONSUMER_KEY=ck_xxx
COCART_CONSUMER_SECRET=cs_xxx
COCART_ENCRYPTION_KEY=your-32-char-secret-key
document.cookie for cart keys.restoreSession() in browser adapters — Always call await client.restoreSession() before making cart calls in browser/client components, or the guest session will be lost on page reload.ck_xxx, cs_xxx) are server-side only. Use NEXT_PUBLIC_ or PUBLIC_ prefixed env vars only for the store URL.client.jwt().withAutoRefresh() instead of manually managing tokens. The SDK handles refresh transparently.per_page and page are strings: { per_page: '12' }, not { per_page: 12 }.npx claudepluginhub cocart-headless/cocart-skills --plugin cocartBuilds and consumes WooCommerce REST API v3 endpoints: authentication, custom routes, resource extensions, webhooks, batch operations. For WooCommerce API development and integrations.
Guides WooCommerce store development: setup, payment/shipping integration, custom products, optimization, and WordPress 7.0 features like AI product descriptions, DataViews, collaboration.
Provides best practices, UI/UX patterns, and guidance for ecommerce storefronts: checkout, cart, products, navigation, homepage. Integrates Medusa backend; framework-agnostic (Next.js, React, Vue).