Setup & Installation

Updated 8 July 2026

Follow this comprehensive guide to set up your Next.js WooCommerce development environment.

Prerequisites

Before you begin, ensure you have the following installed and configured:

Required Software

You should see output similar to:

Important: Make sure your WooCommerce store is accessible and the REST API is enabled before proceeding.

Step 1: Clone and Install

Start by navigating to your project directory and installing dependencies:

# Navigate to project directory
cd Your-Project-Directory

# Install all dependencies
npm install

What Gets Installed?

The installation process will install all required packages including:

Step 2: Configure Environment Variables

Create a .env.local file in the root directory of your project:

# WooCommerce REST API Credentials
WOO_BASE_URL=https://your-store.com
WOO_CONSUMER_KEY=ck_your_consumer_key
WOO_CONSUMER_SECRET=cs_your_consumer_secret
WOO_VERSION=wc/v3

# Optional: Stripe (for payments)
STRIPE_SECRET_KEY=sk_test_...
STRIPE_PUBLISHABLE_KEY=pk_test_...

Security Note: Never commit .env.local to version control. It’s already included in .gitignore.

Environment Variable Details

Step 3: Get WooCommerce API Credentials

You need to generate API keys from your WooCommerce store:

Step 4: Update WooCommerce Client

Edit src/lib/woocommerce.js to use environment variables:

import WooCommerceRestApi from "@woocommerce/woocommerce-rest-api"; // Import WooCommerce REST API client

let wooClient = null; // Initialize WooCommerce client as null

export function getWooClient() { // Function to get WooCommerce client
  if (!wooClient) { 
    const url = process.env.WOO_BASE_URL; // Get WooCommerce base URL from environment variables
    const consumerKey = process.env.WOO_CONSUMER_KEY; // Get WooCommerce consumer key from environment variables
    const consumerSecret = process.env.WOO_CONSUMER_SECRET; // Get WooCommerce consumer secret from environment variables
    const version = process.env.WOO_VERSION || "wc/v3"; // Get WooCommerce version from environment variables

    if (!url || !consumerKey || !consumerSecret) {
      throw new Error("Missing WooCommerce environment variables");
    }

    wooClient = new WooCommerceRestApi({
      url, // Set WooCommerce base URL
      consumerKey,
      consumerSecret, // Set WooCommerce consumer secret
      version, // Set WooCommerce version
    });
  }
  return wooClient; // Return WooCommerce client
}

Note: The client uses a singleton pattern to ensure only one instance is created.

Step 5: Run Development Server

Start the Next.js development server:

npm run dev // Run development server

You should see output similar to:

▲ Next.js 15.5.4
    - Local:        http://localhost:3000
    - Ready in 2.3s

Development Server Features

Step 6: Build for Production

When ready to deploy, build the production version:

# Create optimized production build
npm run build

# Start production server
npm start

Production Build Process

Verification

To verify your setup is working correctly:

Next Steps: Once setup is complete, check out the WooCommerce Integration guide to understand how the APIs work.

Common Setup Issues

Issue: Environment variables not loading

Solution: Restart the development server after creating/updating .env.local

Issue: API authentication errors

Solution: Verify your API credentials are correct and the API key has Read/Write permissions

Issue: CORS errors

Solution: Ensure your WooCommerce store allows requests from your development domain. Use API routes as a proxy (already configured).