Install and Prepare Product Data
Install the commerce package and create typed fixtures without confusing local data with WordPress products.
Install and prepare product data
Start from a working ForgeWP React theme. Its commerce peers include React, @forgewp/react and lucide-react. Inspect package.json first: some scaffolds already include the package.
pnpm add @forgewp/woocommerceActivate WooCommerce on the installed WordPress site and configure real products, currency, taxes, shipping and the selected payment plugins. Importing the package does not configure or verify a store.
Typed local products
1import { defineProducts } from "@forgewp/woocommerce"
2
3export default defineProducts([
4 { id: 101, name: "Canvas bag", slug: "canvas-bag", type: "simple",
5 price: "24.00", stock_status: "instock", sku: "BAG-101" },
6])defineProducts and defineProduct are identity helpers for type checking. They do not save products to WordPress. The runtime supplies preview products through window._forgeWpMockPosts.product; use the CMS-loading workflow rather than assigning that global in production.
Fixture seeding is separate and opt-in. seed.products defaults to false. Review seeding configuration before enabling a strategy on a test site.
Origins and credentials
The commerce API-base resolver checks browser FORGEWP_API_URL, Vite VITE_WP_API_URL, process NEXT_PUBLIC_WP_API_URL/WP_API_URL, the pathname of hydrated WordPress home, then the current origin root. It is separate from the newer Auth resolver. The base precedes /wp-json; do not duplicate that suffix.
Requests generally include credentials. Verify subdirectory paths, REST nonce hydration, cookies and CORS on the deployment. Setting a URL does not itself establish a cross-origin session. Never embed WooCommerce admin consumer secrets in frontend code.