Automattic\WooCommerce\Blocks\Domain\Services
Hydration::cache_cart_context
Cache the cart context before hydrating the API.
Dispatching a Store API cart route runs CartController::load_cart(), which sets cart_context to store-api on the shared cart and never puts it back. That is correct for a real Store API request, where the whole request is Store API — but hydration runs inside a front-end render, so without a snapshot the rest of that render inherits the flag. Shipping code branches on it, so the page would silently take the block path.
Method of the class: Hydration{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->cache_cart_context(): void;
Changelog
| Since 11.1.0 | Introduced. |
Hydration::cache_cart_context() Hydration::cache cart context code WC 11.2.2
protected function cache_cart_context(): void {
$this->cached_cart_context = null;
if ( ! did_action( 'woocommerce_init' ) || ! WC()->cart instanceof \WC_Cart ) {
return;
}
$this->cached_cart_context = WC()->cart->cart_context;
}