Automattic\WooCommerce\Blocks\BlockTypes

Cart::enqueue_data()protectedWC 1.0

Extra data passed through from server to client for block.

Method of the class: Cart{}

Hooks from the method

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->enqueue_data( $attributes );
$attributes(array)
Any attributes that currently are available from the block. Note, this will be empty in the editor context when the block is not in the post content on editor load.
Default: []

Cart::enqueue_data() code WC 8.7.0

protected function enqueue_data( array $attributes = [] ) {
	parent::enqueue_data( $attributes );

	$this->asset_data_registry->add( 'countryData', CartCheckoutUtils::get_country_data(), true );
	$this->asset_data_registry->add( 'baseLocation', wc_get_base_location(), true );
	$this->asset_data_registry->add( 'isShippingCalculatorEnabled', filter_var( get_option( 'woocommerce_enable_shipping_calc' ), FILTER_VALIDATE_BOOLEAN ), true );
	$this->asset_data_registry->add( 'displayItemizedTaxes', 'itemized' === get_option( 'woocommerce_tax_total_display' ), true );
	$this->asset_data_registry->add( 'displayCartPricesIncludingTax', 'incl' === get_option( 'woocommerce_tax_display_cart' ), true );
	$this->asset_data_registry->add( 'taxesEnabled', wc_tax_enabled(), true );
	$this->asset_data_registry->add( 'couponsEnabled', wc_coupons_enabled(), true );
	$this->asset_data_registry->add( 'shippingEnabled', wc_shipping_enabled(), true );
	$this->asset_data_registry->add( 'hasDarkEditorStyleSupport', current_theme_supports( 'dark-editor-style' ), true );
	$this->asset_data_registry->register_page_id( isset( $attributes['checkoutPageId'] ) ? $attributes['checkoutPageId'] : 0 );
	$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme(), true );
	$this->asset_data_registry->add( 'activeShippingZones', CartCheckoutUtils::get_shipping_zones(), true );

	$pickup_location_settings = get_option( 'woocommerce_pickup_location_settings', [] );
	$this->asset_data_registry->add( 'localPickupEnabled', wc_string_to_bool( $pickup_location_settings['enabled'] ?? 'no' ), true );

	// Hydrate the following data depending on admin or frontend context.
	if ( ! is_admin() && ! WC()->is_rest_api_request() ) {
		$this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' );
	}

	/**
	 * Fires after cart block data is registered.
	 *
	 * @since 2.6.0
	 */
	do_action( 'woocommerce_blocks_cart_enqueue_data' );
}