Automattic\WooCommerce\Blocks\BlockTypes

Cart::enqueue_data()protectedWC 1.0

Extra data passed through from server to client for block.

{} Это метод класса: Cart{}

Хуки из метода

Возвращает

null. Ничего.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->enqueue_data( $attributes );
$attributes(массив)
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.
По умолчанию: []

Код Cart::enqueue_data() WC 6.7.0

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

	$this->asset_data_registry->add(
		'shippingCountries',
		function() {
			return $this->deep_sort_with_accents( WC()->countries->get_shipping_countries() );
		},
		true
	);
	$this->asset_data_registry->add(
		'shippingStates',
		function() {
			return $this->deep_sort_with_accents( WC()->countries->get_shipping_country_states() );
		},
		true
	);
	$this->asset_data_registry->add(
		'countryLocale',
		function() {
			// Merge country and state data to work around https://github.com/woocommerce/woocommerce/issues/28944.
			$country_locale = wc()->countries->get_country_locale();
			$states         = wc()->countries->get_states();

			foreach ( $states as $country => $states ) {
				if ( empty( $states ) ) {
					$country_locale[ $country ]['state']['required'] = false;
					$country_locale[ $country ]['state']['hidden']   = true;
				}
			}
			return $country_locale;
		},
		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 );

	// Hydrate the following data depending on admin or frontend context.
	if ( ! is_admin() && ! WC()->is_rest_api_request() ) {
		$this->hydrate_from_api();
	}

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