( $location ) { $location['formatted_address'] = wc()->countries->get_formatted_address( $location['address'], ', ' ); return $location; }, get_option( 'pickup_location_pickup_locations', array() ) ) ); } if ( $is_block_editor && ! $this->asset_data_registry->exists( 'globalShippingMethods' ) ) { $shipping_methods = WC()->shipping()->get_shipping_methods(); $formatted_shipping_methods = array_reduce( $shipping_methods, function ( $acc, $method ) use ( $local_pickup_method_ids ) { if ( in_array( $method->id, $local_pickup_method_ids, true ) ) { return $acc; } if ( $method->supports( 'settings' ) ) { $acc[] = [ 'id' => $method->id, 'title' => $method->method_title, 'description' => $method->method_description, ]; } return $acc; }, [] ); $this->asset_data_registry->add( 'globalShippingMethods', $formatted_shipping_methods ); } if ( $is_block_editor && ! $this->asset_data_registry->exists( 'activeShippingZones' ) && class_exists( '\WC_Shipping_Zones' ) ) { $this->asset_data_registry->add( 'activeShippingZones', CartCheckoutUtils::get_shipping_zones() ); } if ( $is_block_editor && ! $this->asset_data_registry->exists( 'globalPaymentMethods' ) ) { // These are used to show options in the sidebar. We want to get the full list of enabled payment methods, // not just the ones that are available for the current cart (which may not exist yet). $payment_methods = PaymentUtils::get_enabled_payment_gateways(); $formatted_payment_methods = array_reduce( $payment_methods, function ( $acc, $method ) { $acc[] = [ 'id' => $method->id, 'title' => $method->get_method_title() !== '' ? $method->get_method_title() : $method->get_title(), 'description' => $method->get_method_description() !== '' ? $method->get_method_description() : $method->get_description(), ]; return $acc; }, [] ); $this->asset_data_registry->add( 'globalPaymentMethods', $formatted_payment_methods ); } if ( $is_block_editor && ! $this->asset_data_registry->exists( 'incompatibleExtensions' ) ) { if ( ! class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) || ! function_exists( 'get_plugins' ) ) { return; } $declared_extensions = \Automattic\WooCommerce\Utilities\FeaturesUtil::get_compatible_plugins_for_feature( 'cart_checkout_blocks' ); $all_plugins = \get_plugins(); // Note that `get_compatible_plugins_for_feature` calls `get_plugins` internally, so this is already in cache. $incompatible_extensions = array_reduce( $declared_extensions['incompatible'], function ( $acc, $item ) use ( $all_plugins ) { $plugin = $all_plugins[ $item ] ?? null; $plugin_id = $plugin['TextDomain'] ?? dirname( $item, 2 ); $plugin_name = $plugin['Name'] ?? $plugin_id; $acc[] = [ 'id' => $plugin_id, 'title' => $plugin_name, ]; return $acc; }, [] ); $this->asset_data_registry->add( 'incompatibleExtensions', $incompatible_extensions ); } if ( ! is_admin() && ! WC()->is_rest_api_request() ) { $this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' ); $this->asset_data_registry->hydrate_data_from_api_request( 'checkoutData', '/wc/store/v1/checkout' ); $this->hydrate_customer_payment_methods(); } /** * Fires after checkout block data is registered. * * @since 2.6.0 */ do_action( 'woocommerce_blocks_checkout_enqueue_data' ); } /** * Get saved customer payment methods for use in checkout. */ protected function hydrate_customer_payment_methods() { $payment_methods = PaymentUtils::get_saved_payment_methods(); if ( ! $payment_methods || $this->asset_data_registry->exists( 'customerPaymentMethods' ) ) { return; } $this->asset_data_registry->add( 'customerPaymentMethods', is_array( $payment_methods ) ? $payment_methods['enabled'] : null ); } /** * Register script and style assets for the block type before it is registered. * * This registers the scripts; it does not enqueue them. */ protected function register_block_type_assets() { parent::register_block_type_assets(); $chunks = $this->get_chunks_paths( $this->chunks_folder ); $vendor_chunks = $this->get_chunks_paths( 'vendors--checkout-blocks' ); $shared_chunks = [ 'cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend' ]; $this->register_chunk_translations( array_merge( $chunks, $vendor_chunks, $shared_chunks ) ); } /** * Get list of Checkout block & its inner-block types. * * @return array; */ public static function get_checkout_block_types() { return [ 'Checkout', 'CheckoutActionsBlock', 'CheckoutAdditionalInformationBlock', 'CheckoutBillingAddressBlock', 'CheckoutContactInformationBlock', 'CheckoutExpressPaymentBlock', 'CheckoutFieldsBlock', 'CheckoutOrderNoteBlock', 'CheckoutOrderSummaryBlock', 'CheckoutOrderSummaryCartItemsBlock', 'CheckoutOrderSummaryCouponFormBlock', 'CheckoutOrderSummaryDiscountBlock', 'CheckoutOrderSummaryFeeBlock', 'CheckoutOrderSummaryShippingBlock', 'CheckoutOrderSummarySubtotalBlock', 'CheckoutOrderSummaryTaxesBlock', 'CheckoutOrderSummaryTotalsBlock', 'CheckoutPaymentBlock', 'CheckoutShippingAddressBlock', 'CheckoutShippingMethodsBlock', 'CheckoutShippingMethodBlock', 'CheckoutPickupOptionsBlock', 'CheckoutTermsBlock', 'CheckoutTotalsBlock', ]; } }