Skip to content

WooCommerce

Andreas Ekström edited this page Jul 20, 2026 · 3 revisions

ViteWP includes frontend-safe WooCommerce helpers backed by the public WooCommerce Store API.

---
import { getProducts, getProductCategories } from 'vite-wp/woocommerce';

const products = await getProducts({ perPage: 12 });
const categories = await getProductCategories();
---

<ul>
  {products.map((product) => (
    <li>
      <a href={product.permalink}>{product.name}</a>
      <span set:html={product.price_html} />
    </li>
  ))}
</ul>

Available helpers include getProduct, getProductBySlug, getProducts, getProductCategories, getProductTags, getProductBrands, getProductAttributes, getProductAttributeTerms, and getProductReviews.

Cart

Cart API is exported from vite-wp/woocommerce. See example usage below:

import { addCartItem, getCart, getProducts, removeCartItem, updateCartItem } from 'vite-wp/woocommerce';

const products = await getProducts({ perPage: 12 });
const cart = await getCart();

await addCartItem({ id: products[0].id, quantity: 1 });
await updateCartItem({ key: cart.items[0].key, quantity: 2 });
await removeCartItem({ key: cart.items[0].key });

In Astro SSR, cart helpers automatically use the current request cookies and WooCommerce Store API nonce.

WooCommerce account data

Authenticated WooCommerce account helpers are exported from vite-wp/woocommerce:

import {
  getCurrentCustomer,
  getCustomerOrders,
  updateCurrentCustomer,
} from 'vite-wp/woocommerce';

const customer = await getCurrentCustomer(Astro);
const orders = await getCustomerOrders({ status: ['processing', 'completed'] }, Astro);

await updateCurrentCustomer({
  firstName: 'Ada',
  billing: { city: 'Stockholm' },
}, Astro);

Clone this wiki locally