Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Load countries in wcSettings only when a block requires them #1726

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ),
],
Expand Down
6 changes: 6 additions & 0 deletions src/BlockTypes/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Automattic\WooCommerce\Blocks\BlockTypes;

use Automattic\WooCommerce\Blocks\Package;

defined( 'ABSPATH' ) || exit;

/**
Expand Down Expand Up @@ -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'
Expand Down
7 changes: 7 additions & 0 deletions src/BlockTypes/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Automattic\WooCommerce\Blocks\BlockTypes;

use Automattic\WooCommerce\Blocks\Package;

defined( 'ABSPATH' ) || exit;

/**
Expand Down Expand Up @@ -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;
}
Expand Down