Skip to main content

How Woo Components Work

Woo components have two cooperating layers:

  1. PHP component markup renders the authored Etch block tree, data attributes, slots, preview branches, and server-known dynamic data.
  2. The Woo runtime binds those data attributes, reads Store API state, mutates Woo through Store API endpoints, and updates the same live DOM.

Boot Flow

Woo::maybe_boot() registers the Woo service when WooCommerce is available. The service is triggered by any Woo component key listed in Woo.php, and it localizes:

Localized keyRuntime use
storeApiBaseBase URL for /wc/store/v1 requests.
nonceStore API nonce header.
checkoutUrlFallback redirect target for BuyNowButton.
isAvailable and diagnosticsRuntime availability state.
paymentMethodsSimple enabled payment methods for PaymentMethodSelector.
checkoutFieldsWoo checkout field rules, countries, states, locale overrides, and defaults.

The browser service creates one WooCartStore and one WooCheckoutStore. Cart components subscribe to the cart store. Checkout components subscribe to the checkout store only when checkout UI is present.

SSR and Runtime Updates

The Woo line follows this rule:

SurfaceFirst visible state
Product purchase formsAuthored server markup with product props and optional variation data.
Cart items and totalsServer dynamic sources when the block tree references cart data, then runtime refresh.
Shipping and payment selectorsServer rows when dynamic sources are available, then runtime normalization and selection binding.
Checkout fieldsServer-authored fields, then runtime applies Woo field schema and country/state logic.
NoticesRuntime feedback regions.

Server markup is not thrown away. The runtime updates text, input values, row state, and cloned rows in place. Templates remain inert blueprints for rows that need to be cloned after a Store API response.

Store API Requests

The cart store serializes cart mutations through RequestQueue, then refreshes subscribers:

ActionStore API endpoint
Add itemPOST /cart/add-item
Update quantityPOST /cart/update-item
Remove itemPOST /cart/remove-item
Apply couponPOST /cart/apply-coupon
Remove couponDELETE /cart/coupons?code=...
Select shippingPOST /cart/select-shipping-rate

The checkout store also serializes requests:

ActionStore API endpoint
Load checkoutGET /checkout
Persist fieldsPUT /checkout?__experimental_calc_totals=true
Place orderPOST /checkout

Component Binding Order

WooRuntime.boot() binds display components, action components, product purchase controls, checkout components, and selectors. This order matters because some render callbacks re-bind child actions:

Parent renderFollow-up binding
CartItems row renderBinds item quantity inputs and remove buttons in the rendered rows.
CouponAppliedList row renderBinds coupon remove buttons in the rendered rows.
OrderSummary renderBinds read-only summary rows and any row-level actions that are present.

Composition Rules

ComponentNeeds
AddToCartButton with trigger: standaloneA direct product_id prop or a scoped product quantity input. It is ignored when placed inside AddToCartForm; the form owns submission there.
AddToCartButton with trigger: form_submitA parent AddToCartForm; it renders as the form submit control.
BuyNowButtonA parent AddToCartForm; it serializes the form then redirects.
AttributeSelectorA parent purchase form and a bound props.target.attribute object.
Cart item atomsA CartItems row or OrderSummary product row.
CouponRemoveButtonA CouponAppliedList row with a coupon code.
PlaceOrderButtonA parent checkout form scope.

Events

The runtime dispatches:

EventFired from
ome-woo:cart-loadedCart count, totals, cart items, cart notices, or body after cart boot.
ome-woo:checkout-loadedCheckout provider, checkout form, checkout notices, or body after checkout boot.
ome-woo:checkout-startedCheckout form before submit.
ome-woo:checkout-completeCheckout form after Store API checkout success.
ome-woo:checkout-errorCheckout form after local validation or Store API failure.

Product add events are dispatched by the add-item helpers after successful or failed add-to-cart actions.