Wc Customer And Sessions

Use WooCommerce's customer and session APIs correctly — WC ships its own session handler (WC_Session_Handler, single wp_woocommerce_sessions table for both guests and logged-in users) and its own customer object (WC_Customer via WC()->customer). Avoid $_SESSION, direct setcookie, and user_meta for guest/session state. Use WC()->session->set/get for ephemeral visitor data, WC()->customer->get_billing_* for active customer context including guests, and new WC_Customer($user_id) for one-off loads. WC()->session auto-inits only on frontend/admin-ajax; REST, cron, and WP-CLI must call wc_load_cart() explicitly, while Store API cart/checkout routes can use Cart-Token sessions. Use when storing per-visitor state, reading billing data, or debugging session loss across cache/REST/cron. Triggers on WC_Session, WC_Session_Handler, WC_Customer, WC()->session, WC()->customer, wp_woocommerce_sessions.

vikingokft 84eeb34 22.5 KB Updated 0 repo stars

File contents

vikingokft/vikingo-studio-skills/tree/main/woocommerce/wc-customer-and-sessions commit 84eeb3405d

Frequently asked questions

npx skillmds add vikingokft/wc-customer-and-sessions