• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Checkout::enqueue_data() – Extra data passed through from server to client for block.

You appear to be a bot. Output may be restricted

Description

Extra data passed through from server to client for block.

Usage

Checkout::enqueue_data( $attributes );

Parameters

$attributes
( array ) optional – 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.

Returns

void

Source

File name: woocommerce/packages/woocommerce-blocks/src/BlockTypes/Checkout.php


Lines:

1 to 45 of 45
  protected function enqueue_data( array $attributes = [] ) {
    $data_registry = Package::container()->get(
      AssetDataRegistry::class
    );

    if ( ! $data_registry->exists( 'allowedCountries' ) ) {
      $data_registry->add( 'allowedCountries', $this->deep_sort_with_accents( WC()->countries->get_allowed_countries() ) );
    }

    if ( ! $data_registry->exists( 'allowedStates' ) ) {
      $data_registry->add( 'allowedStates', $this->deep_sort_with_accents( WC()->countries->get_allowed_country_states() ) );
    }

    if ( ! $data_registry->exists( 'shippingCountries' ) ) {
      $data_registry->add( 'shippingCountries', $this->deep_sort_with_accents( WC()->countries->get_shipping_countries() ) );
    }

    if ( ! $data_registry->exists( 'shippingStates' ) ) {
      $data_registry->add( 'shippingStates', $this->deep_sort_with_accents( WC()->countries->get_shipping_country_states() ) );
    }

    $permalink = ! empty( $attributes['cartPageId'] ) ? get_permalink( $attributes['cartPageId'] ) : false;

    if ( $permalink && ! $data_registry->exists( 'page-' . $attributes['cartPageId'] ) ) {
      $data_registry->add( 'page-' . $attributes['cartPageId'], $permalink );
    }

    // Hydrate the following data depending on admin or frontend context.
    if ( is_admin() ) {
      $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;

      if ( $screen && $screen->is_block_editor() && ! $data_registry->exists( 'shippingMethodsExist' ) ) {
        $methods_exist = wc_get_shipping_method_count( false, true ) > 0;
        $data_registry->add( 'shippingMethodsExist', $methods_exist );
      }
    }

    if ( ! is_admin() && ! WC()->is_rest_api_request() ) {
      $this->hydrate_from_api( $data_registry );
      $this->hydrate_customer_payment_methods( $data_registry );
    }

    do_action( 'woocommerce_blocks_checkout_enqueue_data' );
  }
 

 View on GitHub View on Trac

Published: 21st August 2020 | Last updated: 10th December 2020

Primary Sidebar

Information

Function name: Checkout::enqueue_data
Class ref: Checkout
Plugin ref: WooCommerce
Version: 5.1.0
Sourcefile: packages/woocommerce-blocks/src/BlockTypes/Checkout.php
File ref: packages/woocommerce-blocks/src/BlockTypes/Checkout.php
Deprecated?: No
API Letters: C,D,E

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.7
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites