diff --git a/src/Assets.php b/src/Assets.php index 2466f5de02e..b1f42943996 100644 --- a/src/Assets.php +++ b/src/Assets.php @@ -129,8 +129,6 @@ public static function get_wc_block_data( $settings ) { 'productCount' => array_sum( (array) $product_counts ), 'attributes' => array_values( wc_get_attribute_taxonomies() ), 'wcBlocksAssetUrl' => plugins_url( 'assets/', __DIR__ ), - 'shippingCountries' => WC()->countries->get_shipping_countries(), - 'allowedCountries' => WC()->countries->get_allowed_countries(), 'restApiRoutes' => [ '/wc/store' => array_keys( \Automattic\WooCommerce\Blocks\RestApi::get_routes_from_namespace( 'wc/store' ) ), ], diff --git a/src/BlockTypes/Cart.php b/src/BlockTypes/Cart.php index df635e484b0..84bae330720 100644 --- a/src/BlockTypes/Cart.php +++ b/src/BlockTypes/Cart.php @@ -7,6 +7,8 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes; +use Automattic\WooCommerce\Blocks\Package; + defined( 'ABSPATH' ) || exit; /** @@ -44,6 +46,10 @@ public function register_block_type() { * @return string Rendered block type output. */ public function render( $attributes = array(), $content = '' ) { + $data_registry = Package::container()->get( + \Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::class + ); + $data_registry->add( 'shippingCountries', WC()->countries->get_shipping_countries() ); \Automattic\WooCommerce\Blocks\Assets::register_block_script( $this->block_name . '-frontend', $this->block_name . '-block-frontend' diff --git a/src/BlockTypes/Checkout.php b/src/BlockTypes/Checkout.php index 282e8f97b4a..c1e60df0395 100644 --- a/src/BlockTypes/Checkout.php +++ b/src/BlockTypes/Checkout.php @@ -7,6 +7,8 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes; +use Automattic\WooCommerce\Blocks\Package; + defined( 'ABSPATH' ) || exit; /** @@ -45,6 +47,11 @@ public function register_block_type() { * @return string Rendered block type output. */ public function render( $attributes = array(), $content = '' ) { + $data_registry = Package::container()->get( + \Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::class + ); + $data_registry->add( 'allowedCountries', WC()->countries->get_allowed_countries() ); + $data_registry->add( 'shippingCountries', WC()->countries->get_shipping_countries() ); \Automattic\WooCommerce\Blocks\Assets::register_block_script( $this->block_name . '-frontend', $this->block_name . '-block-frontend' ); return $content; }