Headless Storefront API
The Storefront API lets an external site show your Core Commerce products and prices. It’s public and read-only, so it needs no API key.
Checkout stays on WordPress, which verifies payments, creates orders, issues licenses and delivers downloads.
Before You Start
- Turn on Licensing and Storefront in Core Forms > Modules.
- Turn on license issuing under Core Commerce > Settings > Store setup.
- Add at least one active product and plan. Products, Licenses and Subscriptions covers the setup.
Endpoints
| Method | Route | Returns |
|---|---|---|
GET |
/wp-json/core-forms/v1/storefront |
API status, checkout URL and links |
GET |
/wp-json/core-forms/v1/storefront/products |
Active products |
GET |
/wp-json/core-forms/v1/storefront/products/{slug} |
One product |
Filters
The product list accepts these query parameters:
| Parameter | Values | Default |
|---|---|---|
page |
1 or more | 1 |
per_page |
1 to 100 | 12 |
type |
plugin, theme, digital, service or event |
All |
currency |
A 3-letter code | All |
search |
Text | None |
orderby |
name, created, updated or version |
name |
order |
ASC or DESC |
ASC |
The single-product route also accepts currency.
Response
The list returns a products array. The single-product route returns one product:
{
"slug": "example-plugin",
"name": "Example Plugin",
"type": "plugin",
"description": "A short product description.",
"plans": [
{
"slug": "lifetime",
"name": "Lifetime",
"price_minor": 10000,
"price": "100.00",
"currency": "USD",
"formatted_price": "USD 100.00",
"is_free": false,
"billing_period": "lifetime",
"billing_interval": 1,
"billing_label": "One-time purchase",
"checkout_url": "https://cms.example.com/core-checkout/?cf_product=example-plugin&cf_plan=lifetime"
}
]
}
Products also carry their icon, gallery, details, update time and links. The API never returns customers, orders, license keys or gateway credentials.
Fetch Every Product
The list is paginated. Save this as src/lib/storefront.js:
const STORE = 'https://cms.example.com/wp-json/core-forms/v1/storefront';
export async function getProducts() {
const products = [];
let page = 1;
let pages = 1;
do {
const response = await fetch(`${STORE}/products?per_page=100&page=${page}`);
if (!response.ok) throw new Error(`Storefront returned ${response.status}.`);
products.push(...(await response.json()).products);
pages = Number(response.headers.get('X-WP-TotalPages') ?? 1);
page += 1;
} while (page <= pages);
return products;
}
Show Products in Astro
Save this as a component in src/components:
---
import { getProducts } from '../lib/storefront.js';
const products = await getProducts();
---
{products.map((product) => (
<article>
<h2>{product.name}</h2>
<p>{product.description}</p>
{product.plans.map((plan) => (
<a href={plan.checkout_url}>
{plan.name}: {plan.formatted_price}, {plan.billing_label}
</a>
))}
</article>
))}
Use checkout_url as it comes from the API. Don’t rebuild it or work out prices in the browser.
Caching
- Responses can be cached for 5 minutes.
- Send the
ETagback inIf-None-Matchto get304 Not Modified. X-WP-TotalandX-WP-TotalPagesreport the list size.- An unknown product returns
404withcf_storefront_product_not_found. - A static build needs a rebuild after a price change.
To change availability, caching or public fields, use these filters:
cf_storefront_enabledcf_storefront_cache_ttlcf_storefront_productcf_storefront_plan