A headless WooCommerce storefront built with Next.js 16, React 19, and TypeScript.
- Full WooCommerce Integration - Products, categories, variations, cart, and checkout
- Type-safe API Layer - Comprehensive TypeScript definitions for WooCommerce
- Client-side Cart - Persistent shopping cart with localStorage
- WooCommerce Checkout - Redirects to WooCommerce for secure payment processing
- Server-side Pagination - Efficient product browsing with filters
- Blog Support - WordPress posts, categories, tags, and authors
- Cache Revalidation - Automatic updates when content changes
- Dark Mode - Built-in theme switching
- Responsive Design - Mobile-first with Tailwind CSS v4
| Feature | Implementation |
|---|---|
| Product browsing | Next.js pages with WooCommerce API |
| Product search & filters | Server-side with URL params |
| Shopping cart | Client-side with localStorage |
| Checkout form | Next.js form, order created via API |
| Payment processing | Redirects to WooCommerce (Stripe, PayPal, etc.) |
| Account management | Redirects to WooCommerce My Account |
| Order confirmation | Next.js success page |
| Blog | WordPress posts via REST API |
Instead of building custom Stripe integration and authentication:
- Security - WooCommerce handles PCI compliance
- Flexibility - Store owner can change payment gateways without code changes
- Simplicity - No auth infrastructure to maintain
- Battle-tested - WooCommerce's checkout is proven at scale
- WordPress 6.0+ with HTTPS enabled
- WooCommerce 8.0+ installed and activated
- Node.js 18+ and pnpm
If you don't have a WordPress site yet:
- Hosting: Use any WordPress host (WP Engine, Bluehost, Cloudways, etc.) or local development (Local by Flywheel, MAMP, Docker)
- Install WordPress: Follow your host's WordPress installation process
- Enable HTTPS: Required for WooCommerce API authentication
Important: The REST API requires pretty permalinks.
- Go to Settings → Permalinks
- Select Post name (or any option except "Plain")
- Click Save Changes
- Install WooCommerce: Plugins → Add New → Search "WooCommerce"
- Activate and run the setup wizard
- Configure your store basics (currency, location, etc.)
WooCommerce creates these automatically, but verify they exist:
- Shop (
/shop) - Product listing - Cart (
/cart) - Shopping cart - Checkout (
/checkout) - Payment page - My Account (
/my-account) - Customer login/dashboard
Check in WooCommerce → Settings → Advanced → Page Setup.
- Go to Products → Add New
- Add product title, description, price, and images
- Set stock status and publish
- Repeat or import products via Products → Import
- Go to WooCommerce → Settings → Advanced → REST API
- Click Add Key
- Set Description to "Next.js" (or any label)
- Set User to an admin account
- Set Permissions to Read/Write
- Click Generate API Key
- Copy both keys immediately - the secret is only shown once
git clone https://github.com/9d8dev/next-woo.git
cd next-woo
pnpm install
cp .env.example .env.localEdit .env.local with your credentials:
# WordPress/WooCommerce Site
WORDPRESS_URL="https://your-wordpress-site.com"
WORDPRESS_HOSTNAME="your-wordpress-site.com"
NEXT_PUBLIC_WORDPRESS_URL="https://your-wordpress-site.com"
# Webhook secret (generate with: openssl rand -base64 32)
WORDPRESS_WEBHOOK_SECRET="your-secret-key-here"
# WooCommerce API credentials from Step 3
WC_CONSUMER_KEY="ck_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
WC_CONSUMER_SECRET="cs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"Configure your payment gateway in WooCommerce → Settings → Payments.
Popular options:
- Stripe - Credit cards (install Stripe plugin)
- PayPal - PayPal checkout
- Cash on Delivery - For testing
After payment, customers should return to your Next.js site:
- Most payment gateways handle this automatically using the order's redirect URL
- If needed, configure the thank you page URL in your gateway settings:
https://your-nextjs-site.com/checkout/success
For automatic cache updates when products/posts change:
- Download next-revalidate.zip
- Go to Plugins → Add New → Upload Plugin
- Upload and activate the plugin
- Go to Settings → Next.js Revalidation
- Enter your Next.js site URL and webhook secret
pnpm devYour site is now running at http://localhost:3000.
- Visit
http://localhost:3000/shop- Should display your products - Visit
http://localhost:3000/posts- Should display your blog posts - Test the cart and checkout flow
┌─────────────────┐ ┌─────────────────┐
│ │ │ │
│ Next.js │ ◄─────► │ WooCommerce │
│ (Frontend) │ API │ (Backend) │
│ │ │ │
└────────┬────────┘ └────────┬────────┘
│ │
│ ┌───────────────────────┐ │
│ │ User Flow │ │
│ └───────────────────────┘ │
│ │
▼ ▼
┌──────────┐ ┌──────────┐
│ Browse │ │ Payment │
│ Cart │ ──redirect──► │ Account │
│ Checkout │ │ Orders │
└──────────┘ └──────────┘
(Next.js) (WooCommerce)
- Customer adds items to cart (client-side, localStorage)
- Customer fills billing form on
/checkout - Order created in WooCommerce via API (unpaid)
- Customer redirected to
order.payment_url(WooCommerce checkout) - Customer pays via configured gateway (Stripe, PayPal, etc.)
- WooCommerce redirects to
/checkout/success - Cart cleared automatically
next-woo/
├── app/
│ ├── api/
│ │ ├── checkout/ # Order creation endpoint
│ │ ├── og/ # OG image generation
│ │ └── revalidate/ # Cache revalidation webhook
│ ├── shop/
│ │ ├── [slug]/ # Product detail pages
│ │ └── category/[slug]/ # Category pages
│ ├── cart/ # Shopping cart page
│ ├── checkout/
│ │ └── success/ # Order confirmation
│ ├── posts/ # Blog posts
│ └── pages/ # WordPress pages
├── components/
│ ├── shop/ # Shop components
│ ├── posts/ # Blog components
│ ├── ui/ # shadcn/ui components
│ └── theme/ # Theme toggle
├── lib/
│ ├── woocommerce.ts # WooCommerce API functions
│ ├── woocommerce.d.ts # WooCommerce type definitions
│ ├── wordpress.ts # WordPress API functions
│ └── wordpress.d.ts # WordPress type definitions
├── site.config.ts # Site metadata
└── menu.config.ts # Navigation configuration
import { getProducts, getProductBySlug } from "@/lib/woocommerce";
// Get paginated products
const { data: products, headers } = await getProducts(1, 12, {
category: 5,
on_sale: true,
orderby: "price",
});
// Get single product
const product = await getProductBySlug("product-name");import { getAllProductCategories, getProductCategoryBySlug } from "@/lib/woocommerce";
const categories = await getAllProductCategories();
const category = await getProductCategoryBySlug("clothing");import { createOrder } from "@/lib/woocommerce";
const order = await createOrder({
billing: { email: "customer@example.com", ... },
line_items: [{ product_id: 123, quantity: 2 }],
});
// Redirect to payment
window.location.href = order.payment_url;import { useCart } from "@/components/shop";
function MyComponent() {
const { cart, addItem, removeItem, updateQuantity, clearCart } = useCart();
await addItem({
productId: 123,
quantity: 1,
name: "Product Name",
price: "29.99",
});
}Edit site.config.ts:
export const siteConfig = {
site_name: "Your Store",
site_domain: "https://yourstore.com",
site_description: "Your store description",
};Edit menu.config.ts:
export const mainMenu = {
home: "/",
shop: "/shop",
blog: "/posts",
};pnpm dev # Start development server
pnpm build # Build for production
pnpm start # Start production server
pnpm lint # Run ESLint- Verify WooCommerce REST API credentials are correct
- Check API at
your-site.com/wp-json/wc/v3/products - Ensure products are published and visible
- Add WordPress domain to
WORDPRESS_HOSTNAME - Check
next.config.tshas correctremotePatterns
- Verify WooCommerce checkout page is configured
- Check payment gateway return URL points to your Next.js domain
- Ensure
NEXT_PUBLIC_WORDPRESS_URLis set correctly - Verify WooCommerce My Account page exists at
/my-account
- Next.js 16 - React framework
- React 19 - UI library
- Tailwind CSS v4 - Styling
- shadcn/ui - UI components
- WooCommerce - E-commerce backend
MIT License