Automattic\WooCommerce\Blocks\BlockTypes

ProductButton::initialize_cart_stateprivateWC 1.0

Initialize the cart state.

Method of the class: ProductButton{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->initialize_cart_state();

ProductButton::initialize_cart_state() code WC 9.8.5

private function initialize_cart_state() {
	if ( null === self::$cart ) {
		$cart = isset( WC()->cart )
			? rest_do_request( new \WP_REST_Request( 'GET', '/wc/store/v1/cart' ) )->data
			: array();

		wp_interactivity_state(
			'woocommerce',
			array(
				'cart'     => $cart,
				'nonce'    => wp_create_nonce( 'wc_store_api' ),
				'noticeId' => '',
				'restUrl'  => get_rest_url(),
			)
		);
	}
}