wc-customer-and-sessions

Manage WooCommerce per-visitor data via WC()->session and WC()->customer across contexts.

21|1|Updated Apr 29, 2026
One-click install
npx skills add https://github.com/Lonsdale201/wp-agent-skills --skill wc-customer-and-sessions
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: wc-customer-and-sessions
Source: https://github.com/Lonsdale201/wp-agent-skills/tree/main/woocommerce/wc-customer-and-sessions
Command: npx skills add https://github.com/Lonsdale201/wp-agent-skills --skill wc-customer-and-sessions

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers correctly use WooCommerce's session and customer abstractions, avoiding $_SESSION and direct cookies that break with page caching, REST, AJAX, cron, and WP-CLI, by guiding data storage and retrieval through WC()->session and WC()->customer.

Core Features & Use Cases

  • Correctly read and write per-visitor data with WC()->session, including ephemeral data such as cart state and feature flags.
  • Read the active customer's billing/shipping details via WC()->customer, and update them in a way that works for both guests and logged-in users.
  • Ensure session initialization in non-frontend contexts (REST, cron, CLI) by calling wc_load_cart() or WC()->initialize_session().

Quick Start

Use WC()->session to store per-visitor data and WC()->customer to read billing info in a plugin context, and call wc_load_cart() in REST or cron contexts when needed.

Frequently Asked Questions about wc-customer-and-sessions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why is WooCommerce session data not working in REST API or cron contexts?

WooCommerce session data is unavailable in REST API, cron, and CLI contexts because WC()->session is not auto-initialized; you must call wc_load_cart() or WC()->initialize_session() to enable session reading and writing in these environments. This Skill defines those initialization rules.

How do I get customer billing details for both guest and logged-in users in WooCommerce?

To get customer billing details for both guest and logged-in users, read the active customer's billing and shipping data via WC()->customer. This Skill guides proper data retrieval and update rules that work consistently across frontend and non-frontend contexts.

Should I use PHP native sessions for WooCommerce cart and visitor data?

You should not use PHP native sessions for WooCommerce cart and visitor data because they break with page caching, REST, AJAX, cron, and WP-CLI. This Skill guides data storage through WC()->session and WC()->customer abstractions instead.

What is the best way to store per-visitor cart state and feature flags in WooCommerce?

The best way to store per-visitor cart state and feature flags in WooCommerce is using WC()->session to read and write ephemeral data. This Skill defines usage rules for session storage and auto-initialization to ensure data persistence without breaking page caching.

Does WooCommerce session handling work with admin-ajax and WP-CLI?

WooCommerce session handling does work with admin-ajax and WP-CLI, but WC()->session may be unavailable by default. This Skill ensures correct data flow by applying wc_load_cart() and WC()->initialize_session() to properly initialize sessions in these non-frontend contexts.

When do I need to initialize WooCommerce sessions manually?

You need to initialize WooCommerce sessions manually in non-frontend contexts such as REST API requests, cron jobs, and WP-CLI commands where WC()->session is unavailable. This Skill defines when to call wc_load_cart() or WC()->initialize_session() to ensure proper data retrieval.