Skip to main content

Store API and Native Hooks

Woo components send cart and checkout mutations through WooCommerce Store API. That is important because Store API still runs Woo's native cart, pricing, checkout, payment, order, and status hooks.

The lifecycle E2E suite proves this with a test-only Woo hook probe.

Cart Requests

WooStoreApiClient sends cart requests with a nonce and cart token. The cart store queues mutations so the UI is not racing multiple responses.

UI actionStore API requestNative behavior tested
Product addPOST /cart/add-itemAdd-to-cart validation can block, add item data can be injected, and add actions fire.
Quantity changePOST /cart/update-itemCart totals refresh after Woo recalculates cart state.
Remove itemPOST /cart/remove-itemCart item rows and totals refresh before empty state appears.
Apply couponPOST /cart/apply-couponDiscount totals and coupon rows update.
Remove couponDELETE /cart/coupons?code=...Coupon rows and totals update.
Shipping selectionPOST /cart/select-shipping-rateSelected package rate and totals update.

Checkout Requests

WooCheckoutStore also queues requests:

UI actionStore API requestState
Boot checkoutGET /checkoutloading then idle.
Persist field changesPUT /checkout?__experimental_calc_totals=trueupdating then idle.
Place orderPOST /checkoutprocessing then success or error.

If a payment result has a redirect URL, the checkout form redirects after the successful response.

Native Hook Coverage

WooLifecycleProbe records deterministic hook events. E2E then checks the order and visible UI effects.

E2E scenarioWhat it proves
lifecycle_add_to_cart with block modewoocommerce_add_to_cart_validation can block cart mutation and the Woo notice renders as text.
lifecycle_add_to_cart with allow modewoocommerce_add_cart_item_data, woocommerce_add_to_cart_validation, woocommerce_add_cart_item, and woocommerce_add_to_cart fire for Etch form submissions.
shipping_selector with pricing modewoocommerce_before_calculate_totals changes item price and woocommerce_cart_calculate_fees changes totals rendered by cart and order summary components.
lifecycle_checkoutStore API checkout creates an order through native hooks, writes order meta, records payment context, and reaches an order-received flow.

Error Handling

Store API errors are converted into safe notices:

  • Cart errors become cart notices with a source such as add-to-cart, quantity, remove, coupon, shipping, stock, or variation.
  • Checkout errors become checkout notices and field error markers when Woo exposes field keys.
  • Known Woo checkout error codes are mapped to field keys when Store API does not include data.params.
  • Notice message text is normalized and rendered with text content, not injected as HTML.

Store API Extension Data

StoreApiExtension registers an ohmyetch namespace on the Store API cart endpoint when Woo Blocks APIs are available. It exposes capability metadata:

CapabilityMeaning
cart_countOME cart count components are supported for the response.
add_to_cartOME add-to-cart components are supported for the response.

This metadata is read-only and does not replace Woo's native cart schema.