Lesson 1.1. Architecture and Tables

Monday, 10:05 AM

A client writes: "The price filter shows products that are out of stock." You open the product: stock 0, status "Out of stock". Everything is correct. But the filter doesn't read the product, it reads wc_product_meta_lookup. Nobody updated it, because the nightly import wrote stock straight into wp_postmeta.

As long as WooCommerce is "posts with meta fields" to you, a bug like this takes hours to find.

Goal

After the lesson you know where WooCommerce stores products, orders, the cart and background jobs, and from a symptom you immediately know which table to check.

Key concepts

  • WC() — the plugin's main object: WC()->cart, WC()->session, WC()->customer, WC()->mailer()
  • Products — posts of type product and product_variation + the wc_product_meta_lookup table for fast filters
  • Orders — HPOS tables wc_orders, wc_order_addresses, wc_order_operational_data, wc_orders_meta
  • A guest's cart — in woocommerce_sessions, not in a cookie
  • Background jobs — Action Scheduler tables (actionscheduler_actions, actionscheduler_logs)
  • Attributes — pa_* taxonomies, categories — product_cat, visibility — the product_visibility taxonomy

Diagram

erDiagram
  wp_posts ||--o{ wp_postmeta : "product / product_variation"
  wp_posts ||--|| wc_product_meta_lookup : "price, stock, SKU"
  wc_orders ||--o{ wc_order_addresses : "billing / shipping"
  wc_orders ||--|| wc_order_operational_data : "internal data"
  wc_orders ||--o{ wc_orders_meta : "order meta"
  wc_orders ||--o{ woocommerce_order_items : "line items"
  woocommerce_order_items ||--o{ woocommerce_order_itemmeta : "qty, total, product_id"
  woocommerce_sessions }o--|| wc_orders : "cart → checkout"

Code

List the WooCommerce tables in your database:

SQL
SHOW TABLES LIKE '%wc\_%';
SHOW TABLES LIKE '%woocommerce\_%';
SHOW TABLES LIKE '%actionscheduler\_%';

Common mistakes

SymptomCauseFix
The price filter is very slowmeta_query on _price in wp_postmetaFilter via wc_get_products() / the lookup table
Order "not found" via get_post()HPOS is on: orders are not in wp_postswc_get_order( $id )
The database grows for no reasonOld sessions and Action Scheduler logsCheck session cleanup and log retention

Weak and strong answer

Question: Where does WooCommerce store orders?

Weak answer. In wp_posts with type shop_order, and the data in wp_postmeta.

Strong answer. It depends on the setting. New sites since 8.2 use the HPOS tables (wc_orders and related). Older ones may use wp_posts or sync mode. That's why my code never touches the tables directly, only wc_get_order() and CRUD.

Why the second is stronger: The candidate knows the current state, remembers both storages and draws a conclusion for the code.

Practice

Open the database of a test store. Find one order in wc_orders, its addresses in wc_order_addresses and its line items in woocommerce_order_items. Draw these relations by hand or in Mermaid. In the terminal below, try the wp wc commands to view the data.

wp — Module 1. WooCommerce as a System

Interview Questions

A denormalized table with a product's price, stock, SKU and rating. WooCommerce uses it for sorting and filters to avoid slow JOINs on wp_postmeta.

In the woocommerce_sessions table. The cookie holds only the session key. For a logged-in user the cart is also saved in user meta so it can be restored on another device.

WP-Cron depends on site visits and has no statuses or retries. Action Scheduler stores jobs in the database, runs them in batches and logs errors. Webhooks, analytics, some emails and migrations run on it.

Save your progress

Sign in or create a free account to mark lessons as completed and continue the whole course. You will come back to this lesson.