Load countries in settings only when a block requires them (https://github.com/woocommerce/woocommerce-blocks/pull/1726)
This commit is contained in:
parent
2320b8aa75
commit
bd8bd4f009
|
@ -129,8 +129,6 @@ class Assets {
|
|||
'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' ) ),
|
||||
],
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Automattic\WooCommerce\Blocks\BlockTypes;
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Package;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
|
@ -44,6 +46,10 @@ class Cart extends AbstractBlock {
|
|||
* @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'
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Automattic\WooCommerce\Blocks\BlockTypes;
|
||||
|
||||
use Automattic\WooCommerce\Blocks\Package;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
|
@ -45,6 +47,11 @@ class Checkout extends AbstractBlock {
|
|||
* @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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue