← Back to Home

WordPress WooCommerce Headless Architecture Complete Guide

WordPressWooCommerceHeadlessDecoupledNext.jsAstro

---

When Does Headless Architecture Actually Make Sense?

Most small-to-medium WooCommerce stores don't need headless. Standard WordPress + WooCommerce with PHP rendering is fast enough and costs less to maintain.

But headless starts making sense when:

I migrated a WooCommerce site with 2000+ products to Next.js frontend in early 2026. LCP dropped from 3.2s to 0.8s. But I hit every major pitfall along the way.

---

Architecture Overview: Data Flow in Headless WooCommerce

[WordPress Admin] → [WooCommerce REST API] → [Next.js/Astro Frontend] → [User Browser]
   (WP + Woo)         (wp-json/wc/v3/)       (SSG/SSR)               (Edge CDN)

WordPress still handles: product management, order processing, payment gateways, user accounts

Frontend handles: page rendering, SEO metadata, global CDN acceleration, app-like experience

---

Step 1: WordPress Admin Configuration (Ensuring API Access)

1.1 Enable WooCommerce REST API

WooCommerce ships with REST API built-in — no extra plugin needed.

Go to WooCommerce > Settings > Advanced > REST API, click "Add key":

> ⚠️ Pitfall 1: WooCommerce REST API requires HTTPS. If your WordPress is still on HTTP, the API will return woocommerce_rest_cannot_view errors. Free solution: Let's Encrypt + Certbot (see my SSL configuration article for the full setup).

1.2 Permalinks Configuration (Required)

REST API routes depend on permalink structure. Go to Settings > Permalinks, select "Post name" or "Custom structure" — avoid "Plain" default.

Verify API is accessible:

curl -s "https://yourdomain.com/wp-json/wc/v3/products?consumer_key=CK&consumer_secret=CS" | head -c 200

Returns a JSON array instead of an error → API is working.

---

Step 2: Frontend Project Setup (Next.js 14 App Router)

2.1 Create the Project

npx create-next-app@latest woocommerce-headless --typescript --app --src-dir --import-alias "@/*" --no-tailwind --use-npm
cd woocommerce-headless
npm install @woocommerce/woocommerce-rest-api

Key choices:

2.2 WooCommerce API Client Configuration

Create src/lib/woocommerce.ts:

import WooCommerceRestApi from "@woocommerce/woocommerce-rest-api";

const api = new WooCommerceRestApi({
  url: process.env.NEXT_PUBLIC_WOOCOMMERCE_URL!,
  consumerKey: process.env.WOOCOMMERCE_CONSUMER_KEY!,
  consumerSecret: process.env.WOOCOMMERCE_CONSUMER_SECRET!,
  version: "wc/v3",
  queryStringAuth: true, // Critical: Vercel/edge environments need this
});

export default api;

> ⚠️ Pitfall 2: queryStringAuth: true is critical for Vercel/Netlify deployments. These platforms don't support custom request headers (Authorization: Basic) — they filter them out entirely. Without this flag, every API request returns 401.

2.3 Fetch Products (SSR Page)

Create src/app/page.tsx:

import api from "@/lib/woocommerce";

async function getProducts() {
  const response = await api.get("products", {
    per_page: 12,
    status: "publish",
  });
  return response.data;
}

export default async function HomePage() {
  const products = await getProducts();

  return (
    

Store

{products.map((product: any) => (
{product.name}

{product.name}

{product.price} USD

View Details
))}
); }

---

Step 3: SSR vs SSG Strategy (Performance Critical)

When to Use SSR (Server-Side Rendering)

When to Use SSG (Static Site Generation)

Recommended: Start with SSG + ISR (Incremental Static Regeneration), works for most e-commerce scenarios:

// Enable ISR, regenerate every hour
export const revalidate = 3600;

async function getProducts() {
  const response = await api.get("products", { per_page: 100 });
  return response.data;
}

> ⚠️ Pitfall 3: WooCommerce API has rate limits. Free WooCommerce accounts are limited to **1 request/second and 3600 requests/day**. If your SSG build script pulls all products at once (2000+ SKUs), you may hit 429 Too Many Requests. Solution: use per_page=100 with pagination loop, add await new Promise(r => setTimeout(r, 1100)) between requests.

---

Step 4: SEO and Meta Tags

The biggest SEO risk with headless architecture: frontend pages lack proper meta tags and schema markup.

4.1 Dynamic SEO Metadata (Next.js Metadata API)

import api from "@/lib/woocommerce";

type Props = { params: { slug: string } };

export async function generateMetadata({ params }: Props) {
  const response = await api.get(`products?slug=${params.slug}`);
  const product = response.data[0];

  return {
    title: product.name,
    description: product.short_description.replace(/<[^>]+>/g, "").slice(0, 160),
    openGraph: {
      images: [{ url: product.images[0]?.src }],
    },
  };
}

4.2 WooCommerce Product Schema (Structured Data)

Google's Product rich results depend on schema markup. Install Schema & Structured Data for WordPress plugin or inject manually:

function ProductSchema({ product }: { product: any }) {
  const schema = {
    "@context": "https://schema.org",
    "@type": "Product",
    name: product.name,
    image: product.images.map((img: any) => img.src),
    description: product.description,
    offers: {
      "@type": "Offer",
      price: product.price,
      priceCurrency: "USD",
      availability: product.stock_status === "instock"
        ? "https://schema.org/InStock"
        : "https://schema.org/OutOfStock",
    },
  };

  return (