Automattic\WooCommerce\Blocks\Domain\Services

Hydration::cache_cart_context │ protected │ WC 11.1.0

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.

Метод класса: Hydration{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->cache_cart_context(): void;

Список изменений

С версии 11.1.0 Введена.

Код Hydration::cache_cart_context() 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;
}